This is an old revision of the document!
Table of Contents
rsync
This section needs expansion. You can help by adding to it.
Useful Commands
Using rsync may seem obtuse to new users at first. However, once you know how to structure and alias your commands, it is one of the absolute fastest & reliable ways to run backup systems:
Built-in Documentation
rsync --h and man grep will tell you all the flags which are available to use. We will only detail some of the most important ones below:
Local Backups
To have rsync copy all files from one directory to another, use this command:
$ rsync -av /path/to/source/dir/ /path/to/destination/dir/
The -a flag tells rsync to not only recursively go into subdirectories, but it also ensures all attributes like timestamps & permissions are preserved. -v is for verbose output, so you can see what rsync is doing.
Remote & Network Backups
rsync supports the use of SSH for transferring backups over network connections, using the -e flag.
To back up files from your local shell to a remote machine via SSH:
$ rsync -avz -e ssh /source/directory/ user@remote:/destination/directory/
Here we are also using the -z flag, which compresses the data to speed up transfer.
To back up files from a remote machine to your local shell via SSH:
$ rsync -avz -e ssh user@remote:/source/directory/ /destination/directory/
In the case of both of these commands, “local shell” just means whatever terminal you are running rsync from. If you are running this from a remote machine, that machine is the “local shell” in this equation, and whatever machine it is SSH'ing into is the “remote shell.” Make sense? Good, because there's a few more things you have to grasp with this command.
Incremental Backups
If you are regularly backing up the same folders, drive, server, etc, then rsync needs to be tweaked further with two flags for efficiency's sake:
With the -u (or --update) flag, we can tell rsync to only copy files from the source that do not exist in the destination, or are newer than the same files in the destination, and skip all the others. With the --delete flag, we can tell rsync to delete files in the destination that no longer exist in the source.
This is the form of rsync that you want to use in automated backup scripts.
More Command Flags
There are more flags you can combine with these basic rsync commands to fine-tune how your backups are executed. Play around with them on some demo directories to see how they affect your files!
- Use the
-nor--dry-runflag in combination with-vto perform a simulated transfer. - Use --progress to see real-time transfer status.
What About Automatic Backups?
This section needs expansion. You can help by adding to it.
Find this page online at: https://bestpoint.institute/tools/rsync