9 Replies Latest reply: Dec 6, 2012 9:04 AM by 966897 RSS

    cp -R Command - Different number of Bytes in Original dir and copied dir

    Nir
      Hi Experts,

      I have copied an Directory (49GB) using *cp -R +<Original file path> <new place>+* command.

      When i run du -c | grep total cammand in both original file and the copied filr below are the values,

      Original - 50998896
      Copied - 50999684

      Why it gives different values ??

      Do i need to use any other command to copy it ??

      Will it be a issue on taking backups ???

      Please help me ......
        • 1. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
          966897
          Nir wrote:
          Hi Experts,

          I have copied an Directory (49GB) using *cp -R +<Original file path> <new place>+* command.

          When i run du -c | grep total cammand in both original file and the copied filr below are the values,

          Original - 50998896
          Copied - 50999684

          Why it gives different values ??

          Do i need to use any other command to copy it ??

          Will it be a issue on taking backups ???

          Please help me ......
          I have noticed similar problems with both "cp -r/R" and "rsync -r". But it happened only when I was trying to copy the home folder.
          • 2. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
            Nik
            Hi.
            It's depend what you copy.

            Some examples, that cause this:

            1. Some files have soft or hard links. cp will copy this as undepended files. ( Backup will lager then source)
            ( tar or cpio will correct copy )
            2. Some files have holes. cp will fill holes by zero. ( Backup will lager then source)
            ( no solutions )

            3. In case on source side at directory was creataed many files and after removed, directroy size still large.
            On destination side new dir will have size required for store curent files. ( Backup will less then source).
            ( no solutions)

            4. Some errors at executions of backup. :)

            Regards.
            • 3. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
              Dude!
              The cp command has various options to handle and dereference symbolic links, sparse files, privileges, etc. If you want copy the complete directory and file structure I suggest to use the tar command. The following, for instance, will copy everything under /u01 to /mydir.

              <pre>
              # cd /u01
              # tar -cf - . | (cd /mydir; tar -xf -; sync)
              </pre>

              Edited by: Dude on Dec 3, 2012 9:37 AM
              • 4. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
                966897
                Dude wrote:
                The cp command has various options to handle and dereference symbolic links, sparse files, privileges, etc. If you want copy the complete directory and file structure I suggest to use the tar command. The following, for instance, will copy everything under /u01 to /mydir.

                <pre>
                # cd /u01
                # tar -cf - . | (cd /mydir; tar -xf -; sync)
                </pre>

                Edited by: Dude on Dec 3, 2012 9:37 AM
                Don't know where I screwed up.

                This is what I did (I am running ol6.3 in /dev/sdb5):

                1. Mount an ("inactive") ol6.3 partition (/dev/sdb6) on /mnt
                2. cd /mnt
                3. tar -cf -. | (cd /extra/sdb6; tar -xf -; sync) # /extra/sdb6 is the destination partition

                Check results:

                # du -s /mnt
                # 3783812     /mnt

                # du -s /extra/sdb6
                # 4456860     /extra/sdb6

                The dest partition (4,456.860MB) is substantially greater than the source partition (3,783.812MB).

                Edited by: Ping-Wu on Dec 3, 2012 10:33 AM
                • 5. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
                  Dude!
                  It works fine here, see below example:

                  <pre>
                  # mkfs.ext4 /dev/sdb3
                  # mkdir /mnt/sdb3
                  # mount /dev/sdb3 /mnt/sdb3
                  # cd /lib64
                  # tar -cf - . | (cd /mnt/sdb3; tar -xf -; sync)

                  # du -s /lib64
                  27072     /lib64

                  # du -s /mnt/sdb3
                  27088     /mnt/sdb3

                  # du -s /mnt/sdb3/lost+found
                  16     /mnt/sdb3/lost+found
                  </pre>

                  Do you have any hidden files on /extra/sdb6? Are you using the same filesystem? You can try the diff command to see what is different, e.g.:

                  <pre>
                  # diff /lib64 /mnt/sdb3
                  ...
                  Only in /mnt/sdb3: lost+found
                  ...
                  </pre>

                  You can also use the cp copy command, but you will have to add some options to preserve file ownerships, timestamps, links, etc, e.g.:

                  <pre>
                  # rm -rf /mnt/sdb3/lib64
                  # cp -pdr /lib64 /mnt/sdb3
                  # sync

                  # du -s /lib64
                  27072     /lib64

                  # du -s /mnt/sdb3/lib64
                  27072     /mnt/sdb3/lib64
                  </pre>

                  Edited by: Dude on Dec 3, 2012 2:12 PM
                  • 6. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
                    966897
                    Dude wrote:
                    It works fine here, see below example:

                    <pre>
                    # mkfs.ext4 /dev/sdb3
                    # mkdir /mnt/sdb3
                    # mount /dev/sdb3 /mnt/sdb3
                    # cd /lib64
                    # tar -cf - . | (cd /mnt/sdb3; tar -xf -; sync)

                    # du -s /lib64
                    27072     /lib64

                    # du -s /mnt/sdb3
                    27088     /mnt/sdb3

                    # du -s /mnt/sdb3/lost+found
                    16     /mnt/sdb3/lost+found
                    </pre>

                    Do you have any hidden files on /extra/sdb6? Are you using the same filesystem? You can try the diff command to see what is different, e.g.:

                    <pre>
                    # diff /lib64 /mnt/sdb3
                    ...
                    Only in /mnt/sdb3: lost+found
                    ...
                    </pre>

                    You can also use the cp copy command, but you will have to add some options to preserve file ownerships, timestamps, links, etc, e.g.:

                    <pre>
                    # rm -rf /mnt/sdb3/lib64
                    # cp -pdr /lib64 /mnt/sdb3
                    # sync

                    # du -s /lib64
                    27072     /lib64

                    # du -s /mnt/sdb3/lib64
                    27072     /mnt/sdb3/lib64
                    </pre>

                    Edited by: Dude on Dec 3, 2012 2:12 PM
                    This is what I got, still doing my investigation:

                    [root@oracle-32 usr]# du -s /mnt/home/oracle/
                    166996     /mnt/home/oracle/
                    [root@oracle-32 usr]# du -s /extra/sdb6/home/oracle/
                    175152     /extra/sdb6/home/oracle/
                    [root@oracle-32 usr]# diff -r /mnt/home/oracle/ /extra/sdb6/home/oracle/
                    Only in /mnt/home/oracle/.dropbox: command_socket
                    Only in /mnt/home/oracle/.dropbox: iface_socket
                    diff: /mnt/home/oracle/.pulse/5325b55a5d3c35d27a2aecaa00000021-runtime: No such file or directory
                    diff: /extra/sdb6/home/oracle/.pulse/5325b55a5d3c35d27a2aecaa00000021-runtime: No such file or directory
                    • 7. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
                      Nir
                      Hi All...

                      Thanks for the replies....

                      I'll try tar command or cp -pdr here after when i taking backups.

                      Thanks all.....
                      • 8. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
                        Dude!
                        Applicatons may create temporary and process dependent files that you do not need to copy. You can avoid problems to access such files by closing the appropriate application prior to your copy attempt. Similarily, you cannot copy socket files and you don't need to copy them because they are recreated at application startup. And last not least, you cannot copy a running database since datafiles will be inconsistent.
                        • 9. Re: cp -R Command - Different number of Bytes in Original dir and copied dir
                          966897
                          Dude wrote:
                          Applicatons may create temporary and process dependent files that you do not need to copy. You can avoid problems to access such files by closing the appropriate application prior to your copy attempt. Similarily, you cannot copy socket files and you don't need to copy them because they are recreated at application startup. And last not least, you cannot copy a running database since datafiles will be inconsistent.
                          I "think" (not-yet-verified) what I might have screwed up was that I rebooted (instead of a powering-off then powering-on) to a different OL installation/partition and the temporary and process dependent files in the now dormant partition, from which I was trying to copy/tar/rsync, were not removed.