Current location

narf Source control manager Git

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2>2007-12-24 13:25:31 +0000
committershtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2>2007-12-24 13:25:31 +0000
commit6667c96620fcb37a781deac2ce8872c3aeab4614 (patch)
tree2dbebb2f95070c62146eeffd0f26635c1cc86b6a /backups.sh
parenta01e82ad5013941609f09d9622ca7647feff7540 (diff)
[scripts] Added some abandonned scripts.
git-svn-id: svn+ssh://scm.narf.ssji.net/svn/shtrom/scripts@92 1991c358-8f32-0410-a49a-990740bdf4c2
Diffstat (limited to 'backups.sh')
-rwxr-xr-xbackups.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/backups.sh b/backups.sh
new file mode 100755
index 0000000..0e0a0c1
--- /dev/null
+++ b/backups.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+TOSAVE="/home /etc /var/cvsroot /var/svn /var/www /var/yp"
+EXCLUDES="--exclude /home/guest --exclude /home/ftp --exclude /home/gullutc --exclude */download/* --exclude */nosave/* --exclude */lost+found/*"
+USETRASH=NO # NO to force automatic deletion
+
+BACKUP_FOLDER=/data/backup
+WBACKUP_FOLDER=${BACKUP_FOLDER}/weekly
+MBACKUP_FOLDER=${BACKUP_FOLDER}/monthly
+TRASH_FOLDER=${BACKUP_FOLDER}/trash
+
+RSYNC=/usr/bin/rsync
+DATE=/bin/date
+TAR=/bin/tar
+FIND=/usr/bin/find
+CP=/bin/cp
+RM=/bin/rm
+MV=/bin/mv
+LN=bin/ln
+BASENAME=/usr/bin/basename
+
+NOWSTRING=`$DATE +%Y%m%d`
+WEEKDAY=`$DATE +%u`
+MONTHDAY=`$DATE +%d`
+
+# daily backup
+for dir in $TOSAVE ; do
+ $RSYNC -a --delete-excluded --delete ${EXCLUDES} $dir $BACKUP_FOLDER
+done
+
+# weekly saves on mondays
+if [ "$WEEKDAY" == "1" ]; then
+ for dir in $TOSAVE ; do
+ # remove saves older than 4 weeks ago (31 days)
+ if [ "$USETRASH" = "NO" ]; then
+ $FIND ${WBACKUP_FOLDER} -ctime +31 -exec $RM \{\} \;
+ else
+ $FIND ${WBACKUP_FOLDER} -ctime +31 -exec $MV \{\} /tmp \;
+ fi
+ # make new backups
+ pushd ${BACKUP_FOLDER} > /dev/null
+ $TAR cjf ${WBACKUP_FOLDER}/${dir//\//_}-${NOWSTRING}.tar.bz2 ./`$BASENAME ${dir}`
+ popd > /dev/null
+
+ # monthly saves
+ if [ $MONTHDAY -le 7 ]; then
+ # remove saves older than 3 months ago (93 days)
+ if [ "$USETRASH" == "NO" ]; then
+ $FIND ${MBACKUP_FOLDER} -ctime +93 -exec $RM \{\} \;
+ else
+ $FIND ${MBACKUP_FOLDER} -ctime +93 -exec $MV \{\} /tmp \;
+ fi
+ # copy new monthly backup
+ $MV ${WBACKUP_FOLDER}/${dir//\//_}-${NOWSTRING}.tar.bz2 ${MBACKUP_FOLDER}
+ pushd ${WBACKUP_FOLDER} > /dev/null
+ $LN -s ${MBACKUP_FOLDER}/${dir//\//_}-${NOWSTRING}.tar.bz2
+ popd > /dev/null
+ fi
+ done
+fi
+