#! /bin/bash #Author: Rothe, Raimund; Schneidereit, Lars #Contact: raimundrothe@googlemail.com ## 0 9 * * * /path/to/script #Variablendeklaration DOM=`date '+%-d'` #DayOfMonth DOW=`date '+%w'` #DayOfWeek M=`date '+%-m'` #Month W=`date '+%-W'` #Week DOY=`date '+%-j'` #DayOfYear #Erstellen des täglichen Backups if [ ! -f /mnt/backup/daily$DOY.tar.gz ] then tar czf /mnt/backup/daily$DOY.tar.gz /home fi #Erstellen des monatlichen Backups if [ ! -f /mnt/backup/monthly$M.tar.gz ] then if [ $DOM = 1 ] then tar czf /mnt/backup/monthly$M.tar.gz /home fi fi #Erstellen des wöchentlichen Backups if [ ! -f /mnt/backup/weekly$W.tar.gz ] then if [ $DOW = 1 ] then tar czf /mnt/backup/weekly$W.tar.gz /home fi fi #Entfernen veralteter täglicher Backups (>10 Tage) for i in {1..355} do hilf=$(($DOY-11)) if [ $i -le $hilf ] then rm -f /mnt/backup/daily$i.tar.gz fi done #Entfernen des Jahresüberhangs täglicher Backups for i in {1..366} do hilf=$(($i-$DOY)) if [ $hilf -le 355 ] then if [ $i -gt $DOY ] then rm -f /mnt/backup/daily$i.tar.gz fi fi done #Entfernen veralteter wöchentlicher Backups (>3 Wochen) for i in {0..50} do hilf=$(($W-4)) if [ $i -le $hilf ] then rm -f /mnt/backup/weekly$i.tar.gz fi done #Entfernen des Jahresüberhangs veralteter wöchentlicher Backups for i in {0..53} do hilf=$(($i-$W)) if [ $hilf -le 49 ] then if [ $i -gt $W ] then rm -f /mnt/backup/weekly$i.tar.gz fi fi done #Entfernen veralteter monatlicher Backups (>2 Monate) for i in {1..9} do hilf=$(($M-3)) if [ $i -le $hilf ] then rm -f /mnt/backup/monthly$i.tar.gz fi done #Entfernen des Jahresüberhangs monatlicher Backups for i in {1..12} do hilf=$(($i-$M)) if [ $hilf -le 9 ] then if [ $i -gt $M ] then rm -f /mnt/backup/monthly$i.tar.gz fi fi done