Copy or rsync command

前端 未结 8 1320
广开言路
广开言路 2021-01-30 03:42

The following command is working as expected...

cp -ur /home/abc/* /mnt/windowsabc/

Does rsync has any advantage over it? Is there a better way

8条回答
  •  温柔的废话
    2021-01-30 04:23

    The command as written will create new directories and files with the current date and time stamp, and yourself as the owner. If you are the only user on your system and you are doing this daily it may not matter much. But if preserving those attributes matters to you, you can modify your command with

    cp -pur /home/abc/* /mnt/windowsabc/
    

    The -p will preserve ownership, timestamps, and mode of the file. This can be pretty important depending on what you're backing up.

    The alternative command with rsync would be

    rsync -avh /home/abc/* /mnt/windowsabc
    

    With rsync, -a indicates "archive" which preserves all those attributes mentioned above. -v indicates "verbose" which just lists what it's doing with each file as it runs. -z is left out here for local copies, but is for compression, which will help if you are backing up over a network. Finally, the -h tells rsync to report sizes in human-readable formats like MB,GB,etc.

    Out of curiosity, I ran one copy to prime the system and avoid biasing against the first run, then I timed the following on a test run of 1GB of files from an internal SSD drive to a USB-connected HDD. These simply copied to empty target directories.

    cp -pur    : 19.5 seconds
    rsync -ah  : 19.6 seconds
    rsync -azh : 61.5 seconds
    

    Both commands seem to be about the same, although zipping and unzipping obviously tax the system where bandwidth is not a bottleneck.

提交回复
热议问题