Sunday, 10 August 2014

rsync options

Finally got round to upgrading the family sever, which holds all our precious photos and music and was several years old (Debian Lenny). Transferring 250GB from old server to new, I didn't have space to tar up the files first. Anyway waste of time creating and gzipping the archive just to unzip it on the new server. So I used rsync with compression. While looking up the syntax, I came across this handy list,with explanations, from:


Basic rsync Command

To begin, we should recap what a basic rsync command — with an SSH key for identity — looks like (all on one line):

rsync -avz -e "ssh -i /ssh-private-key" /source/folder username@username.evbackup.com:destination-folder

Noteworthy rsync Arguments (Args)


"To err is human. To arg is pirate."
There several options that you can add to the basic rsync command. Full documentation for all of the rsync command arguments can be found on the rsync online manual page. However, here some commons arguments that many people use in their rsync command:

-a   or   --archive

-a is equivalent to rsync -rlptgoD (no -H,-A,-X).
-a / --archive is a quick way of saying you want recursion and want to preserve almost all attributes of the source files (with -H being a notable omission).
Note that -a does not preserve hard links, because finding multiply-linked files is expensive. You must separately specify -H.

-v   or   --verbose

This option increases the amount of information you are given during the transfer (rsync works silently without it). A single -v will give you information about what files are being transferred and a brief summary at the end. Two -v options (-vv) will give you information on what files are being skipped and slightly more information at the end. More than two -v options should only be used if you have insomnia.

-z   or   --compress

With this option, rsync compresses the file data as it is sent to the destination machine, which reduces the amount of data being transmitted -- something that is useful over a slow connection.
Note that this option typically achieves better compression ratios than can be achieved by using a compressing remote shell or a compressing transport because it takes advantage of the implicit information in the matching data blocks that are not explicitly sent over the connection.
However, it's worth noting that some file types will not be compressed during transfer. The default list of file extensions that will not be compressed is: gz zip z rpm deb iso bz2 tbz tgz 7z mp3 mp4 mov avi ogg jpg jpeg

-n   or   --dry-run

This makes rsync perform a trial run that doesn't make any changes (and produces mostly the same output as a real run). It is most commonly used in combination with the -v, --verbose and/or -i, --itemize-changes and/or -d , --delete options to see what an rsync command is going to do before one actually runs it.

-t   or   --times

NOTE: Not required if you use -a or --archive
This tells rsync to transfer modification times along with the files and update them on the remote system. Note that if this option is not used, the optimization that excludes files that have not been modified cannot be effective; in other words, a missing -t or a missing -a will cause the next transfer to behave as if it used -I, causing ALL files to be updated.

-p   or   --perms

NOTE: Not required if you use -a or --archive
To give destination files (both old and new) the source permissions, use --perms. To give new files the destination-default permissions (while leaving existing files unchanged), make sure that the --perms option is off and use --chmod=ugo=rwX (which ensures that all non-masked bits get enabled).

-s   or   --protect-args

This option sends all file names and most options to the remote rsync without allowing the remote shell to interpret them. This means that spaces are not split in names, and any non-wildcard special characters are not translated (such as ~, $, ;, &, etc.). Wild cards are expanded on the remote host by rsync (instead of the shell doing it).

-i   or   --itemize-changes

This option requests a simple itemized list of the changes that are being made to each file, including attribute changes. This is exactly the same as specifying --out-format='%i %n%L'. If you repeat the option, unchanged files will also be output.
For further details about --itemize-changes, see the rsync online manual page

-l   or   --links

NOTE: Not required if you use -a or --archive
When symbolic links are encountered in the source files, rsync will recreate the symlink on the destination server instead of copying the file or folder that the symlink points to.

-H   or   --hard-links

This option tells rsync to look for hard-linked files in the transfer and link together the corresponding files on the receiving side. Without this option, hard-linked files in the transfer are treated as though they were separate files.
Note that rsync can only detect hard links between files that are inside the transfer set. If rsync updates a file that has extra hard-link connections to files outside the transfer, that linkage will be broken. If you are tempted to use the --inplace option to avoid this breakage, be very careful that you know how your files are being updated so that you are certain that no unintended changes happen due to lingering hard links (and see the --inplace option for more caveats).

-h   or   --human-readable

This option produces numbers in the log file and stdout in a more human-readable format. This makes big numbers output using larger units, with a K (kilobytes), M (megabytes), or G (gigabytes) suffix. If this option was specified once, these units are K (1000), M (1000*1000), and G (1000*1000*1000). If the option is specified twice (-hh) the units are powers of 1024 instead of 1000.

--log-file=[File]

This option tells the rsync daemon to use the given log-file name instead of using the default "log file" setting. If you would like to keep a log file of your backups, this is the option for you.

--progress

This option tells rsync to print information showing the progress of the transfer. This gives a bored user something to watch. It implies --verbose if it wasn't already specified. The progress information looks like this:
782448 63% 110.64kB/s 0:00:04
In that example, the receiver has reconstructed 782448 bytes (or 63%) of the sender's file, which is being reconstructed at a rate of 110.64 kilobytes per second, and the transfer will finish in 4 seconds if the current rate is maintained until the end.                     

No comments:

Post a Comment