Backup methods (IV): rsync
Making backups regularly is one of the most relevant tasks for a Linux user. In the fourth chapter of ‘Backup methods’ I will show you one of the most popular copying tools:
rsync can copy from a source to a destination, based on last modified time or file size. Destination folder does not need to exist.
rsync [<options>] <SOURCE> <DEST>
-r: recursive into directories.
-t: preserve modification times.
-n: perform a trial run (no changes made).
-p: preserve permissions.
-A: preserve ACLs (How to set permissions for specific users). Implies
-a: archive mode, is a shortcut for recursive into directories, copy symlinks as symlinks, preserve permissions, preserve modification times, preserve group, preserve owner (using “sudo”), preserve device files (using “sudo”) and preserve special files.
-v: increase verbosity.
-e <COMMAND>: specify the remote shell to use. See Using with SSH.
-z: compress file data during the transfer.
-c: update based on checksum, not modification date or file size.
-u: update based only on modification date, not file size.
-b --backup-dir=<DIR>: Put copied files inside
- More options on man page (
# Only copies one level (skips directories) rsync origin/* dest/
# Recursive copy rsync -r origin/ dest/
# Preserve last modification time rsync -tr origin/ dest/
# Create a folder inside dest/ (called 'bck') for copied files rsync -r -b --backup-dir=bck origin/ dest/
Using with SSH