Skip to content

Instantly share code, notes, and snippets.

@grahamg
Created February 14, 2011 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamg/825365 to your computer and use it in GitHub Desktop.
Save grahamg/825365 to your computer and use it in GitHub Desktop.
Rsync Backup Script
#!/bin/bash
# Destination host machine name
DEST="beta.grahamg.org"
# User that rsync will connect as
# Are you sure that you want to run as root, though?
USER="remote_backup"
# Directory to copy from on the source machine.
BACKDIR="/home/"
# Directory to copy to on the destination machine.
DESTDIR="/home/remote_backup/"
# excludes file - Contains wildcard patterns of files to exclude.
# i.e., *~, *.bak, etc. One "pattern" per line.
# You must create this file.
# EXCLUDES=/root/bin/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"
# This is the default option string that normally gets used. The above $OPTS are examples.
OPTS="-v -u -a --rsh=ssh --progress --stats --exclude 'cpeasyapache' --exclude 'tmp' --exclude 'MySQL-install'"
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment