MySQL 数据库的备份与还原
备份:
// 需要用到的备份脚本:
[root@Linkdood ~]# ll /data/linkdood/im/bin/mysql_manager_V2.0.sh
-rwxr-xr-x 1 root root 32676 Aug 17 20:11 /data/linkdood/im/bin/mysql_manager_V2.0.sh
// 需要用到的备份工具:
[root@Linkdood ~]# ll /usr/bin/pigz
-rwxr-xr-x 1 root root 148668 Aug 17 20:11 /usr/bin/pigz
// 需要用到的数据库密码解密脚本
[root@Linkdood ~]# ll /data/linkdood/im/bin/decrypt_so.py
-rwxr-xr-x 1 root root 2167 Aug 17 20:11 /data/linkdood/im/bin/decrypt_so.py
[root@Linkdood ~]# /data/linkdood/im/bin/mysql_manager_V2.0.sh
Usage:
./Mysql_Manager_backup.sh -[Options]
Options:
mysql_manager.sh -V --all|--mess -> Display Tools Version.
mysql_manager.sh --help --all|--mess -> Scripts Help Documemtation.
mysql_manager.sh --auto-backup --all|--mess -> Auto Hot Backup Mysql Data,Apply Log,Tar Package,Using Defalut Parameters.
mysql_manager.sh --backup --all|--mess -> Manual Hot Backup Mysql Data,Apply Log,Tar Package,Using Input or Default Parameters.
mysql_manager.sh --auto-restore --all|--mess -> Auto Hot Restore Mysql Data,Using Default Parameters.
mysql_manager.sh --restore --all|--mess -> Manual Hot Restore Mysql Data,Using Input or Default Parameters.
mysql_manager.sh --auto-expired --all|--mess -> Auto Delete Expired Backup Files,Using Default Parameters.
mysql_manager.sh --expired --all|--mess -> Manual Delete Expired Backup Files,Using Input or Default Parameters.
Examples:
./mysql_manager.sh --backup --all
./mysql_manager.sh --backup --mess
// 执行脚本 手动备份 备份全库
[root@Linkdood ~]# /data/linkdood/im/bin/mysql_manager_V2.0.sh --backup --all
-- Welcome Use Mysql_Manager --
// 确认MySQL配置文件位置(默认即可)
Please Input Mysql Config File [Default:/data/linkdood/im/vrv/mysql/my.cnf]:
// 确认MySQL备份文件存放位置(默认即可)
Please Input Mysql Backup Path [Default:/data/data_center/mysql_backup]:
// 备份过程 全部ok 即完成
1.Mysql Config File Is Normative. [OK]
2.Mysql Backup Path Is Normative. [OK]
3.Mysql InnoBackupex Is Success. [OK]
4.Mysql Apply Hot-Log Is Success. [OK]
5.Mysql Tar Packaging Is Success. [OK]
--> Mysql Backup Success <-- [OK]
--> Expired Delete Success <-- [OK]
------
// 执行脚本 手动备份 不备份消息数据库 IM_MESSAGESTORAGE
[root@Linkdood ~]# /data/linkdood/im/bin/mysql_manager_V2.0.sh --backup --mess
-- Welcome Use Mysql_Manager --
Please Input Mysql Config File [Default:/data/linkdood/im/vrv/mysql/my.cnf]:
Please Input Mysql Backup Path [Default:/data/data_center/mysql_backup]:
1.Mysql Config File Is Normative. [OK]
2.Mysql Backup Path Is Normative. [OK]
3.Mysql InnoBackupex Is Success. [OK]
4.Mysql Apply Hot-Log Is Success. [OK]
5.Mysql Tar Packaging Is Success. [OK]
--> Mysql Backup Success <-- [OK]
--> Expired Delete Success <-- [OK]
还原:
[root@Linkdood ~]# cd /data/data_center/mysql_backup/
[root@Linkdood mysql_backup]# ll
total 38604
-rw-r--r-- 1 root root 1831357 Sep 29 03:10 Mysql_backup_all_2018-09-29_031011.tar.gz
-rw-r--r-- 1 root root 1830329 Sep 30 14:09 Mysql_backup_all_2018-09-30_140917.tar.gz
-rw-r--r-- 1 root root 1720238 Sep 28 03:05 Mysql_backup_nomessage_2018-09-28_030501.tar.gz
-rw-r--r-- 1 root root 1719870 Sep 30 03:05 Mysql_backup_nomessage_2018-09-30_030502.tar.gz
-rw-r--r-- 1 root root 421307 Sep 30 15:24 mysql_manager.info
-rw-r--r-- 1 root root 22358 Sep 30 15:24 mysql_manager.log
-rw-r--r-- 1 root root 2058 Sep 30 15:24 result.info
- 还原常用操作:
- 指定还原文件的绝对路径:
- /data/data_center/mysql_backup/Mysql_backup_all_2018-09-30_140917.tar.gz
// 执行还原脚本 手动还原 全库还原
[root@Linkdood mysql_backup]# /data/linkdood/im/bin/mysql_manager_V2.0.sh --restore --all
-- Welcome Use Mysql_Manager --
// 确认MySQL配置文件目录位置
Please Input Mysql Config File [Default:/data/linkdood/im/vrv/mysql/my.cnf]:
// 确认还原备份文件,若手动指定还原文件需要绝对路径
Please Input Mysql Backup File [Default:/data/data_center/mysql_backup/Mysql_backup_nomessage_2018-09-30_141219.tar.gz]: /data/data_center/mysql_backup/Mysql_backup_all_2018-09-30_140917.tar.gz
1.Mysql Config File Is Normative. [OK]
2.Mysql Backup File Is Normative. [OK]
3.Mysql Move Old-Data Is Success. [OK]
4.Mysql Backup Unzip Is Success. [OK]
5.Mysql Restore Data Is Success. [OK]
-- Mysql Server Start Success --
------
// 执行脚本还原 手动还原 不还原消息数据库 IM_MESSAGESTORAGE
[root@Linkdood mysql_backup]# /data/linkdood/im/bin/mysql_manager_V2.0.sh --restore --mess
-- Welcome Use Mysql_Manager --
Please Input Mysql Config File [Default:/data/linkdood/im/vrv/mysql/my.cnf]:
Please Input Mysql Backup File [Default:/data/data_center/mysql_backup/Mysql_backup_nomessage_2018-09-30_141219.tar.gz]: /data/data_center/mysql_backup/Mysql_backup_nomessage_2018-09-30_141219.tar.gz
1.Mysql Config File Is Normative. [OK]
2.Mysql Backup File Is Normative. [OK]
3.Mysql Move Old-Data Is Success. [OK]
4.Mysql Backup Unzip Is Success. [OK]
5.Mysql Restore Data Is Success. [OK]
-- Mysql Server Start Success --
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于