Advertisement
zentavr

MySQL incremental backup/restore script

Oct 20th, 2013
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 19.34 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Author: Andrey Miroshnichenko <zentavr.trafford.com.ua>
  4. # Created for: Silicom Internet SL                   2012, 2013
  5. #              ICSW Group: http://www.icsw.com/en/
  6. # Created for: Trafford Group                        2012, 2013
  7. # Created for: Localcircles India                    2013
  8. #
  9. # Introducion:
  10. # The script does incremental backup using Percona's xtrabackup utilities.
  11. # You can download them from this site:
  12. # http://www.percona.com/downloads/XtraBackup/LATEST/
  13. # Yum repository: http://www.percona.com/doc/percona-server/5.5/installation/yum_repo.html
  14. # APT repository: http://www.percona.com/doc/percona-server/5.5/installation/apt_repo.html
  15. #
  16. # FreeBSD users can find the percona xtrabackup in the ports (seems like rather old version):
  17. # [root@cassiopeia ~]# cd /usr/ports/
  18. # [root@cassiopeia /usr/ports]# make search key=xtrabackup
  19. # Port:   xtrabackup-1.1
  20. # Path:   /usr/ports/databases/xtrabackup
  21. # Info:   OpenSource version of InnoDB backup with support of Percona extensions
  22. # B-deps: gettext-0.18_1 gmake-3.81_4 libiconv-1.13.1_1
  23. # R-deps:
  24. # WWW:    http://www.percona.com/docs/wiki/percona-xtrabackup:start
  25.  
  26. trap bashtrap INT
  27. function bashtrap() {
  28.     echo "CTRL+C Detected !..."
  29.     exit 1
  30. }
  31.  
  32. function usage() {
  33.     cat << EOF
  34. usage: $0 options
  35.  
  36. The script does incremental MySQL backup.
  37.  
  38. OPTIONS:
  39.     -h, --help  
  40.         Show this message
  41.    
  42.     -j, --job <job>
  43.         What job to do: "backup" or "restore"?
  44.         Default is "backup".
  45.        
  46.     -t, --type <type>
  47.         Backup type: "full" or "incremental".
  48.         Default is "full".
  49.        
  50.     -d, --database <database>
  51.         Database name
  52.    
  53.     -l, --lsndir <directory>
  54.         LSN (Log Seek Number) Directory Name.
  55.         Default is "/tmp"
  56.    
  57.     -T, --threads <threads>
  58.         How many threads to use?
  59.         Default is: "amount of CPUs + 1"
  60.    
  61.     --throttle <IOPS>
  62.         How many IOPS to produce
  63.    
  64.     --ionice-class <ionice_class>
  65.         ionice (1) class to set up during the operation (pass -c ionice_class to ionice):
  66.         0: none, 1: realtime, 2: best-effort, 3: idle
  67.    
  68.     --ionice-classdata <ionice_class>
  69.         ionice (1) classdata to set up during the operation (pass -n ionice_class to ionice):
  70.         class data (0-7, lower being higher prio)
  71.    
  72.     -L, --log <logfile>
  73.         Path to the logfile.
  74.         Default is "/tmp/logfile.log".
  75.    
  76.     -D, --path <path>
  77.         Where to store/pick the backup results.
  78.         Default is "Current Directory"
  79.    
  80.     -r, --dest <path>
  81.         Where to place the retored MySQL data
  82.         Default is "Current Directory"
  83.  
  84.     -x, --xtrabin <xtrabackup_binary>
  85.         Sets up the Xtrabackup binary
  86.    
  87.     -s, --stream <streamtype>
  88.         Sets what the stream to use: "tar" or "xbstream"
  89.         Default is "xbstream"
  90.  
  91.     -n, --do-not-delete
  92.         Do not delete the packed files during restore
  93.    
  94.     -e, --export
  95.         Do an export of InnoDB tablespaces to separate .exp files.
  96.         Only for Percona Server.
  97.         Review this: http://www.percona.com/doc/percona-xtrabackup/innobackupex/importing_exporting_tables_ibk.html
  98.         Set up this into your my.cnf:
  99.             innodb_file_per_table=1               # For any version of Percona Server
  100.             innodb_expand_import=1                # For Percona Sevrer to version 5.5.10-20.1
  101.             innodb_import_table_from_xtrabackup=1 # For Percona Sevrer from version 5.5.10-20.1 and after
  102.         Importing tables:
  103.         To import a table to other server, first create a new table with the same structure as the one that will be imported at that server:
  104.         OTHERSERVER|mysql> CREATE TABLE mytable (...) ENGINE=InnoDB;
  105.         then discard its tablespace:
  106.         OTHERSERVER|mysql> ALTER TABLE mydatabase.mytable DISCARD TABLESPACE;
  107.         After this, copy mytable.ibd and mytable.exp files to database’s home, and import its tablespace:
  108.         OTHERSERVER|mysql> ALTER TABLE mydatabase.mytable IMPORT TABLESPACE;
  109.         Once this is executed, data in the imported table will be available.
  110.        
  111.  
  112. EOF
  113. }
  114.  
  115. function checkpipe() {
  116.     STATUS=$1
  117.     SOFT1=$2
  118.     SOFT2=$3
  119.     if [ "$STATUS" != "0 0" ]; then
  120.         echo "The pipe of $SOFT1 and $SOFT2 was finished unseccussfully: $STATUS"
  121.         exit 1
  122.     else
  123.         echo "The pipe operation was completed successfully"
  124.     fi 
  125. }
  126.  
  127. function checkexit() {
  128.     STATUS=$1
  129.     SOFT=$2
  130.     if [ "$STATUS" != "0" ]; then
  131.         echo "The $SOFT was finished unseccussfully: $STATUS"
  132.         exit 1
  133.     else
  134.         echo "The $SOFT operation was completed successfully"
  135.     fi
  136. }
  137.  
  138. # Extracting the options
  139. # TODO: (Low) If this fails, parse only the short options with bash built-in getopt
  140. #       http://linuxwell.com/2011/07/14/getopt-in-bash/
  141. ARGS=$(getopt -o "hj:t:d:l:T:L:D:r:x:nes:" -l "help,job:,type:,database:,lsndir:,threads:,log:,path:,dest:,xtrabin:,do-not-delete,export,stream:,throttle:,ionice-class:,ionice-classdata:" -n "MyXtraBackup" -- "$@")
  142. if [ $? -ne 0 ]; then
  143.     echo "Bad argument to getopt was given"
  144.     exit 1
  145. fi
  146.  
  147. eval set -- "$ARGS"
  148.  
  149. #
  150. # Set up the defaults :)
  151. #
  152. # Job type: backup or restore
  153. JOB="backup"
  154.  
  155. # Backup type: "full" or "incremental"
  156. TYPE="full"
  157.  
  158. # Path to where LSN position will be stored
  159. LSNDIR="/tmp"
  160.  
  161. # The amount of the threads to use
  162. THREADS=$(( $(grep -c processor /proc/cpuinfo) + 1 ))
  163.  
  164. # Where to store the logfile
  165. LOGFILE="/tmp/logfile.log"
  166.  
  167. # Where to put the dump
  168. BACKUPRES=$(pwd)
  169.  
  170. # Where to restore the data
  171. DEST=$(pwd)
  172.  
  173. # Type of the stream
  174. STREAMTYPE="xbstream"
  175.  
  176. # Location of the utilities
  177. INNOBACKUPEX=$(which innobackupex)
  178. LZOP=$(which lzop)
  179. XBSTREAM=$(which xbstream)
  180. TAR=$(which tar)
  181. MYSQLDUMP=$(which mysqldump)
  182. MYSQL=$(which mysql)
  183. IONICE=$(which ionice)
  184.  
  185. OPTS=""
  186. EXPORT=""
  187. LZOP_OPTS="-dcfU"
  188. IONICE_CMD=""
  189. IONICE_CLASS=""
  190. IONICE_CLASSDATA=""
  191.  
  192. # Extract the options
  193. while true; do
  194.     case "$1" in
  195.         -h|--help)
  196.             usage
  197.             exit;;
  198.        
  199.         -j|--job)
  200.             if [ -n "$2" ];then
  201.                 JOB="$2"
  202.             else
  203.                 echo "No job type was specified (-j | --job)."
  204.                 exit 1;
  205.             fi
  206.             shift 2;;
  207.        
  208.         -t|--type)
  209.             if [ -n "$2" ];then
  210.                 TYPE="$2"
  211.             else
  212.                 echo "No backup type was specified (-t | --type)."
  213.                 exit 1;
  214.             fi
  215.             shift 2;;
  216.            
  217.         -d|--database)
  218.             if [ -n "$2" ];then
  219.                 DATABASE="$2"
  220.             else
  221.                 echo "No database was specified (-d|--database)."
  222.                 exit 1;
  223.             fi
  224.             shift 2;;
  225.        
  226.         -l|--lsndir)
  227.             if [ -n "$2" ];then
  228.                 LSNDIR="$2"
  229.             else
  230.                 echo "No LSN Directory was specified (-l|--lsndir)."
  231.                 exit 1;
  232.             fi
  233.             shift 2;;
  234.        
  235.         -T|--threads)
  236.             if [ -n "$2" ];then
  237.                 THREADS="$2" # TODO: (Low) Check, if the parameter is an integer?
  238.             else
  239.                 echo "No amount of the threads was specified (-T | --threads)."
  240.                 exit 1;
  241.             fi
  242.             shift 2;;
  243.        
  244.         -L|--log)
  245.             if [ -n "$2" ];then
  246.                 LOGFILE="$2" # TODO: (Low) Check, if the basename of logfile exists??
  247.             else
  248.                 echo "No logfile was given (-L | --log)."
  249.                 exit 1;
  250.             fi
  251.             shift 2;;
  252.        
  253.         -D|--path)
  254.             if [ -n "$2" ];then
  255.                 BACKUPRES="$2"
  256.             else
  257.                 echo "No directory for backup results was specified (-D | --path)."
  258.                 exit 1;
  259.             fi
  260.             shift 2;;
  261.        
  262.         -r|--dest)
  263.             if [ -n "$2" ];then
  264.                 DEST="$2"
  265.             else
  266.                 echo "No directory where to place restored data was specified (-r | --dest)."
  267.                 exit 1;
  268.             fi
  269.             shift 2;;
  270.        
  271.         -x|--xtrabin)
  272.             if [ -n "$2" ];then
  273.                 OPTS="$OPTS --ibbackup=$2"
  274.             else
  275.                 echo "No xtrabackup name was specified (-x | --xtrabin)."
  276.                 exit 1;
  277.             fi
  278.             shift 2;;
  279.        
  280.         --throttle)
  281.             if [ -n "$2" ];then
  282.                 OPTS="$OPTS --throttle=$2"
  283.             else
  284.                 echo "No throttle value was specified (--throttle)."
  285.                 exit 1;
  286.             fi
  287.             shift 2;;
  288.        
  289.         --ionice-class)
  290.             if [ -n "$2" ];then
  291.                 IONICE_CLASS="-c$2"
  292.             else
  293.                 echo "No ionice class value was specified (--ionice-class)."
  294.                 exit 1;
  295.             fi
  296.             shift 2;;
  297.        
  298.         --ionice-classdata)
  299.             if [ -n "$2" ];then
  300.                 IONICE_CLASSDATA="-n$2"
  301.             else
  302.                 echo "No ionice class data value was specified (--ionice-classdata)."
  303.                 exit 1;
  304.             fi
  305.             shift 2;;
  306.        
  307.         -s|--stream)
  308.             if [ -n "$2" ];then
  309.                 STREAMTYPE="$2"
  310.             else
  311.                 echo "No streamtype name was specified (-s | --stream)."
  312.                 exit 1;
  313.             fi
  314.             shift 2;;
  315.        
  316.         -n|--do-not-delete)
  317.             LZOP_OPTS="-dcf"
  318.             shift
  319.         ;;
  320.  
  321.         -e|--export)
  322.             EXPORT="--export"
  323.             shift
  324.         ;;
  325.  
  326.         --)
  327.             shift
  328.             break;;        
  329.     esac
  330. done
  331.  
  332. # Remove trailing slashes from the end
  333. BACKUPRES=$(echo "$BACKUPRES" | sed 's/\/*$//')
  334. LSNDIR=$(echo "$LSNDIR" | sed 's/\/*$//')
  335. DEST=$(echo "$DEST" | sed 's/\/*$//')
  336.  
  337. case "${STREAMTYPE}" in
  338.     "tar")
  339.         # Filename Suffix
  340.         echo "Using tar as a streamer"
  341.         FILENAMESUFFIX=".tar.lzo"
  342.         STREAMER_BIN=$TAR
  343.     ;;
  344.     "xbstream")
  345.         # Filename Suffix
  346.         echo "Using xbstream as a streamer"
  347.         FILENAMESUFFIX=".xbs.lzo"
  348.         STREAMER_BIN=$XBSTREAM
  349.     ;;
  350.     *)
  351.         echo "Unknown type of backup was specified: ${STREAMTYPE}"
  352.         exit 1
  353.     ;;
  354.    
  355. esac
  356.  
  357. # Determine for whether we need to use ionice(1)
  358. if [[ -n "$IONICE_CLASS" ]] || [[ -n "$IONICE_CLASSDATA" ]]; then
  359.     if [[ -n "$IONICE" ]] && [[ -x "$IONICE" ]]; then
  360.         IONICE_CMD="$IONICE $IONICE_CLASS $IONICE_CLASSDATA -- "
  361.     else
  362.         echo "No ionice(1) executable was found or it has no executable flag"
  363.     fi
  364. fi
  365.  
  366. # The names will look like this:
  367. # DATABASE-20120810_221058-full-169:12587456.xbs.lzo
  368. # DATABASE-20120811_221055-incremental-169:12599569.xbs.lzo
  369.  
  370. # What needs to be done?
  371. case "$JOB" in
  372.     "backup")
  373.         echo "Doing a backup."
  374.         # Check, if the database was specified?
  375.         if [ -z "$DATABASE" ]; then
  376.             echo "Database was not specified"
  377.             exit 1
  378.         fi
  379.        
  380.         # Checking if the destination path exists
  381.         if [ ! -d $BACKUPRES ]; then
  382.             echo "Creating $BACKUPRES"
  383.             mkdir -p "$BACKUPRES"
  384.             if [ $? -ne 0 ]; then
  385.                 echo "Creation of $BACKUPRES was failed"
  386.                 exit 1
  387.             fi
  388.         fi
  389.        
  390.         if [ -z "$INNOBACKUPEX" ]; then
  391.             echo "No innobackupex was found in $PATH"
  392.             exit 1
  393.         fi
  394.        
  395.         if [ -z "$MYSQL" ]; then
  396.             echo "No mysql was found in $PATH"
  397.             exit 1
  398.         fi
  399.  
  400.         if [ -z "$MYSQLDUMP" ]; then
  401.             echo "No mysqldump was found in $PATH"
  402.             exit 1
  403.         fi
  404.  
  405.         if [ -z "$LZOP" ]; then
  406.             echo "No lzop archiver was found in $PATH"
  407.             exit 1
  408.         fi
  409.        
  410.         # Inventing a name for the file
  411.         FILENAME=$DATABASE"-"$(date "+%Y%m%d_%H%M%S")      
  412.        
  413.         TMPNAME=$(mktemp --tmpdir="$BACKUPRES")
  414.         # What type of the backup do we have?
  415.         case "$TYPE" in
  416.             "full")
  417.                 echo "Doing a full backup to $TMPNAME"
  418.                
  419.                 if [ "$STREAMTYPE" == "xbstream" ]; then
  420.                     echo "...xbstream"
  421.                     $IONICE_CMD $INNOBACKUPEX --include=$DATABASE".*" --parallel=$THREADS --extra-lsndir="$LSNDIR" --stream=$STREAMTYPE --no-timestamp $OPTS "$BACKUPRES" 2>>"$LOGFILE" | $LZOP -c > $TMPNAME
  422.                     # Status of the pipe
  423.                     checkpipe "${PIPESTATUS[*]}" "innobackupex ($INNOBACKUPEX)" "lzop:($LZOP)"
  424.                 else
  425.                     echo "...tar: Doing a backup"
  426.                     rm -rf --preserve-root "$BACKUPRES"/tmp
  427.                     $IONICE_CMD $INNOBACKUPEX --include=$DATABASE".*" --parallel=$THREADS --extra-lsndir="$LSNDIR" --no-timestamp $OPTS "$BACKUPRES"/tmp 2>>"$LOGFILE"
  428.                     echo "...tar: Packing"
  429.                     ( cd "$BACKUPRES"/tmp; $TAR -cf - . | $LZOP -c > $TMPNAME )
  430.                     # TODO: Check for pipe status here
  431.                     echo "Pipe status is: ${PIPESTATUS[*]}"
  432.                     echo "...tar: Removing an old data"
  433.                     rm -rf --preserve-root "$BACKUPRES"/tmp
  434.                 fi
  435.                 ;;
  436.             "incremental")
  437.                 echo "Doing an incremental backup to $TMPNAME"
  438.                 # Check if we have full backup (check LSN, the file could be moved away to another server)?
  439.                 TOLSN=$(grep "to_lsn" "$LSNDIR/xtrabackup_checkpoints" | awk -F'=' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')
  440.                 if [ -z "$TOLSN" ]; then
  441.                     echo "Cannot find LSN position of the previous backup in $LSNDIR"
  442.                     exit 1
  443.                 fi
  444.                
  445.                 if [ "$STREAMTYPE" == "xbstream" ]; then
  446.                     echo "...xbstream"
  447.                     $IONICE_CMD $INNOBACKUPEX --include=$DATABASE".*" --parallel=$THREADS --incremental --extra-lsndir="$LSNDIR" --incremental-lsn=$TOLSN --stream=$STREAMTYPE $OPTS "$BACKUPRES" 2>>"$LOGFILE" | $LZOP -c > $TMPNAME
  448.                     # Status of the pipe
  449.                     STATUS=${PIPESTATUS[*]}
  450.                     if [ "$STATUS" != "0 0" ]; then
  451.                         echo "The pipe of innobackupex ($INNOBACKUPEX) and lzop:($LZOP) was finished unseccussfully: $STATUS"
  452.                         exit 1
  453.                     else
  454.                         echo "The pipe operation was completed successfully"
  455.                     fi
  456.                 else
  457.                     echo "Removing ${BACKUPRES}/tmp"
  458.                     rm -rf --preserve-root "$BACKUPRES"/tmp
  459.                     echo "...tar: Doing a backup"
  460.                     echo $IONICE_CMD $INNOBACKUPEX --include=$DATABASE".*" --parallel=$THREADS --incremental --extra-lsndir="$LSNDIR" --no-timestamp --incremental-lsn=$TOLSN $OPTS "$BACKUPRES"/tmp
  461.                     $IONICE_CMD $INNOBACKUPEX --include=$DATABASE".*" --parallel=$THREADS --incremental --extra-lsndir="$LSNDIR" --no-timestamp --incremental-lsn=$TOLSN $OPTS "$BACKUPRES"/tmp 2>>"$LOGFILE"
  462.                     echo "...tar: Packing"
  463.                     ( cd "$BACKUPRES"/tmp; $TAR -cf - . | $LZOP -c > $TMPNAME )
  464.                     echo "...tar: Removing an old data"
  465.                     rm -rf --preserve-root "$BACKUPRES"/tmp
  466.                 fi
  467.                 ;;
  468.             *)
  469.                 echo "A wrong backup type was specified ($TYPE)"
  470.                 exit 1
  471.                 ;;
  472.         esac
  473.        
  474.         # Checking what we have in the logs
  475.         LOGISOK=$(tail -1 "$LOGFILE" | grep -c 'completed OK!')
  476.         if [ $LOGISOK -eq 1 ]; then
  477.             tail -1 "$LOGFILE"
  478.         else
  479.             echo '##### ALERT #####'
  480.             echo 'We don\'t have \'completed OK!\' status in the end of a logfile, so probably an error happened'
  481.             echo '##### ALERT #####'
  482.         fi
  483.        
  484.         echo "Renaming $TMPNAME"
  485.         # Fetch the latest LSN number
  486.         FROMLSN=$(grep "from_lsn" "$LSNDIR/xtrabackup_checkpoints" | awk -F'=' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')
  487.         TOLSN=$(grep "to_lsn" "$LSNDIR/xtrabackup_checkpoints" | awk -F'=' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')
  488.         mv -f $TMPNAME $BACKUPRES"/"$FILENAME"-"$TYPE"-"$FROMLSN"-"$TOLSN""$FILENAMESUFFIX     
  489.         echo "$TYPE backup is done. The result is in "$BACKUPRES"/"$FILENAME"-"$TYPE"-"$FROMLSN"-"$TOLSN""$FILENAMESUFFIX
  490.         # Storing table definitions
  491.         echo "Dumping table definitions"
  492.         mkdir -p $BACKUPRES/definitions
  493.         for TABLE in $(echo "show tables" | $MYSQL --defaults-extra-file=/root/.my.cnf -B -N "$DATABASE"); do
  494.             echo "Dumping table definition for ${DATABASE}.${TABLE}"
  495.             $IONICE_CMD $MYSQLDUMP --defaults-extra-file=/root/.my.cnf -q -Q --no-data "$DATABASE" "$TABLE" > $BACKUPRES/definitions/${TABLE}.sql 2>> "$LOGFILE"
  496.         done
  497.         echo "Doing a backup of $DATABASE routies"
  498.         $IONICE_CMD $MYSQLDUMP --defaults-extra-file=/root/.my.cnf -q -Q --routines --no-create-info --no-data --no-create-db --skip-opt "$DATABASE" > $BACKUPRES/definitions/__routines.sql 2>> "$LOGFILE"
  499.         echo "Archiving the definitions"
  500.         ( cd $BACKUPRES/definitions; $TAR -cf - . | $LZOP -c > $BACKUPRES/definitions-$FILENAME.tar.lzo )
  501.         rm -rf --preserve-root $BACKUPRES/definitions
  502.         echo "Done"
  503.         ;;
  504.    
  505.     "restore")
  506.         echo "Restoring $DATABASE" | tee "${LOGFILE}"
  507.        
  508.         if [ -z "$XBSTREAM" ]; then
  509.             echo "No xbstream (the part of percona's xtrabackup was found in $PATH" | tee -a "${LOGFILE}"
  510.             exit 1
  511.         fi
  512.        
  513.         # Review what files of full backups do we have (we take the latest one...)
  514.         FULLBACKUP=$(find "$BACKUPRES" -type f -name "$DATABASE-*-full-*$FILENAMESUFFIX" -exec basename {} \; | sort -r | head -1)
  515.         if [ -z "$FULLBACKUP" ]; then
  516.             echo "No full backup was found in $BACKUPRES for database $DATABASE" | tee -a "${LOGFILE}"
  517.             exit 1
  518.         else
  519.             echo "Considering $FULLBACKUP to be as a full backup for $DATABASE" | tee -a "${LOGFILE}"
  520.         fi
  521.        
  522.         # Searching for the incremental backups (We must !!!! apply the increments one by one to the base backup in the right order)
  523.         echo "Searching for the incremental backups" | tee -a "${LOGFILE}"
  524.         # We need to search files recursively. The age the files should be younger then the age of a full backup
  525.         PREV_FILE=$FULLBACKUP
  526.         while true; do
  527.             NEXT_LSN=$(basename $PREV_FILE $FILENAMESUFFIX | cut -f5 -d-) # 479:2100086046
  528.             NEXT_FILE="$DATABASE-*-incremental-$NEXT_LSN-*$FILENAMESUFFIX"
  529.             echo "   Searching for $NEXT_FILE" | tee -a "${LOGFILE}"
  530.             #INC=$(find "$BACKUPRES" -type f -name "$NEXT_FILE" -newer "$BACKUPRES/$PREV_FILE" -exec basename {} \; | sort -r | head -1)
  531.             INC=$(find "$BACKUPRES" -type f -name "$NEXT_FILE" -exec basename {} \; | sort -r | head -1)
  532.             if [ -z "$INC" ]; then
  533.                 echo "    No next incremental found" | tee -a "${LOGFILE}"
  534.                 break
  535.             fi
  536.             echo "     Found $INC" | tee -a "${LOGFILE}"
  537.             # Adding the file to the list
  538.             INCREMENTALS="$INCREMENTALS $INC"
  539.             PREV_FILE=$INC  
  540.         done
  541.        
  542.         FULLRESTORE=$DEST/full
  543.         # Restore a full backup
  544.         mkdir -p $FULLRESTORE
  545.         echo "Unpacking a full backup to $FULLRESTORE" | tee -a "${LOGFILE}"
  546.         $LZOP $LZOP_OPTS $BACKUPRES/$FULLBACKUP | $STREAMER_BIN -x --directory=$FULLRESTORE
  547.         # Status of the pipe
  548.         checkpipe "${PIPESTATUS[*]}" "lzop:($LZOP)" "$STREAMER_BIN" | tee -a "${LOGFILE}"
  549.                
  550.         # Replay the commited transactions on full (base) backup
  551.         echo "Replaying the commited transactions on full (base) backup" | tee -a "${LOGFILE}"
  552.         $IONICE_CMD $INNOBACKUPEX --apply-log --redo-only $FULLRESTORE --use-memory=1G $OPTS $EXPORT 2>>"$LOGFILE"
  553.         checkexit $? "$INNOBACKUPEX" | tee -a "${LOGFILE}"
  554.        
  555.         echo | tee -a "${LOGFILE}"
  556.         echo | tee -a "${LOGFILE}"
  557.         echo | tee -a "${LOGFILE}"
  558.         echo "====================================================================================================================" | tee -a "${LOGFILE}"
  559.         echo | tee -a "${LOGFILE}"
  560.         echo | tee -a "${LOGFILE}"
  561.         echo | tee -a "${LOGFILE}"
  562.        
  563.         # Processing the increments
  564.         for INC in $INCREMENTALS; do
  565.             echo "Processing $INC" | tee -a "${LOGFILE}"
  566.             INCRESTORE=$DEST/$(basename $INC $FILENAMESUFFIX)
  567.             mkdir -p $INCRESTORE
  568.             echo "Unpacking an incremental backup to $INCRESTORE" | tee -a "${LOGFILE}"
  569.             $LZOP $LZOP_OPTS $BACKUPRES/$INC | $STREAMER_BIN -x --directory=$INCRESTORE
  570.             # Status of the pipe
  571.             checkpipe "${PIPESTATUS[*]}" "lzop:($LZOP)" "$STREAMER_BIN" | tee -a "${LOGFILE}"
  572.                        
  573.             echo "Applying incremental backup log to a full backup" | tee -a "${LOGFILE}"
  574.             $IONICE_CMD $INNOBACKUPEX --apply-log --redo-only $FULLRESTORE --incremental-dir=$INCRESTORE --use-memory=1G $OPTS $EXPORT 2>>"$LOGFILE"
  575.             checkexit $? "$INNOBACKUPEX" | tee -a "${LOGFILE}"
  576.            
  577.             echo "Removing the folder whith incremental deltas" | tee -a "${LOGFILE}"
  578.             rm -rf $INCRESTORE
  579.             echo | tee -a "${LOGFILE}"
  580.             echo | tee -a "${LOGFILE}"
  581.             echo | tee -a "${LOGFILE}"
  582.             echo "====================================================================================================================" | tee -a "${LOGFILE}"
  583.             echo | tee -a "${LOGFILE}"
  584.             echo | tee -a "${LOGFILE}"
  585.             echo | tee -a "${LOGFILE}"
  586.         done
  587.        
  588.         # At last - prepare the baclup for usage
  589.         echo "Preparing again the full backup (base + incrementals) once again to rollback the pending transactions" | tee -a "${LOGFILE}"
  590.         $IONICE_CMD $INNOBACKUPEX --apply-log $FULLRESTORE --use-memory=1G $OPTS $EXPORT 2>>"$LOGFILE"
  591.         checkexit $? "$INNOBACKUPEX" | tee -a "${LOGFILE}"
  592.        
  593.         echo | tee -a "${LOGFILE}"
  594.         echo | tee -a "${LOGFILE}"
  595.         echo | tee -a "${LOGFILE}"
  596.         echo "====================================================================================================================" | tee -a "${LOGFILE}"
  597.         echo | tee -a "${LOGFILE}"
  598.         echo | tee -a "${LOGFILE}"
  599.         echo | tee -a "${LOGFILE}"
  600.        
  601.         echo "The restore is done. The result is in $FULLRESTORE folder" | tee -a "${LOGFILE}"
  602.         ;;
  603.     *)
  604.         echo "Wrong job-type was specified"
  605.         exit 1
  606.         ;;
  607. esac
  608.  
  609. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement