Backing up files on a regular basis is an integral part of administering your server.
Although you could download every individual file when you want to save them, using
rsync makes the task of backing up easier because it downloads only the files that have changed, saving time and bandwidth.
rsync is available on most Linux distributions by default. If you need to install it manually, however, you can do so by using your distribution's package manager. For example, the following commands are some common Linux®
rsync installation commands:
The Ubuntu operating system
sudo aptitude install rsync
sudo emerge rsync
sudo yum install rsync
If you are downloading files to another system, both systems must have
To keep your files and system secure, be sure to use encryption when uploading or downloading files. The following example uses the Secure Shell (SSH) protocol with
rsync to keep your data secure. If you prefer not to use SSH, you will be prompted for a password each time you run
If you use
rsync to automate your backups, ensure that the destination server (where the backup directory
is located) has access to the originating server.
To back up your files from one server to another, run the following command on the destination server:
rsync -e 'ssh -p 30000' -avlP --delete --stats [email protected]:/home/demo /backup
The following explanation covers each part of the command:
-e 'ssh -p 30000'
rsyncuses the SSH protocol and sets the port.
A shortcut that contains the following options:
Archive. Saves the permission settings for the files.
Verbose. Returns more information about what
rsyncis doing. You can change how much information
rsyncreturns by eliminating
-v, or you can request more information with
-vvv. Setting verbose mode with
-vvvreturns all information about the
Links. Preserves any symbolic links (symlinks) that you created on the source server.
Progress. Displays the progress of each file transfer.
Deletes files from the destination folder that are no longer required (that is, they have been deleted from the originating folders). Typically, you delete files to save space, but if you think you might need it later, ensure that you have a backed-up copy before deleting it.
Adds more output regarding the file transfer status.
The originating folders to back up.
/home/demo/. With the trailing slash,
rsynccopies the contents of the directory, but doesn't recreate the directory. This example backs up a folder from one system to another, so omitting the trailing slash replicates the entire directory structure.
Identifies the folder on the backup server in which to place the files.
Your output should look similar to the following example:
receiving file list ... 31345 files to consider ./ tuning-primer.sh 42596 100% 533.30kB/s 0:00:00 (xfer#2, to-check=31331/31345) bin/ bin/Backup 618 100% 7.74kB/s 0:00:00 (xfer#3, to-check=31310/31345) bin/Search 455 100% 5.70kB/s 0:00:00 (xfer#4, to-check=31309/31345) configs/ configs/php.ini 114 100% 1.43kB/s 0:00:00 (xfer#5, to-check=31307/31345) public_html/ ... ...
In the preceding example,
rsync receives a list of 31,345 files and, because this is the first time
rsync has been run, downloads them all. When
rsync runs again, only files that have changed since the last backup are synchronized to the backup folder.
Updated 14 days ago