Re: Vilket backupprogram är bra/bäst?
Claes Hohner
claes.h at multek.se
Mon Dec 19 06:56:19 CET 2005
Jag kör följande lilla script, som använder rsync, för att köra incremental
for ever.
Jag använder rsyncs länk-funktion så att varje tillfälle ser ut som en
fullständig backup.
Här görs det lokalt, men jag använder det även över nätverket genom att
sätta dstdir såhär: set dstdir = "backup at backup:/storage", och ha
ssh-nycklar för det.
#!/bin/csh
# user configuration variables
set notifyemail = "claes.h at multek.se" # backup reports
receiver
set srcdir = "/storage" # no trailing /
set dstdir = "/backup" # no trailing /
# script variables
set today = `date "+%y%m%d"`
set yesterday = `date -v -1d "+%y%m%d"`
set time = `date "+%H%M%S"`
set dstindex = `ls -rt $dstdir`
set dstdirindex = `ls -t $dstdir/$dstindex[$#dstindex]`
set lastday = foobar
set lasttime = foobar
if ($#dstindex != 0) then
set lastday = $dstindex[$#dstindex]
set lasttime = $dstdirindex[$#dstdirindex]
endif
set subject = "Local backup report "`date`
set logfile = "/var/log/backup/local-$today-$time.log" # output is logged
to this file
# start of backup script
echo "Backup started "`date` >> $logfile
if ($lastday == $today) then
echo "Not the first backup of today. Linking from previous backup:
$dstdir/$lastday/$lasttime." >> $logfile
mkdir $dstdir/$today/$time >>& $logfile
/usr/local/bin/rsync -a --delete
--link-dest=$dstdir/$lastday/$lasttime --exclude "winbas/" $srcdir/
$dstdir/$lastday/$time >>& $logfile
else if (-d $dstdir/$lastday/$lasttime) then
echo "This is the first backup of today. Linking from previous
backup: $dstdir/$lastday/$lasttime." >> $logfile
mkdir $dstdir/$today >>& $logfile
mkdir $dstdir/$today/$time >>& $logfile
/usr/local/bin/rsync -a --delete
--link-dest=$dstdir/$lastday/$lasttime --exclude "winbas/" $srcdir/
$dstdir/$today/$time >>& $logfile
else
echo "This is the first backup. Doing a complete rsync of $srcdir
to $dstdir/$today/$time." >> $logfile
mkdir $dstdir/$today >>& $logfile
mkdir $dstdir/$today/$time >>& $logfile
/usr/local/bin/rsync -v -a --delete --exclude "winbas/" $srcdir/
$dstdir/$today/$time >>& $logfile
set subject = "New complete backup! Backup report "`date`
endif
set df = `df -h |grep $dstdir`
echo "Free space on destination after this backup: $df[4]" >> $logfile
# mail the backup report to the user specified by $notifyemail
mail -s "$subject" $notifyemail <<ENDMAIL
`cat $logfile`
ENDMAIL
More information about the BUS
mailing list