summaryrefslogtreecommitdiff
path: root/rdiff-backup/rdiff-backup.inc.sh
blob: 96877e879f71277d1c8f23078d82ed88a2550f42 (plain)
  1. #!/bin/bash
  2. # Usage: Include this file, and add lines below lines like these:
  3. #rdiffit xayide.jones.dk /etc /home/jonas/websites
  4. #rdiffit coreander.bitbase.dk /etc /home
  5. #rdiffit ida.idraetsdaghojskolen.dk "(10000,10000)" /home
  6. function rdiffit() {
  7. host="$1"; shift
  8. # grab optional upload and download limits
  9. up=""; down=""
  10. if echo "$1" | grep -Eq '^\(.*\)$'; then
  11. updown=`echo "$1" | sed -e 's/^(\(.*\))$/\1/'`
  12. up=`echo "$updown" | awk -F, '{ print $1 }'`
  13. down=`echo "$updown" | awk -F, '{ print $2 }'`
  14. shift
  15. fi
  16. for dir in $@; do
  17. if echo "$dir" | grep -Eq '^/'; then
  18. dir=`echo "$dir" | sed -e 's/^\///'`
  19. else
  20. echo "ERROR: host \"$host\" path \"$dir\" lacks leading \"/\""
  21. continue
  22. fi
  23. excludes=""
  24. while read exclude; do
  25. excludes="$excludes --exclude $exclude"
  26. done < /etc/local-COMMON/rdiff-backup/excludes
  27. if [ "$host" = "`hostname -f`" ]; then
  28. rdiff-backup --terminal-verbosity 1 $excludes /"$dir" "/var/local/backups/$host/rdiff-backup/${dir//\//-}"
  29. elif [ -z "$up$down" ]; then
  30. rdiff-backup --terminal-verbosity 1 $excludes --remote-schema 'ssh -o BatchMode=yes %s '\''rdiff-backup --server'\' $host::/"$dir" "/var/local/backups/$host/rdiff-backup/${dir//\//-}"
  31. else
  32. rdiff-backup --terminal-verbosity 1 $excludes --remote-schema 'cstream -t '$up' | ssh -o BatchMode=yes %s '\''rdiff-backup --server'\'' | cstream -t '$down $host::/"$dir" "/var/local/backups/$host/rdiff-backup/${dir//\//-}"
  33. fi
  34. done
  35. }