Home > Uncategorized > Using rsync to Backup Data

Using rsync to Backup Data

rsync

The rsync command will create an exact copy of your information in a new location based on what has changed. It takes a look a timestamps to determine what file have changed. This synchronization process is a reliable way to keep two directories exactly the same.

The Trailing Slash
It is important to understand the difference in use with or without the trailing slash.

rsync -av /home/office/ /bk
This example does not move the office directory folder only the contents.

rsync -av /home/office /bk
This example will result in the office directory located under the /bk = /bk/office.

Note the differences and choose the method you want to use for your backups.

Compression
If you want to make your transfer smaller then use the -z option to compress your transfer.

rsync -avz /home/office/ /bk

Archive Mode -a
This will ensure that all symbolic links, devices, attributes,permissions, ownerships,etc. are preservered and transferred. This is the same as rlptgoD

Verbose -v
This will provide you with information.

Get Stats on Transfer –stats

rsync -avz –stats /home/office/ /var/bk

Here is an example of the stats you will have available.
Number of files: 324352
Number of files transferred: 70613
Total file size: 20610660916 bytes
Total transferred file size: 11504455981 bytes
Literal data: 11504455981 bytes
Matched data: 0 bytes
File list size: 17670110
File list generation time: 37.718 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 11527010557
Total bytes received: 1887490

sent 11527010557 bytes received 1887490 bytes 21212323.91 bytes/sec
total size is 20610660916 speedup is 1.79

File size Transferred
11.5 MB


Exclude a Pattern

rsync -avz –exclude=*.rpm –stats /home/office/ /var/bk

Linux Training Packages CLICK HERE

Create an exclude file.
If you have a number of extensions you want to exclude, create a file and then tell rsync where the file is so that these extensions or patterns will not be transferred.

rsync -avz –exclude-from=/home/office/exclude –stats /home/office/ /bk
Here the file containing the patterns is listed by using –exclude-from= followed by a path to the file. As you can see the patterns in the file are not transferred.

home/office/exclude file contents, one pattern on each line.
*.rpm
*.bz2
*.tar

rsync script
This script will sync the /home where user mail is kept to a directory on a separate drive. Once the file is synced then it will be backed up with a tar command in the example above.

########################################
#!/bin/sh
#
/usr/bin/rsync -a – -verbose – -stats /home /bk/home
if [ $? -ne 0 ]; then
FAILED=1
fi
########################################

Crontab By using crontab -e you will be able to setup cron jobs that will run the two scripts above as often as you need.
17 8-17 * * * /root/rsync.sh
47 8-17 * * * /root/bk.sh

If you created a script like this, below is the output.

/usr/bin/rsync -a –verbose –stats /home /bk/home

—cut—
home/mike/wiki/scribus/sc4.png
home/mike/wiki/scribus/sc5.png
home/mike/wiki/scribus/sc6.png
home/mike/wiki/scribus/sc7.png
home/mike/wiki/scribus/sc9.png
home/mike/work_bridge.png
home/mike/yum.png
home/mike/yum2.rtf
home/mike/zone.192.168.5.23
home/mike/zones.png

Number of files: 8195
Number of files transferred: 7376
Total file size: 6677491116 bytes
Total transferred file size: 6677490762 bytes
Literal data: 6677490762 bytes
Matched data: 0 bytes
File list size: 218205
Total bytes sent: 6678839831
Total bytes received: 147540

sent 6678839831 bytes received 147540 bytes 12045062.89 bytes/sec
total size is 6677491116 speedup is 1.00

About these ads
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 56 other followers

%d bloggers like this: