#!/bin/ksh # # Poor man's backup tool # # # Edit those settings # backupdir=/data/backup/ backuplist=/root/bin/backup.lst [[ ! -d $backupdir ]] && print $backupdir does not exist && exit 1 [[ ! -f $backuplist ]] && print $backuplist not available && exit 1 folders=`cat $backuplist` # # Other settings # dateformat=`date +%Y-%m-%d-%H-%M-%S` maxold=10 #z=xz #z=bzip2 z=gzip # # Clean-up old backups and proceed with new ones. # Note. -mtime before the -name -o -name otherwise -name takes precedence. # Note. could use -Btime isntead of -mtime on freebsd. # Trash. find /data/backup/ -type f -mtime +5d -name "*.gz" -o -name "*.bz2" | xargs rm -f # -mtime +${maxold}d \ # fcleanup() { print cleaning up ${maxold} days old backups against $backupdir... \\c find $backupdir -type f \ -mtime +${maxold} \ -name "*.gz" -o -name "*.bz2" -o -name "*.xz" | xargs rm -f && print done #-exec rm -f {} \; && print done } fmain() { fcleanup #fmysql ffiles #print $backupdir content: #ls -alhF $backupdir #print uploading backups to dedibackup \\c #date +%Y-%m-%d-%H-%M-%S #/usr/local/bin/ftpmirror upload.backup #[[ -x $HOME/bin/backup_lftp.ksh ]] && $HOME/bin/backup_lftp.ksh } # # web hosts and email # # I don't want to use -P and I don't want to see that warning either, # tar: Removing leading '/' from member names # so I am proceeded with a relative path from the root of the system tree. #TODO: adjust compression type depending on .lst... ffiles() { cd / for folder in $folders; do relative=`echo $folder | sed 's|^/||'` underscore=`echo $folder | sed 's|^/||; s|/|_|g'` [[ $z = xz ]] && args="-cJp" && dest=$backupdir/$dateformat.$underscore.tar.xz [[ $z = bzip2 ]] && args="-cjp" && dest=$backupdir/$dateformat.$underscore.tar.bz2 [[ $z = gzip ]] && args="-czp" && dest=$backupdir/$dateformat.$underscore.tar.gz print backing up $folder/... \\c tar $args \ --exclude *.avi \ --exclude *.pdf \ --exclude "unix/Slackware/*" \ -f $dest $relative && print done unset relative underscore args dest done; unset folder } date fmain $@ date