Differential Backup sample sh script:
#!/bin/bash
## Edit part---------------------
SOURCE_PATH="/home/abc"
DESTINATION="/mnt/usb"
CYCLEDAY="30"
LOG="/var/log/backup.log"
## ------------------------------
## DONT modify below code ##
## variable assign
NEW_BACKUP_DIR=`date +%F`
LAST_BACKUP_DIR=`ls -1 $DESTINATION | tail -n 1`
OLD_BACKUP_DIR=`ls -1 $DESTINATION | head -n 1`
NUM_BACKUP=`ls -1 $DESTINATION | wc -l`
## delete old log
rm -f $LOG
## make new backup directory
mkdir -p $DESTINATION/$NEW_BACKUP_DIR
## check if over 90 backup directory to delete the oldest one
if [ "$NUM_BACKUP" -ge "$CYCLEDAY" ]; then
echo "Deleting the oldest backup from storage, timestamp of backup - $OLD_BACKUP_DIR" >> $LOG
rm -rf $DESTINATION/$OLD_BACKUP_DIR
fi
## rsync differential backup compare with last(yesterday) backup directory (copy symbolic link only)
/usr/bin/rsync -rltcv --delete --copy-unsafe-links --link-dest=$DESTINATION/$LAST_BACKUP_DIR $SOURCE_PATH $DESTINATION/$NEW_BACKUP_DIR >> $LOG
## To avoid compare the empty backup directory
## in rsync differential, remove empty new backup directory
if [ `find $DESTINATION/$NEW_BACKUP_DIR | wc -l` -eq 1 ]; then
rm -rf $DESTINATION/$NEW_BACKUP_DIR
fi
Server is hosted by Alanstudio
Linux Operating System
Recommend screen resolution 1024 x 768 / IE / FireFox
Alan Studio © 2007 by Alan Cheung Hin Lun. All rights reserved.
|