Just spent a few minutes testing how to synchronise a back up drive on Ubuntu. After reading a few hundred lines of man pages I came up with what I needed. This is just a summary of what I needed to get my backups done.
- Working directory
- Backup directory
- Here is recursive list of the working directory
d_1_1 file1 file2 file3
To synchronise the d_1 directory now and in the future efficiently
rsync [options] working_directory backup_directory
- Increase verbosity
- Recurse into directories
- Transfer directories without recursing
- Skip files that are newer on the receiver
- Dry run
- Do not update files at the destination that already exist
- Give file transfer stats
- Output in human readable format
- Show progress during transfer
Lets run the rsync command over d_1 a few times using different flags
rsync -vrn --stats --human-readable --progress d_1/ d_2/
The following is the output to the screen doing a dry run, when the command is run without the dry run option, the two folders are synchronised (even the directory d_1_1 and its file file1_1, as we used the -r option)
sending incremental file list
Number of files: 6Number of files transferred: 4Total file size: 0 bytesTotal transferred file size: 0 bytesLiteral data: 0 bytesMatched data: 0 bytesFile list size: 105File list generation time: 0.020 secondsFile list transfer time: 0.000 secondsTotal bytes sent: 134Total bytes received: 28sent 134 bytes received 28 bytes 324.00 bytes/sectotal size is 0 speedup is 0.00 (DRY RUN)
That is a fairly simple example so lets try something a bit more interesting.
rsync -vn --stats --human-readable –progress --ignore-existing d_1/ d_2/
This synchronised d_1 to d_2 however it did not copy over any files that already existed.
rsync -vun --stats --human-readable --progress d_1/ d_2/
This synchronised d_1 and d_2 and only updated files that had been modified (in the working copy) and therefore were newer than the file in the backup copy (d_2)
rsync -vdn --stats --human-readable --progress d_1/ d_2/
This synchronised d_1 to d_2 however directories directly under d_1 were brought across to d_2 minus their contents and any subdirectories were completely ignored.