Hallo,
ich habe diverse Backupskripte, die alle auf rsync basieren. Hier mal beispielhaft ein solches backup.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/bin/bash source="/backup" backup="/media/backup" sync() { date="$1" srcpath="$source/$date/" destpath="$backup/latest" rsync -az -H --progress --human-readable --delete --sparse --checksum --hard-links --numeric-ids \ --exclude-from=/etc/backup_ext_init.exclude "$srcpath" "$destpath" btrfs subvolume snapshot "$destpath" "$backup/$date" } ls -1 "$source" | sort | tail -n1 |\ if read dir; then sync "$dir" fi |
Aufgerufen wird das Skript mit:
1 2 | sudo -s nohup /opt/sh/backup/backup.sh & |
Soweit, so gut... bis hierhin funktioniert es so, wie es soll. Beende ich aber die aufrufende Shell (z.B. SSH-Logoff), erschein folgendes in nohup.out:
sending incremental file list [...] rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.0] Create a snapshot of '/media/backup/latest' in '/media/backup/20140930'
D.h., rsync wird gekillt, das Shellskript läuft aber weiter (es erzeugt noch den btrfs-Snapshot). Wie kann das sein? rsync dürfte meiner Meinung nach nur beendet werden, wenn das Shellskript gekillt wird, aber nicht wenn die das Skript per nohup aufrufende Shell beendet wird. Gibt's da eine elegante Lösung, wie man das Beenden von rsync in diesem Fall verhindern kann?