备份MySQL shell脚本
00 分钟
2022-8-26
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
\#!bin/sh<br> db_user=<br> db_passwd=<br> db_name=<br>
\# the directory for story your backup file.you shall change this dir<br> backup_dir="备份文件路径"<br>
\# date format for backup file (dd-mm-yyyy)<br> \# 以时间命名备份数据库 time="$(date +"%Y%m%d%H%M%S")"<br> createAt=date +%Y-%m-%d-%H:%M:%S<br> mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"_"$time.sql"<br>
cd /www/wwwroot/blog //Git操作<br> git add .<br> git commit -m $time<br> git push<br>
\#删除七天之前的备份<br> find $backup_dir -name $db_name"*.sql" -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1
\#删除一分钟之前的备份<br> \#find $backup_dir -name $db_name"*.sql" -type f -mmin +1 -exec rm -rf {} \; > /dev/null 2>&1

评论