Backing up a directory to a remote file system

Garrett Goebel garrett at scriptpro.com
Thu Jan 29 21:01:21 CST 2004


Jason Clinton wrote:
> Jason Clinton wrote:
> |
> | I want to perform incremental backups of /pub on a Linux
> | samba server to a box on the other side of Kansas City.
> | Some combination involving tar looks like the right
> | direction to go but I can't think of a way to have
> | tar incrementally compare the files being backed up to
> | the remote tarball before the operation begins. I'm not
> | ready to rely on sshfs until it is more stable.
>
> I should probably clarify the problem a bit more:
>
> I want one entire backup to occur on Saturday night and then
> incremental additions to that remote file to occur throughout
> the week to minimize transfers.

How about a cron job to do local monthly and weekly full backups, and
nightly incremental backups. Then finish off with a scp of backup files
which have changed in the last day to a remote host?

I dislike the idea of compounding steps when a failure could cause data
loss. I'd do separate full and incremental backups locally... then copy them
to a remote server.

Here's a possible (untested) nightly cron job...

#!/bin/sh
# full and incremental remote backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny at freebsd.org>
# and modified by Gerhard Mourani <gmourani at videotron.ca>
# and modified by Garrett Goebel <garrett at scriptpro dot com>

PATH=/usr/local/bin:/usr/bin:/bin
BNAME=$HOSTNAME          # name by which to group backups
BSRCDIR="/pub"           # dirs to backup
BDSTDIR=/backups         # path at which to place backups
BSCPDEST="user at host:dir" # scp destination

TAR=/bin/tar             # location of tar
DOW=`date +%a`           # Thu
DOM=`date +%d`           # 29
MON=`date +%m`           # 01
YEAR=`date +%G`          # 2004

if [ ! -e $BDSTDIR/last-full ]; then
echo  "Thu Jan  1 00:00:00 GMT 1970" > $BDSTDIR/$BNAME-last-full
echo  "Thu Jan  1 00:00:00 GMT 1970" > $BDSTDIR/$BNAME-last-incr
fi

# Monthly full backup
if [ $DOM = "01" ]; then
$TAR -czf $BDSTDIR/$BNAME-$YEAR-$MON-$DOM.tgz $BSRCDIR
fi

# Weekly full backup - overwrites last week's
NOW=`date`
if [ $DOW = "Sat" ]; then
$TAR -czf $BDSTDIR/$BNAME-$DOW-full.tgz $BSRCDIR
echo $NOW > $BDSTDIR/$BNAME-last-full

# Otherwise daily incremental backup - overwrites last week's
else
if [ $DOW = 'Sun' ]; then
NEWER="`cat $BDSTDIR/$BNAME-last-full`"
else
NEWER="`cat $BDSTDIR/$BNAME-last-incr`"
fi
$TAR --newer="$NEWER" -czf $BDSTDIR/$BNAME-$DOW-incr.tgz $BSRCDIR
echo $NOW > $BDSTDIR/$BSRCHOST-last-incr
fi

scp `find $BDSTDIR -mtime -1 -type f` $BSCPDEST

--
Garrett Goebel
IS Development Specialist

ScriptPro                   Direct: 913.403.5261
5828 Reeds Road               Main: 913.384.1008
Mission, KS 66202              Fax: 913.384.2180
www.scriptpro.com          garrett at scriptpro dot com






More information about the Kclug mailing list