mysql 定时数据备份
可以根据自己的需求自己改写:)
运行bash mysql_backup.sh
#!/bin/bash #This is a ShellScript For Auto DB Backup #Powered by liuzheng #系统变量定义 DBName=Bulletin_production DBUser=root DBPasswd= BackupPath=/home/worker/mysql_backup/ NewFile="$BackupPath"db$(date +%y%m%d).tar.gz DumpFile="$BackupPath"db$(date +%y%m%d).sql OldFile="$BackupPath"db$(date +%y%m%d --date='1 days ago').tar.gz #创建备份文件 if [ ! -d $BackupPath ]; then mkdir $BackupPath fi echo "---------------------------" echo $(date +"%y-%m-%d %H:%M:%S") echo "---------------------------" #删除历史文件 if [ -f $OldFile ]; then rm -f $OldFile >> $LogFile echo "[$OldFile]Delete Old File Success!" else echo "not exist old file!" fi #新文件 if [ -f $NewFile ]; then echo "[$NewFile] The Backup File is exists,Can't Backup! " else mysqldump -u $DBUser $DBName > $DumpFile tar czvf $NewFile $DumpFile rm -rf $DumpFile echo "[$NewFile]Backup Success!" fi
相关推荐
九天银河技术 2020-11-11
tufeiax 2020-09-03
zhangjie 2020-11-11
Crazyshark 2020-11-13
步知道 2020-10-27
李轮清 2020-09-15
85251846 2020-09-14
wangpaiyonghu 2020-06-28
jackalwb 2020-06-14
yhljxy 2020-06-14
myveer 2020-06-14
xiaobaif 2020-06-14
klarclm 2020-06-13
songshijiazuaa 2020-06-13
TMD咯MySQL 2020-06-12
archive 2020-06-12
清风徐来水波不兴 2020-06-09