Snalk

Snalk » OS Tutorials » Unix » Basic Backups with rsync

Reply
  #1 (permalink)  
Old 10-31-2008, 11:03 AM
Junior Member
 
Join Date: Oct 2008
Posts: 4
Post Basic Backups with rsync

Basic Backups with rsync



You can perform basic complete backups with rsync just like with cfengine. Here is an example shell script that can be executed on a daily basis on each of your systems:

#!/bin/bash

BACKUP_PATH=backup@backup.mydomain.com:/usr/local/backup
DIRS="/etc /var /usr/local /home"

weekday='date +%a'
shorthost='hostname | sed 's/\..*$//''

rsync -a --delete $DIRS "$BACKUP_PATH/$shorthost/$weekday"


The -a switch places rsync into archive mode, which means all permissions and ownership are preserved. In addition, symbolic links, special files, and directories are also preserved. rsync also operates recursively when in archive mode, so there is no reason to specify the -r option.

The –delete switch causes any files within the destination directory that are not present in the source directory to be deleted. Since the backup directories are based on the day of the week and are reused from week to week, you need this option to prevent your backups from continuously growing. This also allows you to create a true snapshot of the system.

If you don't have enough disk space to keep multiple days worth of backup for each host, you may need to use the script or move the data to tapes. If none of this is possible, you may need to keep only one day's worth of backups using this slightly simpler script:

#!/bin/bash

BACKUP_PATH=backup@backup.mydomain.com:/usr/local/backup
DIRS="/etc /var /usr/local /home"

shorthost='hostname | sed 's/\..*$//''

rsync -a $DIRS "$BACKUP_PATH/$shorthost"


Note that I removed the –delete switch from the second example. This would not delete any files on the backup server, allowing you to retrieve files that were accidentally deleted more than 24 hours ago. It doesn't help with corrupted files because the corrupted version will be copied to the backup server anyway. You will also need to occasionally wipe out the backup directory (or run the script with the –delete switch) to prevent it from growing continuously.
Reply With Quote
Reply

Bookmarks

Tags
backups, backups with rsync, rsync, unix

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump



All times are GMT. The time now is 07:03 AM.
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.