#!/bin/bash # Please see the backup(8) man page for full documentation. DATE=$(date +%Y%m%d) BACKUPS=/var/backups DUMPS=7 # Search for the last full backup. LEVEL0=$(find $BACKUPS -name "*full.tgz" | sort | tail -n1) # Search and count incremental dumps newer than the last full backup. INCR=$(find $BACKUPS -name "*incremental.tgz" -newer $LEVEL0 | wc -l) # If there is at least one full backup and less than specified incremental dumps if [ ! -z $LEVEL0 ] && [ $INCR -le $DUMPS ] then TYPE=incremental else TYPE=full rm -f $BACKUPS/*.snapshot # Remove the first backup set (full and incremental dumps) if there is a second one. find $BACKUPS -name "*.tgz" ! -newer $LEVEL0 ! -wholename $LEVEL0 -exec rm {} \; fi nice tar -cz \ --exclude ".nobackup" \ --exclude "nobackup" \ --exclude="/home/irc/*" \ --exclude='/home/slip/*' \ --exclude='/home/angelok/*' \ --exclude='/home/ubergeek/*' \ --exclude='/home/amcclure/*' \ --exclude='/home/fosslinux/*' \ --exclude='/home/zszoke/*' \ --exclude='/home/duitser/*' \ --exclude='/home/fltk/*' \ --exclude='/home/nirvana/*' \ --exclude='/home/transfusion/*' \ /home/ \ /var/games/minetest-server/.minetest/ \ /var/lib/minecraft/paper/ \ /var/lib/bzflag/ \ /var/lib/znc/configs/ /var/lib/znc/moddata/ \ /var/spool/cron/ \ /var/spool/anacron/ \ /var/lib/botany/sqlite/ \ -g $BACKUPS/$TYPE.snapshot \ -f $BACKUPS/$DATE-$TYPE.tgz chown root:sudo $BACKUPS/{$DATE*.tgz,$TYPE.snapshot} chmod 640 $BACKUPS/{*.tgz,$TYPE.snapshot} if [ $TYPE = full ] then cp -p $BACKUPS/full.snapshot $BACKUPS/incremental.snapshot fi # Database backup find $BACKUPS -name "*.sql.gz" -mtime +$DUMPS -exec rm {} \; mysqldump --all-databases | gzip > $BACKUPS/$DATE-all_databases.sql.gz chown root:sudo $BACKUPS/$DATE*.sql.gz chmod 640 $BACKUPS/*.sql.gz