Linux: The Best and Safest Way to Copy Files

What is the best and safest way to copy files in Linux machine? In some cases where the directory that I need to copy over is too large with 10000+ files and 50GB+ of total size, I need to transfer the files in the most convenience and safest way. Conditions that I need are:

  • I can monitor the copying progress
  • I can resume if got some problem during the file transfer
  • Some summary report after completion
  • Log the progress into a file
  • I do not need any prompt for ‘yes’ or ‘no’ or whatsoever
  • And must be in one line of command!

The answer is using rsync!

I do not need to introduce this tool. You can find by yourself in the Internet cause it is so popular. So I just show you the best way to meet the condition as mentioned above.

Variables that I used:

OS: CentOS 6.0 64bit
Source directory: /mnt/nfs/contents
Destination directory: /home/user1/public_html
Log files location: /home/user1/logs/copy.txt

1. Lets check the total number of files in the source directory:

$ tree /mnt/nfs/contents/ | wc -l

2. The rsync command will be:

$ rsync -Pavzh --log-file=/home/user1/logs/copy.txt /mnt/nfs/contents /home/user1/public_html &

3. Check the progress:

 $ tail -f /home/user1/logs/copy.txt

4. Count the total number of files in the destination directory:

$ tree /home/user1/public_html/contents/ | wc -l

If the copy process being interrupted, you just need repeat step 2 and the copying process will continue from the last state before interruption. Good luck!