скрипт для инкрементного бекапа на rsync с определенным количеством хранящихся копий
#!/bin/sh
TASKNAME=0_1160_profiles
BACKUPDIR=/mnt/hdd30Tb/rsync_backups
SOURCEDIR=/mnt/1160
EXCLUDE='--exclude="Thunderbird/" --exclude="thunderbird/"'
donttouch=15
#
path=$BACKUPDIR/$TASKNAME/increment_backup
count=$(ls $path|grep "[0-9]\{1,\}"|wc -l)
if [ $count -gt $donttouch ]; then
countdelete=$(($count-$donttouch))
dirs=$(ls -l $path|awk '{print $9}'|grep "[0-9]\{1,\}"|sort -n|head -n$countdelete)
echo `/bin/date +%d.%m.%y_%H:%M:%S`" - "$TASKNAME" - START remove old backups. count: "$countdelete >> $BACKUPDIR/$TASKNAME/backup.log
for dir in $dirs
do
rm -rf $path/$dir
done
echo `/bin/date +%d.%m.%y_%H:%M:%S`" - "$TASKNAME" - FINISH remove old backups" >> $BACKUPDIR/$TASKNAME/backup.log
fi
#
echo `/bin/date +%d.%m.%y_%H:%M:%S`" - "$TASKNAME" - START increment backup" >> $BACKUPDIR/$TASKNAME/backup.log
INCREMENTDATADIR=`/bin/date +%Y%m%d_%H%M`
/usr/bin/rsync --progress -aqv \
--exclude="Thunderbird/" --exclude="thunderbird/" --force \
--ignore-errors --delete -b --backup-dir=$BACKUPDIR/$TASKNAME/increment_backup/$INCREMENTDATADIR \
$SOURCEDIR/ $BACKUPDIR/$TASKNAME/last_full_backup/
echo `/bin/date +%d.%m.%y_%H:%M:%S`" - "$TASKNAME" - FINISH increment backup" >> $BACKUPDIR/$TASKNAME/backup.log