{"id":227533,"date":"2014-06-25T11:10:02","date_gmt":"2014-06-25T07:10:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=227533"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=227533","title":{"rendered":"<span class=\"post_title\">\u0411\u0435\u043a\u0430\u043f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u2013 \u0435\u0441\u0442\u044c \u043b\u0438 \u043e\u043d?<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/c05\/89e\/903\/c0589e9034c9e6658b5adbf2b08af8a3.jpg\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 mysql. <br \/>  \u0418 \u043e\u0434\u043d\u043e \u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u0432\u0430\u0436\u043d\u044b\u0445 \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0430 \u0441\u0434\u0435\u043b\u0430\u043b\u0441\u044f \u043b\u0438 \u0431\u0435\u043a\u0430\u043f? \u0410 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043b\u0438 \u043f\u0440\u043e\u0448\u0435\u043b \u0434\u0430\u043c\u043f? \u0410 \u0431\u044b\u043b\u0438 \u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0438? \u0410 \u0437\u043d\u0430\u044e \u043b\u0438 \u044f \u043e \u043d\u0438\u0445<\/p>\n<p>  \u041f\u043e-\u043c\u043e\u0435\u043c\u0443, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0440\u044f\u0434 \u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u0433\u043e, \u043a\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0431\u0435\u043a\u0430\u043f. \u041d\u043e \u0432\u043e\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0431\u0435\u043a\u0430\u043f\u0430, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c <a href=\"http:\/\/centos-admin.ru\">\u043c\u044b<\/a>.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0441\u0445\u0435\u043c\u044b, \u043d\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435, \u0447\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0443 \u0441\u0435\u0431\u044f.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u041e\u043f\u0438\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u0443\u0442\u0438<\/p>\n<pre><code class=\"bash\">PATH=\/usr\/local\/bin:\/usr\/bin:\/bin:\/usr\/local\/mysql\/bin  DATE=`date +%Y-%m-%d_%Hh%Mm`                            # Datestamp e.g 2002-09-21  DOW=`date +%A`                                                  # Day of the week e.g. Monday  DNOW=`date +%u`                                         # Day number of the week 1 to 7 where 1 represents Monday  DOM=`date +%d`                                                  # Date of the Month e.g. 27  M=`date +%B`                                                    # Month e.g January  W=`date +%V`                                                    # Week Number e.g 37  VER=2.5                                                                 # Version Number  LOGFILE=$BACKUPDIR\/$DBHOST-`date +%N`.log               # Logfile Name  LOGERR=$BACKUPDIR\/ERRORS_$DBHOST-`date +%N`.log         # Logfile Name  BACKUPFILES=&quot;&quot;  OPT=&quot;--quote-names --opt --routines --single-transaction --events&quot;      # OPT string for use with mysqldump ( see man mysqldump )  DBEXCLUDE+=&quot; information_schema performance_schema&quot;     LOCATION=&quot;$(cd -P -- &quot;$(dirname -- &quot;$0&quot;)&quot; && pwd -P)\/..&quot;  <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0441\u043a\u0440\u0438\u043f\u0442 \u043e\u0434\u0438\u043d, \u043d\u043e \u043a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445, \u043d\u043e \u0438 \u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u041c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<p>  mysql-backup.conf.dist \u2014 \u0444\u0430\u0439\u043b \u0445\u0440\u0430\u043d\u0438\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043e\u0431\u0449\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432<\/p>\n<p>  mysql-backup.conf \u2013 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/p>\n<p>  mysql-backup.local.conf \u2013 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0431\u0435\u043a\u0430\u043f\u0430<\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433 \u2014 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0435\u043a\u0430\u043f \u043d\u0430 \u044d\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0438:<\/p>\n<pre><code class=\"bash\">if [ -f &quot;$LOCATION\/etc\/mysql-backup.conf.dist&quot; ]; then      . &quot;$LOCATION\/etc\/mysql-backup.conf.dist&quot;      if [ -f &quot;$LOCATION\/etc\/mysql-backup.conf&quot; ]; then          . &quot;$LOCATION\/etc\/mysql-backup.conf&quot;      fi      if [ -f &quot;$LOCATION\/etc\/mysql-backup.local.conf&quot; ]; then          . &quot;$LOCATION\/etc\/mysql-backup.local.conf&quot;      fi  else      echo &quot;mysql-backup.conf.dist not found&quot;      exit 0  fi <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u0439\u0434\u0451\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u043e\u043f\u0446\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0430 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"bash\"># Add --compress mysqldump option to $OPT  if [ &quot;$COMMCOMP&quot; = &quot;yes&quot; ];          then                  OPT=&quot;$OPT --compress&quot;          fi     # Add --compress mysqldump option to $OPT  if [ &quot;$MAX_ALLOWED_PACKET&quot; ];          then                  OPT=&quot;$OPT --max_allowed_packet=$MAX_ALLOWED_PACKET&quot;          fi     if [ ! &quot;$BACKUP_DAYS&quot; ];          then                  BACKUP_DAYS=7          fi     if [ ! &quot;$BACKUP_MONTH&quot; ];          then                  BACKUP_MONTH=4          fi     if [ ! &quot;$DO_SQL_DUMP&quot; ];          then                  DO_SQL_DUMP=&quot;yes&quot;          fi     if [ ! &quot;$DO_HOT_BACKUP&quot; ];          then                  DO_HOT_BACKUP=&quot;no&quot;          fi <\/code><\/pre>\n<p>  \u0414\u0443\u043c\u0430\u044e \u0442\u0443\u0442 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u0442.\u043a. \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0430\u043c\u0438 \u0432\u0441\u0451 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0437\u0430 \u0441\u0435\u0431\u044f.<\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0431\u0435\u043a\u0430\u043f\u043e\u0432<\/p>\n<pre><code class=\"bash\"># Create required directories  if [ ! -e &quot;\/var\/lib\/mysql.backup&quot; ]             # Check Backup Directory exists.          then              mkdir -p &quot;\/var\/lib\/mysql.backup&quot;  fi     if [ ! -e &quot;$BACKUPDIR&quot; ]                # Check Backup Directory exists.          then          mkdir -p &quot;$BACKUPDIR&quot;  fi     if [ ! -e &quot;$BACKUPDIR\/daily&quot; ]          # Check Daily Directory exists.          then          mkdir -p &quot;$BACKUPDIR\/daily&quot;  fi     if [ ! -e &quot;$BACKUPDIR\/weekly&quot; ]         # Check Weekly Directory exists.          then          mkdir -p &quot;$BACKUPDIR\/weekly&quot;  fi     if [ ! -e &quot;$BACKUPDIR\/monthly&quot; ]        # Check Monthly Directory exists.          then          mkdir -p &quot;$BACKUPDIR\/monthly&quot;  fi     if [ &quot;$LATEST&quot; = &quot;yes&quot; ]  then          if [ ! -e &quot;$BACKUPDIR\/latest&quot; ] # Check Latest Directory exists.          then                  mkdir -p &quot;$BACKUPDIR\/latest&quot;          fi  eval rm -fv &quot;$BACKUPDIR\/latest\/*&quot;  fi <\/code><\/pre>\n<p>  \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0435\u043a\u0430\u043f, \u043d\u043e \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"bash\"># IO redirection for logging.  touch $LOGFILE  exec 6&gt;&1           # Link file descriptor #6 with stdout.                      # Saves stdout.  exec &gt; $LOGFILE     # stdout replaced with file $LOGFILE.  touch $LOGERR  exec 7&gt;&2           # Link file descriptor #7 with stderr.                      # Saves stderr.  exec 2&gt; $LOGERR     # stderr replaced with file $LOGERR.     echo $LOCATION <\/code><\/pre>\n<p>  \u041e\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0438 \u0444\u0443\u043a\u0446\u0438\u0438. \u0422.\u043a. \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043d\u0443\u0436\u0435\u043d \u0440\u0430\u0437\u043d\u044b\u0439 \u0431\u0435\u043a\u0430\u043f, \u043a\u043e\u043c\u0443 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u0442\u043d\u044b\u0439, \u0443 \u043a\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u043e\u0447\u044c\u044e \u0441\u043f\u044f\u0442 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0430\u043c\u043f\u0430 \u043d\u043e\u0447\u043d\u043e\u0433\u043e.<\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u044b\u0439 mysqldump<\/p>\n<pre><code class=\"bash\"># Database dump function  dbdump () {      if [ &quot;$SEPTABLE&quot; = &quot;yes&quot; ]; then          TABLENAMES=&quot;`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --batch --skip-column-names -e &quot;show tables&quot; $1| sed 's\/ \/%\/g'`&quot;          for TABLENAME in $TABLENAMES ; do             OUTFILENAME=`echo $2 | sed &quot;s~$3~$3.$TABLENAME~&quot;`             mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 $TABLENAME &gt; $OUTFILENAME          done          mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT --no-data $1 &gt; $2      else          mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 &gt; $2      fi      return 0  } <\/code><\/pre>\n<p>  \u0421 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c mydumper<\/p>\n<pre><code class=\"bash\"># Database dump function  dbdump_mydumper () {      MYOPT=&quot;&quot;          # Add --ignore-table options to $MYOPT             if [ -n &quot;$TABLEEXCLUDE&quot; ]; then              for table in $TABLEEXCLUDE ; do                  MYOPT=&quot;${MYOPT}${table}|&quot;              done          fi          if [ -n &quot;$DBEXCLUDE&quot; ]; then              for table in $DBEXCLUDE ; do                  MYOPT=&quot;${MYOPT}${table}|&quot;              done          fi          if [ -n &quot;$MYOPT&quot; ]; then              MYOPT=&quot;--regex '^(?!(${MYOPT}mysql.noptable))'&quot;          fi         eval mydumper --user $USERNAME --password $PASSWORD -c -l 300 --kill-long-queries -s 500000 $MYOPT -o $1         if [ $? -gt 0 ]; then            echo &quot;Error in mydumper backup stage&quot; &gt;&2            mysql -u root -p`cat \/root\/.mysql` -e &quot;SHOW FULL PROCESSLIST&quot; | sort -n -k 6 &gt;&2      fi         \/usr\/bin\/find &quot;$BACKUPDIR\/daily&quot; -name &quot;_mydumper*&quot; -type d -mtime +$BACKUP_DAYS -print0 | xargs -0 rm -rf      \/usr\/bin\/find &quot;$BACKUPDIR\/weekly&quot; -name &quot;_mydumper*&quot; -type d -mtime +35 -print0 | xargs -0 rm -rf      \/usr\/bin\/find &quot;$BACKUPDIR\/monthly&quot; -name &quot;_mydumper*&quot; -type d -mtime +100 -print0 | xargs -0 rm -rf      return 0  } <\/code><\/pre>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446<\/p>\n<pre><code class=\"bash\">dbdump_h () {      echo First rsync started at `date`      rsync -avH --delete --numeric-ids \/var\/lib\/mysql\/ \/var\/lib\/mysql.backup      echo First rsync finished at `date`      echo DB locked, second rsync started at `date`      echo &quot;FLUSH TABLES WITH READ LOCK&quot; | mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST      rsync -avH --delete --numeric-ids \/var\/lib\/mysql\/ \/var\/lib\/mysql.backup      echo &quot;UNLOCK TABLES&quot; | mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST      echo DB unlocked, second rsync finished at `date`  return 0  } <\/code><\/pre>\n<p>  \u0418 \u043a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u043d\u0435\u0433\u043e, \u0432\u0441\u0435\u043c \u043d\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0435\u043a\u0430\u043f<\/p>\n<pre><code class=\"bash\">dbdump_h_xtra () {      if [ ! -f \/usr\/bin\/innobackupex ]; then          yum -y install xtrabackup.x86_64      fi      if [ ! -f \/var\/lib\/mysql-xtra\/xtrabackup_checkpoints ]; then          echo Full backup stage started at `date`          #ionice -c3          \/usr\/bin\/innobackupex --defaults-file=\/etc\/my.cnf --password=`cat \/root\/.mysql` --no-timestamp  --throttle=40 --rsync \/var\/lib\/mysql-xtra 2&gt;&1          if [ $? -gt 0 ]; then            echo &quot;Error in full backup stage&quot; &gt;&2          fi          #ionice -c3          \/usr\/bin\/innobackupex --apply-log --redo-only --defaults-file=\/etc\/my.cnf --password=`cat \/root\/.mysql` --no-timestamp  --throttle=40 \/var\/lib\/mysql-xtra 2&gt;&1          if [ $? -gt 0 ]; then            echo &quot;Error in apply log redo stage&quot; &gt;&2          fi          echo Full backup stage finished at `date` code $?      else          echo INC backup stage started at `date` code $?          rm -rf \/var\/lib\/mysql-xtra-inc          #ionice -c3          \/usr\/bin\/innobackupex --defaults-file=\/etc\/my.cnf --password=`cat \/root\/.mysql` --no-timestamp  --throttle=40  --rsync --incremental \/var\/lib\/mysql-xtra-inc --incremental-basedir=\/var\/lib\/mysql-xtra 2&gt;&1          if [ $? -gt 0 ]; then            echo &quot;Error in inc stage&quot; &gt;&2          fi          #ionice -c3          \/usr\/bin\/innobackupex --defaults-file=\/etc\/my.cnf --password=`cat \/root\/.mysql` --no-timestamp  --throttle=40 --apply-log \/var\/lib\/mysql-xtra --incremental-dir=\/var\/lib\/mysql-xtra-inc 2&gt;&1          if [ $? -gt 0 ]; then            echo &quot;Error in inc apply stage&quot; &gt;&2          fi          \/usr\/bin\/rsync -vaH --delete -f &quot;+ *\/&quot; -f &quot;+ *\/**&quot; -f &quot;- *&quot; \/var\/lib\/mysql-xtra-inc\/ \/var\/lib\/mysql-xtra          rm -rf \/var\/lib\/mysql-xtra-inc          echo INC backup stage finished at `date` code $?      fi  return 0 <\/code><\/pre>\n<p>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439 \u0438 \u0444\u0443\u043a\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0438\u0438 \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0414\u043b\u044f \u0447\u0435\u0433\u043e? \u2014 \u0424\u0435\u043d\u0448\u0443\u0439. \u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0438 \u043a\u0430\u043a\u0443\u044e \u043e\u043d \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043a\u043e\u043c\u043f\u0440\u0435\u0441\u0441\u0438\u044e. \u0414\u0430\u0434\u0438\u043c \u0435\u043c\u0443 \u043f\u0440\u0430\u0432\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<pre><code class=\"bash\"># Compression function plus latest copy  SUFFIX=&quot;&quot;  compression () {      if [ &quot;$SEPTABLE&quot; = &quot;yes&quot; ]; then          TBDIR=`\/usr\/bin\/dirname $2`          TFNAME=`\/bin\/basename $2`          if [ &quot;$COMP&quot; = &quot;gzip&quot; ]; then              TPWD=`pwd`              cd $TBDIR              tar -czvf &quot;$1.tgz&quot; ${TFNAME}*.sql 2&gt;&1              cd $TPWD              SUFFIX=&quot;.tgz&quot;          elif [ &quot;$COMP&quot; = &quot;bzip2&quot; ]; then              TPWD=`pwd`              cd $TBDIR              tar -cjvf &quot;$1.tbz2&quot; ${TFNAME}*.sql 2&gt;&1              cd $TPWD              SUFFIX=&quot;.tbz2&quot;          fi          rm -f ${2}*.sql      else          if [ &quot;$COMP&quot; = &quot;gzip&quot; ]; then              gzip -f &quot;$1&quot;              echo              echo Backup Information for &quot;$1&quot;              gzip -l &quot;$1.gz&quot;              SUFFIX=&quot;.gz&quot;          elif [ &quot;$COMP&quot; = &quot;bzip2&quot; ]; then          echo Compression information for &quot;$1.bz2&quot;          bzip2 -f -v $1 2&gt;&1          SUFFIX=&quot;.bz2&quot;      else          echo &quot;No compression option set, check advanced settings&quot;      fi fi      if [ &quot;$LATEST&quot; = &quot;yes&quot; ]; then          cp $1$SUFFIX &quot;$BACKUPDIR\/latest\/&quot;      fi      return 0  }  # Compression function plus latest copy  SUFFIX=&quot;&quot;  compression_h () {      if [ &quot;$COMP&quot; = &quot;gzip&quot; ]; then          TPWD=`pwd`          cd \/var\/lib\/mysql.backup          tar -czvf &quot;$1.tgz&quot; . 2&gt;&1          cd $TPWD          SUFFIX=&quot;.tgz&quot;      elif [ &quot;$COMP&quot; = &quot;bzip2&quot; ]; then          TPWD=`pwd`          cd \/var\/lib\/mysql.backup          tar -cjvf &quot;$1.tbz2&quot; . 2&gt;&1          cd $TPWD          SUFFIX=&quot;.tbz2&quot;      else          echo &quot;No compression option set, check advanced settings&quot;      fi      if [ &quot;$LATEST&quot; = &quot;yes&quot; ]; then          cp $1$SUFFIX_H &quot;$BACKUPDIR\/latest\/&quot;      fi      return 0  } <\/code><\/pre>\n<p>  \u041e\u043f\u0438\u0448\u0435\u043c \u0440\u043e\u0442\u0430\u0446\u0438\u044e. \u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u0441\u0440\u043e\u043a\u0435 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0431\u044b\u0432\u0430\u044e\u0442 \u0440\u0430\u0437\u043d\u044b\u0435.<\/p>\n<pre><code class=\"bash\">## rotates monthly backups, set 'keep' to the last n backups to keep  rotateMonthly () {        mdbdir=&quot;$1&quot;     ## set to the number of monthly backups to keep  keep=$BACKUP_MONTH     (cd ${mdbdir}         totalFilesCount=`\/bin\/ls -1 | wc -l`         if [ ${totalFilesCount} -gt ${keep} ]; then          purgeFilesCount=`expr ${totalFilesCount} - ${keep}`          purgeFilesList=`\/bin\/ls -1tr | head -${purgeFilesCount}`             echo &quot;&quot;          echo &quot;Rotating monthly: Purging in ${mdbdir}&quot;          rm -fv ${purgeFilesList} | sed -e 's\/^\/\/g'      fi  )  } <\/code><\/pre>\n<p>  \u0411\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0435\u043a\u0430\u043f\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443. \u041f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0445. \u0421\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u0438\u043a\u0430\u043c \u0438 \u0434\u0430\u043c\u043f\u0435 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0439 \u0431\u0430\u0437\u044b. \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c.<\/p>\n<pre><code class=\"bash\"># Run command before we begin  if [ &quot;$PREBACKUP&quot; ]          then          echo ======================================================================          echo &quot;Prebackup command output.&quot;          echo          eval $PREBACKUP          echo          echo ======================================================================          echo  fi <\/code><\/pre>\n<p>  \u041f\u043e\u0440\u043e\u0439 \u043d\u0435 \u0432\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u043a\u0430\u043f\u0438\u0442\u044c.<\/p>\n<pre><code class=\"bash\"># Add --ignore-table options to $OPT  if [ -n &quot;$TABLEEXCLUDE&quot; ]; then          for table in $TABLEEXCLUDE ; do                  OPT=&quot;${OPT} --ignore-table=${table}&quot;          done  fi <\/code><\/pre>\n<p>  \u0414\u0443\u043c\u0430\u044e, \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f<\/p>\n<pre><code class=\"bash\">if [ &quot;$SEPDIR&quot; = &quot;yes&quot; ]; then # Check if CREATE DATABSE should be included in Dump          if [ &quot;$CREATE_DATABASE&quot; = &quot;no&quot; ]; then                  OPT=&quot;$OPT --no-create-db&quot;          else                  OPT=&quot;$OPT --databases&quot;          fi  else          OPT=&quot;$OPT --databases&quot;  fi     # Hostname for LOG information  if [ &quot;$DBHOST&quot; = &quot;localhost&quot; ]; then          HOST=`hostname`          if [ &quot;$SOCKET&quot; ]; then                  OPT=&quot;$OPT --socket=$SOCKET&quot;          fi  else          HOST=$DBHOST  fi <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0441\u0435 \u0431\u0430\u0437\u044b \u0438 \u0443\u0434\u0430\u043b\u0438\u043c \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0434\u043b\u044f \u0431\u0435\u043a\u0430\u043f\u0430 \u0431\u0430\u0437\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"bash\"># If backing up all DBs on the server  if [ &quot;$DBNAMES&quot; = &quot;all&quot; ]; then          DBNAMES=&quot;`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --batch --skip-column-names -e &quot;show databases&quot;| sed 's\/ \/%\/g'`&quot;             # If DBs are excluded          for exclude in $DBEXCLUDE          do                  DBNAMES=`echo $DBNAMES | sed &quot;s\/\\b$exclude\\b\/\/g&quot;`          done             MDBNAMES=$DBNAMES  Fi <\/code><\/pre>\n<p>  \u041f\u043e\u0440\u0430 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u0431\u0435\u043a\u0430\u043f\u0443<\/p>\n<pre><code class=\"bash\">echo ======================================================================  echo AutoMySQLBackup VER $VER  echo http:\/\/sourceforge.net\/projects\/automysqlbackup\/  echo  echo Backup of Database Server - $HOST  echo ====================================================================== <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0434\u0430\u043c\u043f\u044b? \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0434\u0430\u043c\u043f\u0430\u043c<\/p>\n<pre><code class=\"bash\">if [ &quot;$DO_SQL_DUMP&quot; = &quot;yes&quot; ]; then     echo Backup Start Time `date`  echo ====================================================================== <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u043e \u0444\u0435\u043d\u0448\u0443\u044e \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0431\u0435\u043a\u0430\u043f\u0430, \u043d\u0443 \u0447\u0442\u043e \u0436 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e? \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0441\u044f\u0447\u043d\u044b\u0439 \u0434\u0430\u043c\u043f.<\/p>\n<pre><code class=\"bash\"> # Monthly Full Backup of all Databases          if [ $DOM = &quot;01&quot; ]; then                  for MDB in $MDBNAMES                  do                           # Prepare $DB for using                          MDB=&quot;`echo $MDB | sed 's\/%\/ \/g'`&quot;                             if [ ! -e &quot;$BACKUPDIR\/monthly\/$MDB&quot; ]           # Check Monthly DB Directory exists.                          then                                  mkdir -p &quot;$BACKUPDIR\/monthly\/$MDB&quot;                          fi                          echo Monthly Backup of $MDB...                                  dbdump &quot;$MDB&quot; &quot;$BACKUPDIR\/monthly\/$MDB\/${MDB}_$DATE.$M.$MDB.sql&quot; &quot;$BACKUPDIR\/monthly\/$MDB\/${MDB}&quot;                                  compression &quot;$BACKUPDIR\/monthly\/$MDB\/${MDB}_$DATE.$M.$MDB.sql&quot; &quot;$BACKUPDIR\/monthly\/$MDB\/${MDB}&quot;                                  BACKUPFILES=&quot;$BACKUPFILES $BACKUPDIR\/monthly\/$MDB\/${MDB}_$DATE.$M.$MDB.sql$SUFFIX&quot;                          echo ----------------------------------------------------------------------                          TTT=`expr 33 \\* $BACKUP_MONTH`                          \/usr\/bin\/find &quot;$BACKUPDIR\/monthly\/$MDB&quot; -name &quot;*.sql.*&quot; -mtime +$TTT -type f -delete                     done <\/code><\/pre>\n<p>  \u041d\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u0435\u0441\u044f\u0446\u0430? \u2013 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e-\u0435\u0436\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u043c\u0443 \u0431\u0435\u043a\u0430\u043f\u0443. \u041f\u0440\u0435\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"bash\">else                     for DB in $DBNAMES                  do                  # Prepare $DB for using                  DB=&quot;`echo $DB | sed 's\/%\/ \/g'`&quot;                     # Create Seperate directory for each DB                  if [ ! -e &quot;$BACKUPDIR\/daily\/$DB&quot; ]              # Check Daily DB Directory exists.                  then                          mkdir -p &quot;$BACKUPDIR\/daily\/$DB&quot;                  fi                  if [ $BACKUP_DAYS -le 7 ]; then                      if [ ! -e &quot;$BACKUPDIR\/weekly\/$DB&quot; ]         # Check Weekly DB Directory exists.                      then                          mkdir -p &quot;$BACKUPDIR\/weekly\/$DB&quot;                      fi                      # Weekly Backup                  fi                  if [ $DNOW = $DOWEEKLY -a $BACKUP_DAYS -le 7 ]; then                      echo Weekly Backup of Database \\( $DB \\)                      echo Rotating 5 weeks Backups...                      if [ &quot;$W&quot; -le 05 ];then                                  REMW=`expr 48 + $W`                          elif [ &quot;$W&quot; -lt 15 ];then                                  REMW=0`expr $W - 5`                          else                                  REMW=`expr $W - 5`                      fi                      eval rm -fv &quot;$BACKUPDIR\/weekly\/$DB\/${DB}_week.$REMW.*&quot;   echo                          dbdump &quot;$DB&quot; &quot;$BACKUPDIR\/weekly\/$DB\/${DB}_week.$W.$DATE.sql&quot; &quot;$BACKUPDIR\/weekly\/$DB\/${DB}&quot;                          compression &quot;$BACKUPDIR\/weekly\/$DB\/${DB}_week.$W.$DATE.sql&quot; &quot;$BACKUPDIR\/weekly\/$DB\/${DB}&quot;                          BACKUPFILES=&quot;$BACKUPFILES $BACKUPDIR\/weekly\/$DB\/${DB}_week.$W.$DATE.sql$SUFFIX&quot;                      echo ----------------------------------------------------------------------                  # Daily Backup                  else                      echo Daily Backup of Database \\( $DB \\)                      echo Rotating last weeks Backup...                      \/usr\/bin\/find &quot;$BACKUPDIR\/daily\/$DB&quot; -name &quot;*.sql.*&quot; -mtime +$BACKUP_DAYS -delete                      echo                          dbdump &quot;$DB&quot; &quot;$BACKUPDIR\/daily\/$DB\/${DB}_$DATE.$DOW.sql&quot; &quot;$BACKUPDIR\/daily\/$DB\/${DB}&quot;                          compression &quot;$BACKUPDIR\/daily\/$DB\/${DB}_$DATE.$DOW.sql&quot; &quot;$BACKUPDIR\/daily\/$DB\/${DB}&quot;                          BACKUPFILES=&quot;$BACKUPFILES $BACKUPDIR\/daily\/$DB\/${DB}_$DATE.$DOW.sql$SUFFIX&quot;                      echo ----------------------------------------------------------------------                  fi                  done          fi  echo Backup End `date`  echo ======================================================================  fi <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d HOT BACKUP? \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c:<\/p>\n<pre><code class=\"bash\">#### HOT BACKUP  if [ &quot;$DO_HOT_BACKUP&quot; = &quot;yes&quot; ]; then         echo HOT Backup Start `date`      echo ======================================================================      # Monthly HOT Full Backup of all Databases      if [ $DOM = &quot;01&quot; ]; then          echo Monthly full Backup of \\( $MDBNAMES \\)...          dbdump_h &quot;$MDBNAMES&quot; &quot;$BACKUPDIR\/monthly\/$DATE.$M.all-databases.sql&quot;  ###        compression_h &quot;$BACKUPDIR\/monthly\/$DATE.$M.all-databases.sql&quot;          BACKUPFILES=&quot;$BACKUPFILES $BACKUPDIR\/monthly\/$DATE.$M.all-databases.sql$SUFFIX&quot;          echo ----------------------------------------------------------------------  ###     TTT=`expr 33 \\* $BACKUP_MONTH`  ###     \/usr\/bin\/find &quot;$BACKUPDIR\/monthly\/&quot; -name &quot;*.all-databases.sql.*&quot; -mtime +$TTT -type f -delete      else  # Weekly Backup      if [ $DNOW = $DOWEEKLY -a $BACKUP_DAYS -le 7 ]; then          echo Weekly Backup of Databases \\( $DBNAMES \\)          echo          echo Rotating 5 weeks Backups...          if [ &quot;$W&quot; -le 05 ];then                  REMW=`expr 48 + $W`          elif [ &quot;$W&quot; -lt 15 ];then                  REMW=0`expr $W - 5`          else                  REMW=`expr $W - 5`          fi          eval rm -fv &quot;$BACKUPDIR\/weekly\/week.$REMW.*&quot;          echo          dbdump_h &quot;$DBNAMES&quot; &quot;$BACKUPDIR\/weekly\/week.$W.$DATE.sql&quot;  ###        compression_h &quot;$BACKUPDIR\/weekly\/week.$W.$DATE.sql&quot;          BACKUPFILES=&quot;$BACKUPFILES $BACKUPDIR\/weekly\/week.$W.$DATE.sql$SUFFIX&quot;          echo ----------------------------------------------------------------------  # Daily Backup else          echo Daily Backup of Databases \\( $DBNAMES \\)          echo          echo Rotating last weeks Backup...          \/usr\/bin\/find &quot;$BACKUPDIR\/daily\/$DB&quot; -name &quot;*.sql.*&quot; -mtime +$BACKUP_DAYS -delete          echo          dbdump_h &quot;$DBNAMES&quot; &quot;$BACKUPDIR\/daily\/$DATE.$DOW.sql&quot;  ###        compression_h &quot;$BACKUPDIR\/daily\/$DATE.$DOW.sql&quot;          BACKUPFILES=&quot;$BACKUPFILES $BACKUPDIR\/daily\/$DATE.$DOW.sql$SUFFIX&quot;          echo ----------------------------------------------------------------------      fi      fi      echo Backup End Time `date`      echo ======================================================================  fi <\/code><\/pre>\n<p>  HOT XTRA BACKUP? \u2014 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"bash\">#### HOT XTRA BACKUP  if [ &quot;$HOT_XTRA_BACKUP&quot; = &quot;yes&quot; ]; then      dbdump_h_xtra  fi     \u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 - mydumper:  #### DO_MYDUMPER_BACKUP  if [ &quot;$DO_MYDUMPER_BACKUP&quot; = &quot;yes&quot; ]; then      # Monthly Full Backup of all Databases      BACKUPDIRM=$BACKUPDIR\/daily\/      if [ $DOM = &quot;01&quot; ]; then         BACKUPDIRM=$BACKUPDIR\/monthly\/      else        if [ $DNOW = $DOWEEKLY -a $BACKUP_DAYS -le 7 ]; then          BACKUPDIRM=$BACKUPDIR\/weekly\/        fi      fi      BACKUPDIRM=${BACKUPDIRM}_mydumper-`date +%F_%R`      dbdump_mydumper &quot;$BACKUPDIRM&quot;      OPT=&quot;$OPT --no-data&quot;      for DB in $DBNAMES      do          # Prepare $DB for using          DB=&quot;`echo $DB | sed 's\/%\/ \/g'`&quot;          dbdump &quot;$DB&quot; &quot;$BACKUPDIRM\/$DB-schema.sql&quot;          compression &quot;$BACKUPDIRM\/$DB-schema.sql&quot;      done  fi <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0434\u0430\u043c\u043f\u044b, \u043c\u0435\u0441\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0443 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"bash\">echo Total disk space used for backup storage..  echo Size - Location  echo `du -hs &quot;$BACKUPDIR&quot;`  echo <\/code><\/pre>\n<p>  \u041f\u043e\u0440\u043e\u0439 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u043f\u043e\u0441\u043b\u0435 \u0431\u0435\u043a\u0430\u043f\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u043d\u043e\u0432\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0430\u0439\u0442. \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"bash\"># Run command when we're done  if [ &quot;$POSTBACKUP&quot; ]          then          echo ======================================================================          echo &quot;Postbackup command output.&quot;          echo          eval $POSTBACKUP          echo          echo ======================================================================  fi <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u043b\u043e\u0433\u0430 \u0431\u0435\u043a\u0430\u043f\u0430<\/p>\n<pre><code class=\"bash\">#Clean up IO redirection  exec 1&gt;&6 6&gt;&-      # Restore stdout and close file descriptor #6.  exec 1&gt;&7 7&gt;&-      # Restore stdout and close file descriptor #7. <\/code><\/pre>\n<p>  \u0414\u0430, \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0441\u043f\u0430\u0441\u0438\u0431\u043e. \u0423\u0434\u0430\u043b\u0438\u043c \u044d\u0442\u043e \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u043e\u0433\u0430.<\/p>\n<pre><code class=\"bash\">sed -i '\/Using a password on the command line interface can be insecure\/d' $LOGERR <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432: \u043f\u0440\u0438\u0441\u043b\u0430\u0442\u044c \u043b\u043e\u0433 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u043f\u0440\u0438\u0441\u043b\u0430\u0442\u044c \u043b\u043e\u0433 \u0438 \u0444\u0430\u0439\u043b\u044b \u0434\u0430\u043c\u043f\u0430, \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c (\u043e\u0442\u043b\u0430\u0434\u043a\u0430, \u043a\u0443\u0434\u0430 \u0436\u0435 \u0431\u0435\u0437 \u043d\u0435\u0451), \u043f\u0440\u0438\u0441\u043b\u0430\u0442\u044c \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u043b\u043e\u0433 \u0438 \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439 \u0432 \u0434\u0435\u0444\u043e\u043b\u0442\u0435 \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041d\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u0432\u0441\u0435.<\/p>\n<pre><code class=\"bash\">if [ &quot;$MAILCONTENT&quot; = &quot;files&quot; ]  then          if [ -s &quot;$LOGERR&quot; ]          then                  # Include error log if is larger than zero.                  BACKUPFILES=&quot;$BACKUPFILES $LOGERR&quot;                  ERRORNOTE=&quot;WARNING: Error Reported - &quot;          fi          #Get backup size          ATTSIZE=`du -c $BACKUPFILES | grep &quot;[[:digit:][:space:]]total$&quot; |sed s\/\\s*total\/\/`          if [ $MAXATTSIZE -ge $ATTSIZE ]          then                  BACKUPFILES=`echo &quot;$BACKUPFILES&quot; | sed -e &quot;s# # -a #g&quot;` #enable multiple attachments                  mutt -s &quot;$ERRORNOTE MySQL Backup Log and SQL Files for $HOST - $DATE&quot; $BACKUPFILES $MAILADDR &lt; $LOGFILE         #send via mutt          else                  cat &quot;$LOGFILE&quot; | mail -s &quot;WARNING! - MySQL Backup exceeds set maximum attachment size on $HOST - $DATE&quot; $MAILADDR          fi  elif [ &quot;$MAILCONTENT&quot; = &quot;log&quot; ]  then          cat &quot;$LOGFILE&quot; | mail -s &quot;MySQL Backup Log for $HOST - $DATE&quot; $MAILADDR          if [ -s &quot;$LOGERR&quot; ]                  then                          cat &quot;$LOGERR&quot; | mail -s &quot;ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE&quot; $MAILADDR          fi  elif [ &quot;$MAILCONTENT&quot; = &quot;quiet&quot; ]  then          if [ -s &quot;$LOGERR&quot; ]                  then                          cat &quot;$LOGERR&quot; | mail -s &quot;ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE&quot; $MAILADDR                          cat &quot;$LOGFILE&quot; | mail -s &quot;MySQL Backup Log for $HOST - $DATE&quot; $MAILADDR          fi  else          if [ -s &quot;$LOGERR&quot; ]                  then                          cat &quot;$LOGFILE&quot;                         echo                          echo &quot;###### WARNING ######&quot;                          echo &quot;Errors reported during AutoMySQLBackup execution.. Backup failed&quot;                          echo &quot;Error log below..&quot;                          cat &quot;$LOGERR&quot;          else                  cat &quot;$LOGFILE&quot;          fi  fi <\/code><\/pre>\n<p>  \u041f\u043e\u0447\u0438\u0441\u0442\u0438\u043c \u0437\u0430 \u0441\u043e\u0431\u043e\u0439:<\/p>\n<pre><code class=\"bash\">if [ -s &quot;$LOGERR&quot; ]          then                  STATUS=1          else                  STATUS=0  fi     # Clean up Logfile  eval rm -f &quot;$LOGFILE&quot;  eval rm -f &quot;$LOGERR&quot;  exit $STATUS <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433 \u0434\u043b\u044f \u043e\u043f\u0446\u0438\u0439:<\/p>\n<pre><code class=\"bash\"># Username to access the MySQL server e.g. dbuser  USERNAME=root     # Username to access the MySQL server e.g. password  if [ -f &quot;\/root\/.mysql&quot; ]; then      PASSWORD=`cat \/root\/.mysql`  else      exit 0  fi     # Host name (or IP address) of MySQL server e.g localhost  DBHOST=localhost     # List of DBNAMES for Daily\/Weekly Backup e.g. &quot;DB1 DB2 DB3&quot;  DBNAMES=&quot;all&quot;     # Backup directory location e.g \/backups  BACKUPDIR=&quot;\/var\/backups\/mysql&quot;     # Mail setup  # What would you like to be mailed to you?  # - log   : send only log file  # - files : send log file and sql files as attachments (see docs)  # - stdout : will simply output the log to the screen if run manually.  # - quiet : Only send logs if an error occurs to the MAILADDR.  MAILCONTENT=&quot;quiet&quot;     # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])  MAXATTSIZE=&quot;4000&quot;     # Email Address to send mail to? (user@domain.com)  MAILADDR=&quot;root&quot; # ============================================================  # === ADVANCED OPTIONS ( Read the doc's below for details )===  #=============================================================     # List of DBBNAMES for Monthly Backups.  MDBNAMES=&quot;mysql $DBNAMES&quot;     # List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in &quot; quotes)  DBEXCLUDE=&quot;information_schema performance_schema &quot;     # List of tables to exclude from the backup (in form db.table)  TABLEEXCLUDE=&quot;&quot;     # Include CREATE DATABASE in backup?  CREATE_DATABASE=no     # Separate backup directory and file for each DB? (yes or no)  SEPDIR=yes     # Which day do you want weekly backups? (1 to 7 where 1 is Monday)  DOWEEKLY=0     # How many days keep backup  BACKUP_DAYS=3     # Choose Compression type. (gzip or bzip2)  COMP=gzip  # Compress communications between backup server and MySQL server?  COMMCOMP=no     # Additionally keep a copy of the most recent backup in a seperate directory.  LATEST=no     #  The maximum size of the buffer for client\/server communication. e.g. 16MB (maximum is 1GB)  MAX_ALLOWED_PACKET=1GB  #  For connections to localhost. Sometimes the Unix socket file must be specified.  OS=`uname`  if [ &quot;$OS&quot; = &quot;FreeBSD&quot; ]; then      SOCKET=\/tmp\/mysql.sock  else      SOCKET=\/var\/lib\/mysql\/mysql.sock  fi     # Command to run before backups (uncomment to use)  #PREBACKUP=&quot;\/etc\/mysql-backup-pre&quot;     # Command run after backups (uncomment to use)  #POSTBACKUP=&quot;\/etc\/mysql-backup-post&quot;     # (\u0435\u0441\u043b\u0438 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043e, \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0442\u0430\u043a \u0438 \u0434\u0435\u043b\u0430\u0442\u044c)  DO_SQL_DUMP=yes  # separate table to file ?  SEPTABLE=no     # (\u0435\u0441\u043b\u0438 \u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043e, \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c)  DO_HOT_BACKUP=no  HOT_XTRA_BACKUP=no  DO_MYDUMPER_BACKUP=no  <\/code><\/pre>\n<p>  \u041c\u044b \u043d\u0435 \u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0446\u0435\u043b\u044c\u044e \u00ab\u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0410\u043c\u0435\u0440\u0438\u043a\u0443\u00bb, \u043d\u043e \u0442\u0435\u043c\u0430 \u0431\u0435\u043a\u0430\u043f\u043e\u0432 \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0451\u0442 \u0431\u044b\u0442\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439. \u0418 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u0430\u043c\u043f \u0431\u0430\u0437\u044b, \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0434\u0430\u043c\u043f\u0430. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0432 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442 \u0432\u0430\u043c \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0431\u0435\u043a\u0430\u043f\u043e\u0432. \u0410 \u0442\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b \u0441\u0432\u043e\u0439 \u0431\u0435\u043a\u0430\u043f?<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/centos-admin.ru\/images\/habrahabr\/backup2.png\" alt=\"image\"\/>      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/company\/centosadmin\/blog\/227533\/\"> http:\/\/habrahabr.ru\/company\/centosadmin\/blog\/227533\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/c05\/89e\/903\/c0589e9034c9e6658b5adbf2b08af8a3.jpg\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 mysql. <br \/>  \u0418 \u043e\u0434\u043d\u043e \u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u0432\u0430\u0436\u043d\u044b\u0445 \u2013 \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u0430 \u0441\u0434\u0435\u043b\u0430\u043b\u0441\u044f \u043b\u0438 \u0431\u0435\u043a\u0430\u043f? \u0410 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043b\u0438 \u043f\u0440\u043e\u0448\u0435\u043b \u0434\u0430\u043c\u043f? \u0410 \u0431\u044b\u043b\u0438 \u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0438? \u0410 \u0437\u043d\u0430\u044e \u043b\u0438 \u044f \u043e \u043d\u0438\u0445<\/p>\n<p>  \u041f\u043e-\u043c\u043e\u0435\u043c\u0443, \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0440\u044f\u0434 \u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u0433\u043e, \u043a\u0442\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0431\u0435\u043a\u0430\u043f. \u041d\u043e \u0432\u043e\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0431\u0435\u043a\u0430\u043f\u0430, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u044e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c <a href=\"http:\/\/centos-admin.ru\">\u043c\u044b<\/a>.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0441\u0445\u0435\u043c\u044b, \u043d\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0434\u043b\u044f \u0441\u0435\u0431\u044f, \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435, \u0447\u0442\u043e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0443 \u0441\u0435\u0431\u044f.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-227533","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/227533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227533"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/227533\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}