Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

tarsnap.sh 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. # Tarsnap backup script
  3. # Written by Tim Bishop, 2009.
  4. # Directories to backup (relative to /)
  5. DIRS="home root decrypted var/www var/lib/postgresql/9.1/main"
  6. # Number of daily backups to keep
  7. DAILY=7
  8. # Number of weekly backups to keep
  9. WEEKLY=3
  10. # Which day to do weekly backups on
  11. # 1-7, Monday = 1
  12. WEEKLY_DAY=5
  13. # Number of monthly backups to keep
  14. MONTHLY=1
  15. # Which day to do monthly backups on
  16. # 01-31 (leading 0 is important)
  17. MONTHLY_DAY=01
  18. # Path to tarsnap
  19. TARSNAP="/usr/local/bin/tarsnap"
  20. # Extra flags to pass to tarsnap
  21. EXTRA_FLAGS="-C /"
  22. # end of config
  23. set -e
  24. # day of week: 1-7, monday = 1
  25. DOW=`date +%u`
  26. # day of month: 01-31
  27. DOM=`date +%d`
  28. # month of year: 01-12
  29. MOY=`date +%m`
  30. # year
  31. YEAR=`date +%Y`
  32. # time
  33. TIME=`date +%H%M%S`
  34. # Backup name
  35. if [ X"$DOM" = X"$MONTHLY_DAY" ]; then
  36. # monthly backup
  37. BACKUP="$YEAR$MOY$DOM-$TIME-monthly"
  38. elif [ X"$DOW" = X"$WEEKLY_DAY" ]; then
  39. # weekly backup
  40. BACKUP="$YEAR$MOY$DOM-$TIME-weekly"
  41. else
  42. # daily backup
  43. BACKUP="$YEAR$MOY$DOM-$TIME-daily"
  44. fi
  45. # Do backups
  46. for dir in $DIRS; do
  47. echo "==> create $BACKUP-$dir"
  48. $TARSNAP $EXTRA_FLAGS -c -f $BACKUP-$dir $dir
  49. done
  50. # Backups done, time for cleaning up old archives
  51. # using tail to find archives to delete, but its
  52. # +n syntax is out by one from what we want to do
  53. # (also +0 == +1, so we're safe :-)
  54. DAILY=`expr $DAILY + 1`
  55. WEEKLY=`expr $WEEKLY + 1`
  56. MONTHLY=`expr $MONTHLY + 1`
  57. # Do deletes
  58. TMPFILE=/tmp/tarsnap.archives.$$
  59. $TARSNAP --list-archives > $TMPFILE
  60. for dir in $DIRS; do
  61. for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-daily-$dir" $TMPFILE | sort -rn | tail -n +$DAILY`; do
  62. echo "==> delete $i"
  63. $TARSNAP -d -f $i
  64. done
  65. for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-weekly-$dir" $TMPFILE | sort -rn | tail -n +$WEEKLY`; do
  66. echo "==> delete $i"
  67. $TARSNAP -d -f $i
  68. done
  69. for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-monthly-$dir" $TMPFILE | sort -rn | tail -n +$MONTHLY`; do
  70. echo "==> delete $i"
  71. $TARSNAP -d -f $i
  72. done
  73. done
  74. rm $TMPFILE