Rsync
From ArchWiki
rsync is an open source utility that provides fast incremental file transfer.
Contents |
Installation
Install the rsync package using pacman:
# pacman -S rsync
Usage
For more examples, search the Community Contributions and General Programming forums.
As a cp alternative
rsync can readily be used as an advanced cp alternative, specially useful for copying larger files:
$ rsync -P src dest
The -P option is the same as --partial --progress, which keeps partially transferred files and shows a progress bar during transfer.
As a backup utility
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media. For a more thorough example, see rsync/Full system backup.
Automated backup
For the sake of this example, the script is created in the /etc/cron.daily directory, and will be run on a daily basis if a cron daemon is installed and properly configured. Configuring and using cron is outside the scope of this article.
First, create a script containing the appropriate command options:
#!/bin/bash rsync -a --delete /folder/to/backup /location/to/backup &> /dev/null
- -a
- indicates that files should be archived, meaning that all of their attributes are preserved
- --delete
- means files deleted on the source are to be deleted on the backup aswell
Here, /folder/to/backup should to be changed to what needs to be backed-up (/home, for example) and /location/to/backup is where the backup should be saved (/media/disk, for instance).
Finally, the script must be executable:
# chmod +x /etc/cron.daily/rsync.backup
Automated backup with SSH
If backing-up to a remote host using SSH, use this script instead:
#!/bin/bash rsync -a -r --delete -e ssh /folder/to/backup remoteuser@remotehost:/location/to/backup &> /dev/null
- -e ssh
- tells rsync to use SSH
- remoteuser
- is the user on the host remotehost