Advertisement
Guest User

Untitled

a guest
Aug 14th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
  2. # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
  3. #
  4. # duplicity script for backupninja
  5. # requires duplicity >= 0.4.4, and >= 0.4.9 when using a custom tmpdir.
  6. #
  7.  
  8.  
  9. ######################################
  10. # backupdir: Where to backup to
  11. # incremantal: yes/np crate incremental backups
  12. # full_on: Iso 3 Char Day of Week on which a new full backip should be made.
  13. # max_age: Max Age in days of how long a backup is stored.
  14. # nicelevel: nice lebel
  15. # options: custom options to pass
  16. ##############################
  17.  
  18. getconf basebackupdir /var/backups/mysql/base
  19. getconf incrbackupdir /var/backups/mysql/incr
  20. getconf incremental yes
  21. getconf full_on mon
  22. getconf max_age 14
  23. getconf nicelevel 0
  24. getconf options
  25.  
  26. # authentication:
  27. getconf user
  28. getconf dbusername
  29. getconf dbpassword
  30. getconf configfile /etc/mysql/debian.cnf
  31.  
  32. ### COMMAND-LINE MANGLING ######################################################
  33.  
  34. ### initialize $execstr*
  35. execstr_precmd=
  36. execstr_command=
  37. options="$options --user=$user --password=$dbpassword"
  38.  
  39. day_of_week=$(date +%a)
  40.  
  41. # Check base dir exists and is writable
  42. if test ! -d $basebackupdir -o ! -w $basebackupdir
  43. then
  44. fatal "$basebackupdir does not exist or is not writable"
  45. fi
  46. # check incr dir exists and is writable
  47. if test ! -d $incrbackupdir -o ! -w $incrbackupdir
  48. then
  49. echo "$incrbackupdir does not exist or is not writable"
  50. fi
  51.  
  52. if [ -z "`mysqladmin $USEROPTIONS status | grep 'Uptime'`" ]
  53. then
  54. fatal "HALTED: MySQL does not appear to be running."
  55. fi
  56.  
  57. debug "Check completed OK"
  58.  
  59. ###Check for empty backupdir, if so force full backup
  60. if [ "$(ls -A $basebackupdir)" ]; then
  61. incremental=$incremental
  62. else
  63. incremental="no"
  64. fi
  65.  
  66. latest=`find $basebackupdir -mindepth 1 -maxdepth 1 -type d -printf "%P\n" | sort -nr | head -1`
  67.  
  68. ### Incremental or full backup mode
  69. # If incremental==yes, use the default duplicity behaviour: perform an
  70. # incremental backup if old signatures can be found, else switch to
  71. # full backup.
  72. # If incremental==no, force a full backup anyway.
  73. if [ "$incremental" == "no" ]; then
  74. execstr_command="$basebackupdir"
  75. else
  76. if [ "${day_of_week,,}" == "$full_on" ] ; then
  77. execstr_command="$basebackupdir"
  78. else
  79. latestincr=`find $incrbackupdir/$latest -mindepth 1 -maxdepth 1 -type d | sort -nr | head -1`
  80. if [ ! $latestincr ]
  81. then
  82. # This is the first incremental backup
  83. incrbasedir=$basebackupdir/$latest
  84. else
  85. # This is a 2+ incremental backup
  86. incrbasedir=$latestincr
  87. fi
  88.  
  89. execstr_command="--incremental $incrbackupdir/$latest --incremental-basedir=$incrbasedir"
  90. fi
  91. fi
  92.  
  93.  
  94.  
  95. ### Backup command
  96. debug "$execstr_precmd innobackupex $options $execstr_command"
  97. if [ ! $test ]; then
  98. outputfile=`maketemp backupout`
  99. output=`nice -n $nicelevel \
  100. su -c \
  101. "$execstr_precmd innobackupex $options $execstr_command >$outputfile 2>&1"`
  102. exit_code=$?
  103. debug $output
  104. cat $outputfile | (while read output ; do
  105. if [ $exit_code -eq 0 ]; then
  106. info $output
  107. else
  108. error $output
  109. fi
  110. done
  111. )
  112. if [ $exit_code -eq 0 ]; then
  113. info "innobackupex finished successfully."
  114. else
  115. fatal "innobackupex failed."
  116. fi
  117. rm $outputfile
  118.  
  119. # Delete old bakcups
  120. info "Cleanup"
  121. for DEL in `find $basebackupdir -mindepth 1 -maxdepth 1 -type d -mtime +$max_age -printf "%P\n"`
  122. do
  123. echo "deleting $DEL"
  124. rm -rf $basebackupdir/$DEL
  125. rm -rf $incrbackupdir/$DEL
  126. done
  127. fi
  128.  
  129.  
  130.  
  131.  
  132. return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement