Re: Incremental backup -- hvordan?

From: Erik Cederstrand (none@erik--cederstrand.dk.lh.bsd-dk.dk)
Date: Mon 24 Aug 2009 - 08:20:21 CEST


From: Erik Cederstrand <none@erik--cederstrand.dk.lh.bsd-dk.dk>
To: bsd-dk@bsd-dk.dk
Subject: Re: Incremental backup -- hvordan?
Date: Mon, 24 Aug 2009 08:20:21 +0200



Den 24/08/2009 kl. 01.59 skrev Anders Østergaard Jensen:
>
> Tak for tippet. Er det evt. noget teknologi, du kunne taenke dig at
> del med os herinde? :)

Så gerne. Jeg har et backupdir, /backup, hvor jeg rsync'er hver server
ned i sin egen mappe. Scriptet kører, når rsync har kørt om natten via
cron. Jeg bruger tar til at spare lidt på pladsen. Jeg modtager gerne
forslag til forbedringer.

Mvh Erik
-----------------------

#!/bin/sh
#
# Incremental backup script

BACKUPDIR=/backup # where to store the backups
TIMEDIR=/backup/last-full # where to store time of full backup
TAR=/usr/bin/bsdtar # name and locaction of tar

DOW=`/bin/date +%a` # Day of the week e.g. Mon
IOW=`/bin/date +%w` # Number of the weekday, e.g. 5
DOM=`/bin/date +%d` # Date of the month e.g. 27
FULLDAY=`/bin/date +%Y-%m-%d` # Full day, e.g. 2005-11-24
FULLDATE=`/bin/date "+%Y-%m-%d %H:%M:%S"` # Full date, e.g. 2005-11-24
13:43:15

# On the 1st of the month a permanet full backup is made.
# Every Sunday a full backup is made - overwriting last Sunday's backup.
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories.
# Otherwise it backs up files newer than the NEWER date. NEWER
# gets it's date from the file written every Sunday.

cd $BACKUPDIR

for DIRECTORY in server1 server2 server3 server4
do
     # Monthly full backup
     if [ $DOM = "01" ]; then
         $TAR -czf $DIRECTORY-$FULLDAY.tar $DIRECTORY
         chmod 400 $DIRECTORY-$FULLDAY.tar
     fi

     # Weekly full backup on Sundays
     if [ $IOW = 0 ]; then
         # Update full backup date
         echo $FULLDATE > $TIMEDIR/$DIRECTORY-full-date
         chmod 600 $DIRECTORY-$DOW.tar
         $TAR -czf $DIRECTORY-$DOW.tar $DIRECTORY
         chmod 400 $DIRECTORY-$DOW.tar

     # Incremental daily backup - overwrite last week's
     else
         # Get date of last full backup
         chmod 600 $DIRECTORY-$DOW.tar
         $TAR -cz --newer "`cat $TIMEDIR/$DIRECTORY-full-date`" -f
$DIRECTORY-$DOW.tar $DIRECTORY
         chmod 400 $DIRECTORY-$DOW.tar
     fi
done






This archive was generated by hypermail 2b30 : Mon 31 Aug 2009 - 23:00:01 CEST