Information in this section is courtesy of Everything Linux
A utility designed to synchronize files between two distinct computers, rsync is widely used in many Linux distributions for file system backup and redundancy. It’s a powerful, flexible utility that makes updates significantly faster by copying only the differences in files that have been changed or compressed. It can also be used over SSH if you’re particularly security-conscious.
In order to use rsync, you’ll need two machines, one of which will be configured as an “rsync server.” On said server, type rsync –daemon at the command line, then set up a configuration file. The first few lines of this file contain the following components:
- A Message of the Day file. This displays when clients connect to the machine.
- A log file where diagnostic and runtime information will be recorded.
- A PID file that contains the “process ID” number of the daemon. This is a signal to other processes and systems that rsync is running, and allows it to ensure that prior instances stopped successfully.
- A lock file that prevents another rsync instance from being started while the previous one is still running.
The next four lines denote what path rsync uses to sync files – and where it syncs them. These are local settings, and only impact the file block they apply to. Once you’ve assigned a simple path name (something that’s short and easy to remember), you’ll configure the following settings: e
- Path: The actual, full filesystem path which files are synced to or from.
- Comment: A description of where the path points.
- Auth Users: Restricts access to a predefined user or set of users. It is highly advised you make use of this option, or anyone using rsync will be able to access the files you’re syncing.
- Secrets File: Denotes where the secrets file, which contains plaintext passwords and usernames, is located.
Once you’re done, the full config file will look a little something like this:
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
path = /rsync_files_here
comment = My Very Own Rsync Server
uid = nobody
gid = nobody
read only = no
list = yes
auth users = username
secrets file = /etc/rsyncd.scrt
Next up, let’s look at a few of the many options that can be applied to fine-tune rsync’s when you call the function(source):
- -v: Increases the amount of information you see during the transfer, giving you details regarding what files are being transferred. Using this twice will give you information on what files are being skipped in the transfer, as well. You can also use –verbose in place of -v.
- -q: The opposite of –verbose, –quiet decreases the information generated by rsync.
- -c: The –checksum option changes how rsync checks files that are in need of a transfer. Without –checksum, rsync skips files that have identical times and sizes between the source and destination. With –checksum, it examines only file size. Files with identical sizes have their checksum examined, and are transferred if there are differences. Generally, this is an option you’ll only use if you’re transferring files to a destination where file corruption is a possibility, or to verify backups.
- -a: Enables recursion, allowing you to preserve everything except for hard links. Essentially works the same was -rlptgoD. To preserve hard links as well, pair this option with -H.
- –help: Displays a short help page listing the available options in rsync. Older versions of rsync use -h, as well.