![Jonny Mulandros](/data/avatars/m/17/17196.jpg?1445331730)
Jonny Mulandros
Doppel-As
Hallo liebes Unixboard,
ich bastel gerade an meiner Backup Lösung mit Rsync in Kombination mit einer Udev Regel.
Ich bin schon so weit, dass ich eine funktionierende Udev Regel erstellt habe, die beim einstecken meiner externen USB Platte folgendes Skript aufruft:
Dieses Skript habe ich unter /usr/local/bin/backup gespeichert und ausführbar gemacht. Es mountet die USB-Platte, führt das Backup Skript aus und bindet sie anschliessend normal ins System ein.
Hier ist das Backup Skript:
Udev-Regel /etc/udev/rules.d/07.usb.storage.custom.rules:
Hier zur Info meine fstab:
Das alles funktioniert auch soweit ganz gut, nur habe ich das Problem, das er beim ersten Skript das Backup auch ausführt, wenn das mounten nicht klappen sollte, und das Backup in das existierende Mount-Verzeichnis schreib, was dann sehr schnell meine Root-Partition volllaufen lässt.
Ich würde gerne umsetzen:
1. Er prüft im ersten Skript, ob die Platte wirklich eingehängt ist, und bricht ansonsten mit einer Fehlermeldung ab bzw. erstellt eine log-Datei mit dem Fehler
2. Das Backup Skript sendet über notify-osd eine Meldung, wenn das Backup startet und ob es erfolgreich war oder ein Fehler passiert ist.
Ich kenne mich leider mit Shell Skripting so gut wie gar nicht aus und hoffe dass ihr mir bei meinem Problem weiterhelfen könnt.
Vielen Dank schonmal im vorraus...
ich bastel gerade an meiner Backup Lösung mit Rsync in Kombination mit einer Udev Regel.
Ich bin schon so weit, dass ich eine funktionierende Udev Regel erstellt habe, die beim einstecken meiner externen USB Platte folgendes Skript aufruft:
Code:
#!/bin/bash
mount /dev/backup
sh /home/sebastian/Scripts/backup.sh
eject /dev/backup
Dieses Skript habe ich unter /usr/local/bin/backup gespeichert und ausführbar gemacht. Es mountet die USB-Platte, führt das Backup Skript aus und bindet sie anschliessend normal ins System ein.
Hier ist das Backup Skript:
Code:
#!/bin/bash
# Simple backup with rsync
# SOURCES and TARGET must end with slash
SOURCES="/home/sebastian/ /media/Data/"
TARGET="/media/Backup/"
LOGFILE="/home/sebastian/.backup.log"
EXPIREDAYS=14
RSYNC="--delete --include=.conkyrc --exclude=.* --exclude=*.*~ --exclude=Downloads --exclude=Desktop --exclude=RECYCLE.BIN --exclude=System Volume Information"
#SSHUSER="user"
#SSHHOST="hostname"
#SSHPORT=22
### do not edit ###
`/bin/date > $LOGFILE`
if [ -e $TARGET ]; then
LASTBACKUP=`/bin/ls -d $TARGET[[:digit:]]* 2>> $LOGFILE | /usr/bin/sort -r | /usr/bin/head -1 `
fi
TODAY=$(/bin/date +%d%m%y)
if [ $EXPIREDAYS -gt 0 ]; then
EXPIRED=`/usr/bin/find $TARGET[[:digit:]]* -maxdepth 0 -ctime +$EXPIREDAYS 2>> $LOGFILE`
for EX in `/bin/echo $EXPIRED`
do
/bin/echo "rm -rf $EX " >> $LOGFILE
`/bin/rm -rf $EX`
done
fi
for SOURCE in `/bin/echo $SOURCES`
do
if [ "$LASTBACKUP" ]; then
INC="--link-dest=$LASTBACKUP$SOURCE"
fi
if [ "$SSHUSER" ] && [ "$SSHHOST" ] && [ "$SSHPORT" ]; then
SSH="ssh -p $SSHPORT -l $SSHUSER";
SOURCEDIR="$SSHHOST:$SOURCE";
else
SOURCEDIR=$SOURCE;
fi
`/bin/mkdir -p $TARGET$TODAY$SOURCE` >> $LOGFILE
echo "/usr/bin/rsync -e \"$SSH\" -av $SOURCEDIR $RSYNC $INC $TARGET$TODAY$SOURCE " >> $LOGFILE 2>> $LOGFILE;
/usr/bin/rsync -e "$SSH" -av $SOURCEDIR $RSYNC $INC $TARGET$TODAY$SOURCE >> $LOGFILE 2>> $LOGFILE;
done
Udev-Regel /etc/udev/rules.d/07.usb.storage.custom.rules:
Code:
# USB-Festplatte für inkrementelle Backups
BUS=="usb", KERNEL=="sd?1",SYSFS{serial}=="DEF10000DF72172",SYSFS{idProduct}=="6830",SYMLINK+="backup",RUN+="/usr/local/bin/backup"
Hier zur Info meine fstab:
Code:
# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# / was on /dev/sda2 during installation
UUID=cedb8e71-0790-4a02-a303-f63045e13092 / ext3 relatime,errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=f2d687b9-f9f9-45d9-a0de-d1e576cd5108 none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
## Selbst eingetragen ##
# Windows HD
/dev/sda1 /media/Windows ntfs-3g defaults,noatime 0 0
# Data HD
/dev/sda3 /media/Data ntfs-3g defaults,noatime 0 0
# Backup HD
UUID=52c1a2b5-af83-49a3-bdf7-769d2c8e492c /media/Backup ext3 noauto,user,defaults 0 0
Das alles funktioniert auch soweit ganz gut, nur habe ich das Problem, das er beim ersten Skript das Backup auch ausführt, wenn das mounten nicht klappen sollte, und das Backup in das existierende Mount-Verzeichnis schreib, was dann sehr schnell meine Root-Partition volllaufen lässt.
Ich würde gerne umsetzen:
1. Er prüft im ersten Skript, ob die Platte wirklich eingehängt ist, und bricht ansonsten mit einer Fehlermeldung ab bzw. erstellt eine log-Datei mit dem Fehler
2. Das Backup Skript sendet über notify-osd eine Meldung, wenn das Backup startet und ob es erfolgreich war oder ein Fehler passiert ist.
Ich kenne mich leider mit Shell Skripting so gut wie gar nicht aus und hoffe dass ihr mir bei meinem Problem weiterhelfen könnt.
Vielen Dank schonmal im vorraus...