1
0

backup_server_to_disk.sh 940 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. DISK=/Volumes/Server
  3. SERVER=cnew
  4. # Basic snapshot-style rsync backup script
  5. date=`date "+%Y-%m"`
  6. # Run rsync to create snapshot
  7. # exclude backups on the remote to prevent filling with hardlinks
  8. rsync -aPhRz \
  9. --exclude "*-backup*/*" --exclude="*cache*" --rsync-path "sudo rsync" \
  10. --link-dest=$DISK/last $SERVER:/etc :/home :/var :/root $DISK/$date
  11. # copy lastest backups by following symlinks
  12. # need to explicitly include each level of directories before adding a global
  13. # */last pattern
  14. rsync -aPhRzLK \
  15. --include "var/" --include "*-backups/" --include "home/raspi-backup/" \
  16. --include "*-backup*/last" --include "*-backup*/last/**" --exclude="*" --rsync-path "sudo rsync" \
  17. --link-dest=$DISK/last $SERVER:/home/raspi-backup :/var $DISK/$date
  18. # Remove symlink to previous snapshot
  19. rm -f $DISK/last
  20. # Create new symlink to latest snapshot for the next backup to hardlink
  21. ln -s $DISK/$date $DISK/last