diff options
-rwxr-xr-x | backup-run-rdiff-backup | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/backup-run-rdiff-backup b/backup-run-rdiff-backup new file mode 100755 index 0000000..c1e2fea --- /dev/null +++ b/backup-run-rdiff-backup @@ -0,0 +1,65 @@ +#!/bin/bash + +# Copyright 2013 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +set -e +set -u + +host="$(hostname)" +base="/Auto/net-backup/backups/" +keep=12W + +if [ "${1:-}" = "-v" ]; then + verbose="--terminal-verbosity=5" + verboseexpire="--terminal-verbosity=5" +else + verbose="" + verboseexpire="--terminal-verbosity=2" +fi + +if ! [ -d "$base" ] ; then + echo "$base does not exist" >&2 + exit 1 +fi + + + +for dir in $(df -Pkl -x tmpfs -x iso9660 -x devtmpfs | tail -n +2 | awk '{print $NF}' | sort -u); do + [ -e "$dir/.nobackup" ] && continue + + if [ "$dir" = '/' ]; then + cleaned="root" + else + cleaned="$(echo "$dir" | tr '/' '-')" + fi + tgt="$base/$host-$cleaned" + + if [ -e "$dir"/.rdiff-exclude ]; then + exclude="--exclude-globbing-filelist=$dir/.rdiff-exclude" + else + exclude="" + fi + + rdiff-backup $verbose $exclude --no-acls --exclude-sockets --exclude-other-filesystems "$dir" "$tgt" || echo "Warning: rdiff-backup $host:$dir -> $tgt failed." + rdiff-backup $verboseexpire --force --remove-older-than "$keep" "$tgt" || echo "Warning: rdiff-backup remove old backups for $tgt ($host:$dir) failed." +done |