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.
--remove-source-files: remove source files after transfer.
-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
--chown:<user>:<group>change the user and group of the copied files. You need superuser privileges to use this parameter.
- More options on man page (
# Only copies one level (skips directories) rsync origin/* dest/
# Recursive copy rsync -r origin dest
# Copy the source folder content to the target directory rsync -r origin-folder/ dest-folder/ # Copy the source folder itself and its content to the target directory rsync -r origin-folder dest-folder/
# 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
If you have any suggestion, feel free to contact me via social media or email.