欢迎来到天天文库
浏览记录
ID:52290551
大小:14.87 KB
页数:3页
时间:2020-03-26
《Linux网络操作系统配置与管理 项目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_passwdismysqlpasswo
2、rd#db_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"
3、MYSQLDUMP="/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"$
4、backup_dir/backup.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-
6、rf"$backup_dir/backup.5"#rotatebackupdirectoryforintin43210doif(test-d"$backup_dir"/backup."$int")thennext_int=`expr$int+1`$MV"$backup_dir"/backup."$int""$backup_dir"/backup."$next_int"fidoneexit0;
此文档下载收益归作者所有