Benutzer:Lyl: Unterschied zwischen den Versionen
Lyl (Diskussion | Beiträge) Backup-Script |
Lyl (Diskussion | Beiträge) K →backup |
||
Zeile 11: | Zeile 11: | ||
KEYFILE=backup/backup.key | KEYFILE=backup/backup.key | ||
BACKUPCLOSE=/root/script/backup-close | BACKUPCLOSE=/root/script/backup-close | ||
pacman -Sy rsnapshot | pacman -Sy rsnapshot | ||
mkdir /extbackup/ | mkdir /extbackup/ |
Version vom 16. Februar 2009, 20:54 Uhr
Jabber: lyl@jabber.ccc.de
scripting
backup
Inbetriebnahme des scripts:
# Beispiel mit: STATUSFILE=/root/script/backup.day KEYFILE=backup/backup.key BACKUPCLOSE=/root/script/backup-close
pacman -Sy rsnapshot mkdir /extbackup/ mkdir /mnt/keyfs/ mount /mnt/usbstick-auf-dem-das-passwort-gespeichert-wir /mnt/keyfs/ echo "passwort-für-externe-hdd" /mnt/keyfs/$KEYFILE echo 0 > $STATUSFILE # Konfigurieren von rsnapshot: http://www.rsnapshot.org/howto/ # anlegen des Backup-Scripts Inhalt # anpassen der Konfiguration am Anfang des Backup-Scripts # anlegen von $BACKUPCLOSE
Inhalt des Backup-Scripts (./backup):
#!/bin/sh ######################################################################## ## ## ## Script to automate mounting crypted, external hdd, start backup ## ## using rsnapshot. ## ## ## ## by lyl 25.10.2008 - 10.02.2009 GPL v3 ## ## ## ######################################################################## # # rsnapshot is configured in /etc/rsnapshot.conf # parameters given to this script will be forwarded to rsnapshot # see `man rsnapshot` for mor information # # use cron or anacron to start backup automaticaly # # depends=('rsnapshot') # optdepends=('anacron') # # filesystems BACKUPFS=/dev/disk/by-id/usb-WDC_WD2500AB-1234567890-0\:0-part1 KEYFS=/dev/disk/by-id/usb-USB_DISK_USB_DISK_123456790-0\:0-part1 # files STATUSFILE=/root/script/backup.day KEYFILE=backup/backup.key BACKUPCLOSE=/root/script/backup-close # Number of hourly backups until more deep backups are made DAYS=2 WEEKS=6 MONTHS=18 YEARS=90 # END OF CONFIG # # Mounting filesystems # echo "mounting filesystem containing the key-file..." mount $KEYFS /mnt/keyfs/ echo "opening and mounting backup filesystem..." cryptsetup luksOpen $BACKUPFS extbackup < /mnt/keyfs/$KEYFILE mount /dev/mapper/extbackup /extbackup/ if (mount | grep -c "/dev/mapper/extbackup on /extbackup" > /dev/null) then echo "done" else echo "fail" /root/script/backup-close exit 1 fi # # Start backing up # BACKUPNR=`cat $STATUSFILE` echo "starting hourly backups (Nr. $BACKUPNR)..." rsnapshot hourly $1 # calculation deepth if (test $[$BACKUPNR % $DAYS] -eq 0); then BACKUPDAY=1 else BACKUPDAY=0 fi if (test $[$BACKUPNR % $WEEKS] -eq 0); then BACKUPDAY=2 fi if (test $[$BACKUPNR % $MONTHS] -eq 0); then BACKUPDAY=3 fi if (test $[$BACKUPNR % $YEARS] -eq 0); then BACKUPDAY=4 fi if (test $BACKUPDAY -ge 1) then echo "done" echo "creating daily backup..." rsnapshot daily $1 if (test $BACKUPDAY -ge 2) then echo "done" echo "creating weekly backup..." rsnapshot weekly $1 if (test $BACKUPDAY -ge 3) then echo "done" echo "creating monthly backups..." rsnapshot monthly $1 if (test $BACKUPDAY -ge 4) then echo "done" echo "creating yearly backups..." rsnapshot yearly $1 fi fi fi fi echo `expr $BACKUPNR + 1` > $STATUSFILE echo "done" $BACKUPCLOSE exit $?
Die nummer das aktuellen backups wird aus der Datei /root/script/backup.day ($STATUSFILE) gelesen:
1
Inhalt von backup/backup.key ($KEYFILE):
passwort-für-externe-hdd
Inhalt von /root/script/backup-close ($BACKUPCLOSE):
#!/bin/sh ERRORCODE=0 echo "umounting key filesystem..." umount /mnt/keyfs echo "umounting backup filesystem..." umount /dev/mapper/extbackup echo "closing crypto device..." cryptsetup luksClose extbackup if (ls /dev/mapper | grep -c "extbackup" > /dev/null) then echo "fail" echo "if you have opened the backup-file-system, please close it and try again!" ERRORCODE=1 else if (ls /mnt/keyfs/ |grep -c "" > /dev/null) then echo "fail" echo "if you have opened the key-file-system, please close it and try again!" ERRORCODE=2 fi echo "done" fi exit $ERRORCODE