Rsync boiler plate script


/ Published in: Bash
Save to your folder(s)

Great script found on http://www.scrounge.org/linux/rsync.html. Useful for creating boilerplate backup scripts


Copy this code and paste it in your HTML
  1. #!/bin/sh
  2.  
  3. # Simple rsync "driver" script. (Uses SSH as the transport layer.)
  4. # http://www.scrounge.org/linux/rsync.html
  5.  
  6. # Demonstrates how to use rsync to back up a directory tree from a local
  7. # machine to a remote machine. Then re-run the script, as needed, to keep
  8. # the two machines "in sync." It only copies new or changed files and ignores
  9. # identical files.
  10.  
  11. # Destination host machine name
  12. DEST="smpent"
  13.  
  14. # User that rsync will connect as
  15. # Are you sure that you want to run as root, though?
  16. USER="root"
  17.  
  18. # Directory to copy from on the source machine.
  19. BACKDIR="/root/bin/"
  20.  
  21. # Directory to copy to on the destination machine.
  22. DESTDIR="/root/bin/"
  23.  
  24. # excludes file - Contains wildcard patterns of files to exclude.
  25. # i.e., *~, *.bak, etc. One "pattern" per line.
  26. # You must create this file.
  27. # EXCLUDES=/root/bin/excludes
  28.  
  29. # Options.
  30. # -n Don't do any copying, but display what rsync *would* copy. For testing.
  31. # -a Archive. Mainly propogate file permissions, ownership, timestamp, etc.
  32. # -u Update. Don't copy file if file on destination is newer.
  33. # -v Verbose -vv More verbose. -vvv Even more verbose.
  34. # See man rsync for other options.
  35.  
  36. # For testing. Only displays what rsync *would* do and does no actual copying.
  37. OPTS="-n -vv -u -a --rsh=ssh --exclude-from=$EXCLUDES --stats --progress"
  38. # Does copy, but still gives a verbose display of what it is doing
  39. #OPTS="-v -u -a --rsh=ssh --exclude-from=$EXCLUDES --stats"
  40. # Copies and does no display at all.
  41. #OPTS="--archive --update --rsh=ssh --exclude-from=$EXCLUDES --quiet"
  42.  
  43. # May be needed if run by cron?
  44. export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
  45.  
  46. # Only run rsync if $DEST responds.
  47. VAR=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
  48. if [ $VAR -eq 0 ]; then
  49. rsync $OPTS $BACKDIR $USER@$DEST:$DESTDIR
  50. else
  51. echo "Cannot connect to $DEST."
  52. fi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.