MySQL自動化メンテナンスmysqldumpとmysqlbinlogを使用して、あるデータベースの毎週の完全な準備と毎日の差異の準備を実現
ケース:
オンライン上にデータベースがあります.週に1回、毎日1回準備する必要があります.
1、毎週データベースhellodbを完全バックアップする
crontabタスク計画:
完全バックアップスクリプト/work/dump-complete-hello.shの内容は以下の通りである.
2、毎日データベースhellodbに対して差異バックアップを行う:
crontabタスク計画:
差分スクリプト/work/dump-incre.shの内容は以下の通りである.
3、回復テスト:
フル・スタンバイ・リカバリ:
差分リカバリ:
以上の結果から、フルバックアップと差分バックアップが回復できることがわかりました.それでは、正常に使用することができます.交差することができます.ははは
オンライン上にデータベースがあります.週に1回、毎日1回準備する必要があります.
1、毎週データベースhellodbを完全バックアップする
crontabタスク計画:
10 01 * * 1 /bin/bash /work/dump-complete-hello.sh ===> 1 10 /work/dump-complete-hello.sh
完全バックアップスクリプト/work/dump-complete-hello.shの内容は以下の通りである.
#!/bin/bash
#
weekbackup=/complete/hello-`date +%F`.sql
# mysqldump
# --database
# --master-data CHANGE MASTER TO ,2
# --flush-logs flush logs , binlog
# --single-transaction: , hellodb innodb , ,
/usr/local/mysql/bin/mysqldump --database hellodb --master-data=2 --flush-logs --single-transaction > $weekbackup
# ,
cat > weekbackup.sh << EOF
#!/bin/bash
EOF
echo "wb=$weekbackup" >> weekbackup.sh
2、毎日データベースhellodbに対して差異バックアップを行う:
crontabタスク計画:
20 02 * * * /bin/bash /work/dump-incre.sh ==> 2 20 /work/dump-incre.sh
差分スクリプト/work/dump-incre.shの内容は以下の通りである.
#!/bin/bash
# source /work/weekbackup.sh, ,
. /work/weekbackup.sh
#
binlog=`/usr/local/mysql/bin/mysql -e 'show master status' | grep 'bin' | awk '{print $1}'`
# time
time=grep 'completed' $wb | awk '{printf "%s %s
",$5,$6}'
# mysqlbinlog hellodb
# --start-position position, position
# /var/log/mysql/binarylog/$binlog
/usr/local/mysql/bin/mysqlbinlog --start-datetime="$time" /var/log/mysql/binarylog/$binlog > /increment/incre-`date +%F%H%M%S`.sql
3、回復テスト:
フル・スタンバイ・リカバリ:
[root@localhost data]# mysql < /complete/hello-2015-01-13.sql
[root@localhost data]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.36-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hellodb |
| mysql |
| newdb |
| performance_schema |
| tempdb |
| test |
+--------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> use hellodb;
Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| toc |
+-------------------+
7 rows in set (0.00 sec)
差分リカバリ:
[root@localhost data]# mysql < /increment/incre-2015-01-13.sql
[root@localhost data]# mysqll
-bash: mysqll: command not found
[root@localhost data]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.36-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use hellodb;
Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| tb1 |
| teachers |
| toc |
+-------------------+
8 rows in set (0.00 sec)
MariaDB [hellodb]> select * from tb1;
+------+
| name |
+------+
| wjs |
+------+
1 row in set (0.01 sec)
以上の結果から、フルバックアップと差分バックアップが回復できることがわかりました.それでは、正常に使用することができます.交差することができます.ははは