backup
#!/bin/bash ########################################################### # set prefix=, from= and to= in backup.cfg ... test -e "$0.cfg" || exit 1; source $0.cfg; test -z "$prefix" && exit 2; test -z "$from" && exit 3; cd /; test -d "$to" || exit 4; today=$(date +"%Y-%m-%d"); test -e "$to/$prefix-$today.tgz" && exit 0; ago1d=$(date +"%Y-%m-%d" -d "-1 day"); test -e "$to/$prefix-$today-d.tgz" && exit 0; ago1w=$(date +"%Y-%m-%d" -d "-1 week"); test -e "$to/$prefix-$today-w.tgz" && exit 0; ago4w=$(date +"%Y-%m-%d" -d "-4 week"); test -e "$to/$prefix-$today-m.tgz" && exit 0; ago3m=$(date +"%Y-%m-%d" -d "-3 months"); wkday=$(date +"%w-%d"); case "$wkday" in *-01-01.tgz) ;& # keep full backups of Jan, Apr, Jun and Oct *-04-01.tgz) ;& *-07-01.tgz) ;& *-10-01.tgz) echo "Monthly full backup $to/$prefix-$today.tgz"; echo; tar -cvvzf $to/$prefix-$today.tgz --totals $from|grep -v /$ -; ;; *-01) echo "Monthly full backup $to/$prefix-$today-m.tgz"; echo; tar -cvvzf $to/$prefix-$today-m.tgz --totals $from|grep -v /$ -; ;; 0-??) echo "Weekly backup $to/$prefix-$today-w.tgz (files since $ago1w)"; echo; tar -cvvzf $to/$prefix-$today-w.tgz --totals -N "$ago1w 00:00:00" $from|grep -v /$ -; ;; *) echo "Daily backup $to/$prefix-$today-d.tgz (files since $ago1d)"; echo; tar -cvvzf $to/$prefix-$today-d.tgz --totals -N "$ago1d 00:00:00" $from|grep -v /$ -; ;; esac >"$to/backup.log"; 2>"$to/backup.tmp" grep -v "ndert; nicht gesichert." "$to/backup.tmp" >"$to/backup.err"; rm "$to/backup.tmp"; echo >>"$to/backup.log"; if test -e "$to/$prefix-$ago1w-d.tgz"; then echo "removing $to/$prefix-$ago1w-d.tgz" >>"$to/backup.log"; rm "$to/$prefix-$ago1w-d.tgz" >>"$to/backup.log" 2>>"$to/backup.err"; fi if test -e "$to/$prefix-$ago4w-d.tgz"; then echo "removing $to/$prefix-$ago4w-d.tgz" >>"$to/backup.log"; rm "$to/$prefix-$ago4w-d.tgz" >>"$to/backup.log" 2>>"$to/backup.err"; fi if test -e "$to/$prefix-$ago4w-w.tgz"; then echo "removing $to/$prefix-$ago4w-w.tgz" >>"$to/backup.log"; rm "$to/$prefix-$ago4w-w.tgz" >>"$to/backup.log" 2>>"$to/backup.err"; fi if test -e "$to/$prefix-$ago3m-w.tgz"; then echo "removing $to/$prefix-$ago3m-w.tgz" >>"$to/backup.log"; rm "$to/$prefix-$ago3m-w.tgz" >>"$to/backup.log" 2>>"$to/backup.err"; fi if test -e "$to/$prefix-$ago3m-m.tgz"; then echo "removing $to/$prefix-$ago3m-m.tgz" >>"$to/backup.log"; rm "$to/$prefix-$ago3m-m.tgz" >>"$to/backup.log" 2>>"$to/backup.err"; fi cat "$to/backup.log"; echo; cat "$to/backup.err"; exit 0;
Inkremetelles Backup (täglich, wöchentlich, monatlich)(3.3kB)
Download