Backup

rsnapshot - 未正確歸檔 mysql 數據庫

  • November 24, 2012

我的 rsnapshot 配置:

snapshot_root   /.snapshots/
backup  /home/user          localhost/
backup_script   /usr/local/backup_mysql.sh      localhost/mysql/

使用這個文件:

NOW=$(date +"%m-%d-%Y") # mm-dd-yyyy format
FILE=""                 # used in a loop

### Server Setup ###
#* MySQL login user name *#
MUSER="root"

#* MySQL login PASSWORD name *#
MPASS="YOUR-PASSWORD"

#* MySQL login HOST name *#
MHOST="127.0.0.1"

#* MySQL binaries *#
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

# get all database listing
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"

# start to dump database one by one
for db in $DBS
do
FILE=$BAK/mysql-$db.$NOW-$(date +"%T").gz
# gzip compression for each backup file
$MYSQLDUMP --single-transaction -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done

它將數據庫轉儲到 /

然後我嘗試了以下內容:http: //bash.cyberciti.biz/backup/rsnapshot-remote-mysql-backup-shell-script/

我有:

rsnapshot hourly
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/bin/rsnapshot hourly
----------------------------------------------------------------------------
ERROR: backup_script /usr/local/backup_mysql.sh returned 1
WARNING: Rolling back "localhost/mysql/"


ls -la /.snapshots/hourly.0/localhost/mysql
total 8
drwxr-xr-x 2 root root 4096 Nov 23 17:43 ./
drwxr-xr-x 4 root root 4096 Nov 23 18:20 ../

我到底做錯了什麼?

編輯:

# /usr/local/backup_mysql.sh
*** Dumping MySQL Database ***
Database> information_schema..cphulkd..eximstats..horde..leechprotect..logaholicDB_ns1..modsec..mysql..performance_schema..roundcube..test..
*** Backup done [ files wrote to /.snapshots/tmp/mysql] ***
root@ns1 [~]# ls -la /.snapshots/tmp/mysql
total 8040
drwxr-xr-x 2 root root    4096 Nov 23 18:41 ./
drwxr-xr-x 3 root root    4096 Nov 23 18:41 ../
-rw-r--r-- 1 root root    1409 Nov 23 18:41 cphulkd.18_41_45pm.gz
-rw-r--r-- 1 root root  113522 Nov 23 18:41 eximstats.18_41_45pm.gz
-rw-r--r-- 1 root root    4583 Nov 23 18:41 horde.18_41_45pm.gz
-rw-r--r-- 1 root root   71757 Nov 23 18:41 information_schema.18_41_45pm.gz
-rw-r--r-- 1 root root     692 Nov 23 18:41 leechprotect.18_41_45pm.gz
-rw-r--r-- 1 root root    2603 Nov 23 18:41 logaholicDB_ns1.18_41_45pm.gz
-rw-r--r-- 1 root root     745 Nov 23 18:41 modsec.18_41_45pm.gz
-rw-r--r-- 1 root root  138928 Nov 23 18:41 mysql.18_41_45pm.gz
-rw-r--r-- 1 root root    1831 Nov 23 18:41 performance_schema.18_41_45pm.gz
-rw-r--r-- 1 root root    3610 Nov 23 18:41 roundcube.18_41_45pm.gz
-rw-r--r-- 1 root root     436 Nov 23 18:41 test.18_41_47pm.gz

MySQL 備份似乎很好。

我發現了問題。範例腳本未正確編碼。與 VERBOSE 命令有關。

編輯:不是我的錯誤,只是編寫腳本的編碼人員。

註釋掉詳細行或將詳細更改為 1 並且腳本可以正常工作。

引用自:https://serverfault.com/questions/451675