Back up script

Earlier this week the Disk of Nex died. While it is back up with a bigger and faster disk (not everything’s bad about a failure :D ) I was lucky it “warned” me before actually dying totally so I could create a backup. Here I want to share the simple, yet powerful backup script I use for this:
#!/bin/sh

# Simple rsync "driver" script.  (Uses SSH as the transport layer.)
# http://www.scrounge.org/linux/rsync.html

# Demonstrates how to use rsync to back up a directory tree from a local
# machine to a remote machine.  Then re-run the script, as needed, to keep
# the two machines "in sync."  It only copies new or changed files and ignores
# identical files.

# Destination host machine name
DEST="192.168.0.91"

# User that rsync will connect as
# Are you sure that you want to run as root, though?
USER="cxd"

# Directory to copy from on the source machine.
BACKDIR="/home/cxd/"

# Directory to copy to on the destination machine.
DESTDIR=/storage/`hostname`

# excludes file - Contains wildcard patterns of files to exclude.
# i.e., *~, *.bak, etc.  One "pattern" per line.
# You must create this file.
EXCLUDES=/home/cxd/bin/backup-excludes

# Options.
# -n Don't do any copying, but display what rsync *would* copy. For testing.
# -a Archive. Mainly propogate file permissions, ownership, timestamp, etc.
# -u Update. Don't copy file if file on destination is newer.
# -v Verbose -vv More verbose. -vvv Even more verbose.
# See man rsync for other options.

# For testing.  Only displays what rsync *would* do and does no actual copying.
#OPTS="-n -vv -u -a --rsh=ssh --exclude-from=$EXCLUDES --stats --progress"
# Does copy, but still gives a verbose display of what it is doing
OPTS="-v -u -a --rsh=ssh --exclude-from=$EXCLUDES --stats"
# Copies and does no display at all.
#OPTS="--archive --update --rsh=ssh --exclude-from=$EXCLUDES --quiet"

# May be needed if run by cron?
#export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

# Only run rsync if $DEST responds.
VAR=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
if [ $VAR -eq 0 ]; then
rsync $OPTS $BACKDIR $USER@$DEST:$DESTDIR
else
echo "Cannot connect to $DEST."
fi
As you may have noticed, I’m not the author, but it’s distributed under the GPL and it makes backing up really easy. From now on I’ll run it on a daily basis with a cron-job. Thanks Wayne for this great help :)
Did you like this? Share it:

4 Responses to “Back up script”

  1. Tim Kissane  on February 25th, 2008

    This is my first visit to your blog; found it via EntreCard. Very nice design and useful content! I’m a Linux fanatic and I love to see what others are doing on their *nix boxes. Backups are not sexy, so it’s not a subject that gets enough attention in blogs. Thanks for this post and the link to the author’s site. Peace.

    Reply

  2. Tim Kissane  on February 25th, 2008

    Not surprisingly, CommentLuv didn’t find my last post. My domain is redirected from my main server to a box at home. Allow me to try the direct IP, out of curiousity. In any case, it’s a nice plugin and a nice idea.

    Tim Kissane’s last blog post..Blackle – Green Google!

    Reply

  3. nitric oxide  on January 9th, 2011

    Spot on with this write-up, I actually think this website wants way more consideration. I?ll in all probability be again to read far more, thanks for that info.

    Reply

  4. weight loss  on January 9th, 2011

    I discovered your blog site on google and verify a few of your early posts. Proceed to keep up the superb operate. I just extra up your RSS feed to my MSN Information Reader. Seeking ahead to studying extra from you in a while!?

    Reply


Leave a Reply