欢迎来到天天文库
浏览记录
ID:35975630
大小:17.41 KB
页数:3页
时间:2019-04-29
《新增资源及索引表-王辉静项目2拓展资源_linux定期自动备份mysql的shell脚本.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、linux定期自动备份mysql的shell脚本数据无价,及时备份安全起见,直接用Root执行的:/root/mysql_backup.sh#everyday3:00AMexecutedatabasebackup30***/root/mysql_backup.sh以下是自动自动备份shell,只保留最新5天#!/bin/sh#mysql_backup.sh:backupmysqldatabasesandkeepnewest5daysbackup.##db_userismysqlusername#db_passwdismysqlpassword#db
2、_hostismysqlhost#—————————–db_user="root"db_passwd="zhoz.com"db_host="localhost"#thedirectoryforstoryyourbackupfile.backup_dir="/home/zhozdbbackup"#dateformatforbackupfile(dd-mm-yyyy)time="$(date+"%d-%m-%Y")"#mysql,mysqldumpandsomeotherbin'spathMYSQL="/usr/bin/mysql"MYSQLDUMP=
3、"/usr/bin/mysqldump"MKDIR="/bin/mkdir"RM="/bin/rm"MV="/bin/mv"GZIP="/bin/gzip"#checkthedirectoryforstorebackupiswriteabletest!-w$backup_dir&&echo"Error:$backup_dirisun-writeable."&&exit0#thedirectoryforstorythenewestbackuptest!-d"$backup_dir/backup.0/"&&$MKDIR"$backup_dir/back
4、up.0/"#getalldatabasesall_db="$($MYSQL-u$db_user-h$db_host-p$db_passwd-Bse'showdatabases')"fordbin$all_dbdo$MYSQLDUMP-u$db_user-h$db_host-p$db_passwd$db
5、$GZIP-9>"$backup_dir/backup.0/$time.$db.gz"done#deletetheoldestbackuptest-d"$backup_dir/backup.5/"&&$RM-rf"$backup_dir/backu
6、p.5"#rotatebackupdirectoryforintin43210doif(test-d"$backup_dir"/backup."$int")thennext_int=`expr$int+1`$MV"$backup_dir"/backup."$int""$backup_dir"/backup."$next_int"fidoneexit0;
此文档下载收益归作者所有