首页 > 数据库 > mysql教程 > Shell简单全备mysql脚本案例_MySQL

Shell简单全备mysql脚本案例_MySQL

WBOY
发布: 2016-06-01 13:47:56
原创
802 人浏览过

bitsCN.com
Shell简单全备mysql脚本案例 [root@cacti mysql]# cat backup.sh #!/bin/sh   #created by taiyang#2012-9-16#function:backup mysql database #set local variablesDBname=backupBackupPath=/mysqlbak/mysqlbak/DumpFile=${BackupPath}${DBname}`date +%y%m%d_%H%M%S`.bak v_username='root'if [ $v_username != 'root' ];thenecho "ERROR:the script must be run as mysql"exit 1fi   echo "backup database path:$DumpFile"echo "------------------------------" dateecho "****************************"echo "backup database begin"echo "****************************" mysqldump -uroot -proot --opt $DBname > $DumpFile echo "****************************" echo "backup database end"echo "****************************"date #delete backups before 5 daysfind $BackupPath -ctime +5 -name '*.bak' -exec rm {} /;[root@cacti mysql]#    从备份脚本当中进行还原数据库的信息;
 [root@cacti mysqlbak]# lsbackup120928_114307.bak  backup120928_114556.bak  cacti120928_105558.bakbackup120928_114309.bak  cacti120928_105044.bak   cacti120928_110443.bakbackup120928_114310.bak  cacti120928_105155.bak   cacti120928_110448.bakbackup120928_114311.bak  cacti120928_105457.bak   cacti120928_110449.bak[root@cacti mysqlbak]# pwd /mysqlbak/mysqlbak[root@cacti mysqlbak]#[root@cacti ~]# mysql -hlocalhost -uroot -proot backup /mysqlbak/backup120928_114556.bak 
 [root@cacti ~]# mysql -uroot -prootWelcome to the MySQL monitor.  Commands end with ; or /g.Your MySQL connection id is 860Server version: 5.0.22-log Type 'help;' or '/h' for help. Type '/c' to clear the buffer.   mysql> use backupDatabase changedmysql> show tables;+------------------+| Tables_in_backup |+------------------+| b                | | t                | +------------------+2 rows in set (0.00 sec) mysql> exitBye
  bitsCN.com

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板