Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 05-18-2008, 10:07 AM   #1
LQ Newbie
Registered: Oct 2007
Distribution: SuSE, Redhat, Debian
Posts: 25

Rep: Reputation: 15
Simple rsync script for backing up (multiple) pc's to a usb-disk

Hi all,

I've searched all over the place for a simple backup script that would backup my linux pc's to a usb-disk. Finally I've made something myself.

What you will need:
* A usb disk,connected to your main pc/server
* An ssh connection with "authorized_keys" to your other pc's, or another way that your other pc's are connected to your server.
* The rsync program

After that you will need the two scripts below.
Put it in /etc/cron.daily or /etc/cron.weekly and your basically done.
Of course it could use improvement as far as filtering goes.

What you will get from the first script:
On your usb disk you wil get in your backup-directory the names of the week with the hostname of your pc and the dirs you have selected to backup.

From the second script you will get in your main backup dir a "Static" directory in which you put the things that dont need to be backup up so often, only once in a while.

In the script edit the variables at the beginning to your needs.

Script 1 will copy the basic system files to your USB disk
********CUT HERE SCRIPT 1****************


# Set variables
DST=/Backup # Destination dir
USBDISK=/dev/sdb1 # Your USB disk
MOUNTPOINT=/Backup # Mountpoint of USB disk
DAY="`date +%A`" # Dayname full
HOSTS="pc1 pc2 pc3" # Check these hosts
# Backup these dirs from the hosts:
DIR="/etc /home /root /usr/local/bin /var/lib/rpm /var/spool/cron/tabs /srv/www/htdocs"

# Start backup
# Check if mounted usb drive
mount | grep $USBDISK | grep $MOUNTPOINT 2>&1 > /dev/null || \
( echo "ERROR! USB disk not mounted!" ; exit 1 )

# Rotate the hosts
for host in $HOSTS
# Make the backup dir
[ -d $DST/$DAY/$host ] || mkdir -p $DST/$DAY/$host
for dir in $DIR
if [ "$host" = "`uname -n`" ]
# Local backup has no host to copy from
rsync -aC --delete $dir $DST/$DAY/$host
# Remote backup has a host to copy from
rsync -aC --delete $host:$dir $DST/$DAY/$host

********CUT HERE SCRIPT 1****************

Script 2 will copy the static files to your USB disk
Once again, edit the variables in the beginning to your needs.
And for the stactic components edit manually the dirs you want to backup. (Still need to tidy that)
Mind you though, that I assume no two dir names are the same for that Static components, so they will not overwrite eachother

********CUT HERE SCRIPT 2****************

DST=/Backup/Static # Destination dir
USBDISK=/dev/sdb1 # Your USB disk
MOUNTPOINT=/Backup # Mountpoint of USB disk

# Check if mounted usb drive
mount | grep $USBDISK | grep $MOUNTPOINT 2>&1 > /dev/null || \
( echo "ERROR! USB disk not mounted!" ; exit 1 )

# Make the backup dir
[ -d $DST ] || mkdir -p $DST

# RSYNC the static components
# Edit these to your own dirs
rsync -aC /My/Videos $DST
rsync -aC /My/Mysic $DST
rsync -aC /My Games $DST

# Remote hosts
rsync -aC pc2:/Games/UT2004 $DST

********CUT HERE SCRIPT 2****************

Have fun


backup, rsync+ssh

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rsync not backing up MySQL cabron Linux - Server 3 12-26-2007 07:56 AM
Help with rsync command (or script) multiple file backups luis14 Linux - Software 3 11-08-2007 10:07 PM
rsync and backing up danimalz Linux - Software 12 10-24-2005 12:01 PM
RSync or another way? Backing Up Off-site. kemplej Linux - Software 0 08-19-2004 04:55 PM
copying/backing up between 2 linux pc's across network. Guerin Linux - Newbie 5 05-04-2004 06:47 AM

All times are GMT -5. The time now is 05:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration