#!/bin/sh # incremental-backups: Backups developer's website files # Copyright (C) 2009 David Leutzinger (leutzdave @ charter.net) # /home/david/bin/Website/backup/incremental-backups # 2009-08-17 vs 0.1 # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # ---------- Main ---------- date=`date "+%Y-%m-%d-T%H:%M:%S"` USER_DIR="home/david" SOURCE="/home/david/http" TARGET="/mnt/data/$USER_DIR/Backups/back-$date" LOGFILE="/mnt/data/$USER_DIR/back-$date.log" EXCLUDE="" DIRS=`ls -1t /mnt/data/$USER_DIR/Backups/ | grep -v current` count="0" #echo "DIRS = " #echo "$DIRS" #echo "Pausing ... Press [Enter]" ; read pause for i in $DIRS do if [ -d "/mnt/data/$USER_DIR/Backups/$i" ];then count=`expr $count + 1` echo "Backup #$count = /mnt/data/$USER_DIR/Backups/$i" | tee -a $LOGFILE if [ "$count" -gt 6 ];then echo "Removing backup #$count" | tee -a $LOGFILE rm -rf "/mnt/data/$USER_DIR/Backups/$i" rm "/mnt/data/$USER_DIR/$i.log" #echo "Pausing ... Press [Enter]" ; read pause fi fi done echo "Making new backup $TARGET" | tee -a $LOGFILE rsync -aP --link-dest=/mnt/data/$USER_DIR/Backups/current --delete-after --delete-excluded --delay-updates $EXCLUDE $SOURCE $TARGET rm /mnt/data/$USER_DIR/Backups/current | tee -a $LOGFILE ln -s back-$date /mnt/data/$USER_DIR/Backups/current