Impressum:Ing. Peter GrobnerUnter der Leithen 3aA-3340 Waidhofen/Ybbs
backup
#!/bin/bash ######################################################################################################## # get prefix=""; # from=""; # to=""; from $0.cfg (eg. backup.cfg) ... ######################################################################################################## # (c) 2023 by Ing. Peter Grobner ######################################################################################################## 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; wkday=$(date +"%w-%m-%d"); test -e "$to/$prefix-$today-m.tgz" && exit 0; case "$wkday" in *-01-01) ;& # keep full backups of Jan and Jun *-07-01) 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 2>"$to/backup.tmp" >"$to/backup.log"; echo >>"$to/backup.log"; grep "Gesamtzahl geschriebener Bytes:" "$to/backup.tmp" >>"$to/backup.log"; grep -v "Gesamtzahl geschriebener Bytes:" "$to/backup.tmp"|\ grep -v "ndert; nicht gesichert." >"$to/backup.err"; rm "$to/backup.tmp"; echo >>"$to/backup.log"; find $to/ -name "$prefix-*-d.tgz" -mtime +7 -exec rm -vf {} \; >>"$to/backup.log" 2>>"$to/backup.err"; find $to/ -name "$prefix-*-w.tgz" -mtime +28 -exec rm -vf {} \; >>"$to/backup.log" 2>>"$to/backup.err"; find $to/ -name "$prefix-*-m.tgz" -mtime +92 -exec rm -vf {} \; >>"$to/backup.log" 2>>"$to/backup.err"; cat "$to/backup.log"; echo cat "$to/backup.err"; exit 0;
Inkremetelles Backup (täglich, wöchentlich, monatlich)(3.1kB)
Download