Creating Backups using rsync with Examples

From Brian Nelson Ramblings
Revision as of 14:49, 14 March 2014 by Brian (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Create Backups using rsync with examples

What does rsync stand for?

Rsync stands for remote sync

Rsync is used to perfrom backup operation in Linux and UNIX

It syncs files from one location to another location, Host computer to a Remote computer or a Remote Computer to a Host computer. It can even be used on a single server.

Important Features of rsync

  • Speed: The first time you use rsync it does entire directory, next time it only sends what has been changed, which makes the transfer quick.
  • Security: You can use ssh when using rsync between computers
  • Less Bandwidth: rsync uses compression and decompression of data block by block at the sending an receiving end respectively.

Basic rsync Syntax

rsync options source destination

Source and destination could be either local or remote. When using remote, just specify the login name and remote server name/location

Examples

Local to Local

Local rsync of your html directory to a backup directory on the local computer.

rsync -zvr /var/www/html/ /root/backup
  • -z is to enable compression
  • -v is to enable verbose
  • -r is to enable recursive, all directors below

Local to Local Preserving Timestamps

rysnc -zvra /var/www/html/ /root/backup
  • -a is to enable archive mode, saving timestamps

Syncronize Files from Local Server to Remote Server

rsync -avzr /var/www/html/ brian@remoteserver:/backup/

This will make a backup of the html directory and all files under the html directory to remote backup server

Syncronize Files from Remote Server to Local Server

rsync -avzr brian@remoteserver:/backup /var/www/html

This will do a restore from the backup server to your local server

Example using SSH with rsync

rsync -avzr -e ssh brian@remoteserver:/backup /var/www/html

or

rsync -avzr -e ssh /var/www/html brian@remoteserver:/backup

Use rsync -e ssh to specify which remote shell to use. In this case, rsync will use ssh.

To learn more about rsync you view the man page

man rsync

Additional Articles: