Advertisement
Guest User

my rdiff-backup script. I'm no bash expert :-/

a guest
Nov 30th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.32 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # for debuging stop script on error
  4. # set -e
  5.  
  6. GLOBIGNORE=*:?
  7.  
  8. # as I call this from cron, I like to know how long backups took
  9. # NICECMD="time -p ionice -c 3 nice -n 19"
  10. NICECMD=nice
  11.  
  12. # Backup destination
  13. # over ssh on remote host
  14. # DSTBASE=root@remote.host::/home/backups/myserver
  15.  
  16. # not good practice to backup to local
  17. # but this can be a NFS mount
  18. DSTBASE=/home/backups/
  19.  
  20. RDIFF="rdiff-backup"
  21.  
  22. # RDIFFARGS="-v5 --print-statistics --exclude **/*nobackup*"
  23. # RDIFFARGS="-v5 --print-statistics --exclude **/*nobackup* --exclude-special-files"
  24. RDIFFARGS="--exclude **/*nobackup* --exclude-sockets --exclude-device-files --exclude-fifos"
  25. RDIFFRMOLD="--remove-older-than 1W --force"
  26.  
  27. LOCKFILE=/var/run/backup-rdiff.pid
  28.  
  29. # remove lock file if older then 2 days
  30. # todo: would probably be smarter to check if pid is still runing
  31. if test -e $LOCKFILE
  32. then
  33.     if test `find $LOCKFILE -mtime 2 -type f`;
  34.     then
  35.         echo "$LOCKFILE older then 2 days!  Deleting it."
  36.         rm -f $LOCKFILE
  37.     fi
  38. fi
  39.  
  40. if test -e $LOCKFILE;
  41. then
  42.     echo "Backup is already running!"
  43.     echo "If it isn't, remove $LOCKFILE and try again."
  44.     exit 1
  45. else
  46.     echo $$ > $LOCKFILE
  47. fi
  48.  
  49.  
  50. BACKUPDIR=/var/www
  51. # this is adapted to my local site (no need to backup cache and sessions)
  52. BACKUPARGS="--exclude /var/www/vhosts/*/log/* --exclude **/smarty/cache/* --exclude **/smarty/compile/* --exclude **/wp-content/cache/* --exclude **/cache/cachefs/* --exclude **/cache*/*cache* --exclude /var/www/php5-fpm --exclude **/sites/default --exclude **/sessions/sess_* "
  53.  
  54. echo /*
  55. echo ** Backing up $BACKUPDIR
  56. echo */
  57. $NICECMD $RDIFF $RDIFFARGS $BACKUPARGS $BACKUPDIR $DSTBASE$BACKUPDIR
  58. $NICECMD $RDIFF $RDIFFRMOLD $DSTBASE$BACKUPDIR
  59.  
  60.  
  61. # du to drupal saving it's settings in a readonly dir, this gave issues packing up over ovh NFS
  62. # as I don't have root access on my NFS backup space
  63. # so I will make a local backup
  64. #$NICECMD $RDIFF $RDIFFARGS --include "**/sites/default" --exclude "*" $BACKUPDIR /home/backups/serv01$BACKUPDIR
  65. #$NICECMD $RDIFF $RDIFFRMOLD /home/backups.local/serv01$BACKUPDIR
  66.  
  67.  
  68. BACKUPDIR=/root
  69. BACKUPARGS=""
  70.  
  71. echo /*
  72. echo ** Backing up $BACKUPDIR
  73. echo */
  74. $NICECMD $RDIFF $RDIFFARGS $BACKUPARGS $BACKUPDIR $DSTBASE$BACKUPDIR
  75. $NICECMD $RDIFF $RDIFFRMOLD $DSTBASE$BACKUPDIR
  76.  
  77. BACKUPDIR=/home
  78. BACKUPARGS="--include /home/backups/database --exclude /home/backups --exclude /home/antony/downloads --exclude /home/antony/tmp --exclude /home/archives"
  79.  
  80. echo /*
  81. echo ** Backing up $BACKUPDIR
  82. echo */
  83. $NICECMD $RDIFF $RDIFFARGS $BACKUPARGS $BACKUPDIR $DSTBASE$BACKUPDIR
  84. $NICECMD $RDIFF $RDIFFRMOLD $DSTBASE$BACKUPDIR
  85.  
  86. BACKUPDIR=/etc
  87. BACKUPARGS=""
  88.  
  89. echo /*
  90. echo ** Backing up $BACKUPDIR
  91. echo */
  92. $NICECMD $RDIFF $RDIFFARGS $BACKUPARGS $BACKUPDIR $DSTBASE$BACKUPDIR
  93. $NICECMD $RDIFF $RDIFFRMOLD $DSTBASE$BACKUPDIR
  94.  
  95. BACKUPDIR=/usr/local
  96. BACKUPARGS=""
  97.  
  98. echo /*
  99. echo ** Backing up $BACKUPDIR
  100. echo */
  101. $NICECMD $RDIFF $RDIFFARGS $BACKUPARGS $BACKUPDIR $DSTBASE$BACKUPDIR
  102. $NICECMD $RDIFF $RDIFFRMOLD $DSTBASE$BACKUPDIR
  103.  
  104. BACKUPDIR=/opt
  105. BACKUPARGS=""
  106.  
  107. echo /*
  108. echo ** Backing up $BACKUPDIR
  109. echo */
  110. $NICECMD $RDIFF $RDIFFARGS $BACKUPARGS $BACKUPDIR $DSTBASE$BACKUPDIR
  111. $NICECMD $RDIFF $RDIFFRMOLD $DSTBASE$BACKUPDIR
  112.  
  113.  
  114. # Remove lock file and end script
  115. #
  116. if test -e $LOCKFILE; then
  117.     rm $LOCKFILE;
  118. else
  119.     echo "Could not remove lock file!";
  120. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement