DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2008-10-14 00:36:07

Unit106
Member
Registered: 2008-10-06
Posts: 7

Grandfather-father-son backup

Grandfather-father-son backup script for backing up your first drive to your second drive:

Code:

#!/ffp/bin/sh
export PATH=/ffp/sbin:/ffp/bin:$PATH

# Set Source Path
SRCPATH='/mnt/HD_a2/Data'

# Set the Destination Path
DSTPATH=/mnt/HD_b2/Backup_NAS/Data

# Set path to Fun_Plug files
# Fun_Plug 3.0 or 4.0
# ffppath=/mnt/HD_a2/fun_plug.d
# Fun_Plug 5.0
FFPPATH=/ffp

# Set Rsync
RSYNC=$FFPPATH/bin/rsync

# Set date variables
# date --help
# %w   day of week (0..6);  0 represents Sunday
# %V   week number of year with Monday as first day of week (01..53)
WEEKDAY=`date +'%w'`
YESTERDAY=`expr \( $WEEKDAY + 6 \)  % 7`
WEEKNUMBER=`date +'%V'`
# Convert the string to a number
WEEKNUMBER=`expr \( $WEEKNUMBER + 0 \)`
LASTMONTH=`expr \( 53 + $WEEKNUMBER - 4 \) % 53`
MONTHCOPY=`expr \( $WEEKNUMBER % 4 \)`

# Set directories
BACKUPDIR=/$DSTPATH/Daily/$WEEKDAY
LINKDIR=/$DSTPATH/Daily/$YESTERDAY
WEEKBACKUP=/$DSTPATH/Weekly/$WEEKNUMBER
LASTMONTHBACKUP=/$DSTPATH/Weekly/$LASTMONTH
MONTHBACKUP=/$DSTPATH/Monthly/$WEEKNUMBER

# Set logfile
LOGFILE=/$DSTPATH/Daily_$WEEKDAY.list

# Make directories
mkdir -p /$DSTPATH/Daily/
mkdir -p /$DSTPATH/Weekly/
mkdir -p /$DSTPATH/Monthly/

# Backup source paths
rm -rf $BACKUPDIR 
$RSYNC -v -x -a --delete --link-dest=$LINKDIR $SRCPATH $BACKUPDIR/ >> $LOGFILE

# Copy data for weekly and monthly purposes
if [ $WEEKDAY -eq 0 ]
then 
     rm -rf $LASTMONTHBACKUP
     rm -rf /$DSTPATH/Weekly_$LASTMONTH.list
     
     cp -al $BACKUPDIR/* $WEEKBACKUP
     cp -af $LOGFILE /$DSTPATH/Weekly_$WEEKNUMBER.list
     
     if [ $MONTHCOPY -eq 0 ]  
     then 
          rm -rf $MONTHBACKUP 
          rm -rf /$DSTPATH/Monthly_$WEEKNUMBER.list
          cp -al $BACKUPDIR/* $MONTHBACKUP
          cp -af $LOGFILE /$DSTPATH/Monthly_$WEEKNUMBER.list
     fi
fi

More about the GFS principle: http://en.wikipedia.org/wiki/Grandfathe … Son_Backup

Offline

 

#2 2008-10-27 21:54:51

zeroday
Member
Registered: 2007-07-01
Posts: 136
Website

Re: Grandfather-father-son backup

is this everything you need or do you need extra scripts?

I like the idea to see a total backup and than the snapshots..

Offline

 

#3 2008-10-27 23:33:42

Unit106
Member
Registered: 2008-10-06
Posts: 7

Re: Grandfather-father-son backup

zeroday wrote:

is this everything you need or do you need extra scripts?

I like the idea to see a total backup and than the snapshots..

Schedule this script and you have every day a total backup (Rsync creates hardlinks to existing files so only new files and updates will be added to the already existing files). See the Time Machine topic (http://dns323.kood.org/forum/viewtopic. … 25&p=1). Only this script will cleanup older backups.

Last edited by Unit106 (2008-10-27 23:34:02)

Offline

 

#4 2009-03-09 00:18:54

uyuni
Member
From: Denmark
Registered: 2007-12-29
Posts: 31

Re: Grandfather-father-son backup

I have been running the script for 7 days now and there is no weekly backup!

Reading the script, it seems that the weekly backup is taken on day 0 (sunday) after the daily backup has been taken. This means that you have backups from the last 6 days now because you just overwrote the backup from last sunday with today's backup and furthermore, your weekly backup is from today and not from last sunday. Or am I missing something?

Also, I can only get the script to work if I change
cp -al $BACKUPDIR/* $WEEKBACKUP
to
cp -al $BACKUPDIR $WEEKBACKUP
and the same for the month backup I guess.

I was also wondering that it would probably be much and faster to just
mv $BACKUPDIR $WEEKBACKUP?

And wouldn't it be much faster and less wear on the disk if one left out the line
rm -rf $BACKUPDIR

What do you think?

BTW, I tried using weekday names instead of numbers but it appears that busybox's version of the date command doesn't support the 'yesterday', 'tomorrow', 'next-monday', etc. syntax :-(


D-Link DNS-323 firmware 1.08 + Samsung HD203WI + Samsung HD103UJ + ffp-0.5 + addons

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB