实现MySQL定时数据备份的操作步骤

php中文网
发布: 2016-06-07 16:09:43
原创
1356人浏览过

以下的文章主要介绍的是MySQL定时数据备份的具体操作,如果你对MySQL定时数据备份相关的实际操作有兴趣的话,你就可以对以下的文章点击观看了。同时文章也有更多相关推荐 可以根据自己的需求自己改写: MySQL定时数据备份;运行Java代码 bashmysql_backup.sh

Ex驾校预约小程序
Ex驾校预约小程序

传统驾校预约方式步骤繁琐,效率低下,随着移动互联网科技和5G的革新,驾校考试领域迫切需要更加简洁、高效的预约方式,便捷人们的生活。因此设计基于微信小程序的驾校预约系统,改进传统驾校预约方式,实现高效的驾校学校预约。 采用腾讯提供的小程序云开发解决方案,无须服务器和域名。驾校预约管理:开始/截止时间/人数均可灵活设置,可以自定义客户预约填写的数据项驾校预约凭证:支持线下到场后校验签到/核销/二维码自

Ex驾校预约小程序 0
查看详情 Ex驾校预约小程序

以下的文章主要介绍的是mysql定时数据备份的具体操作,如果你对mysql定时数据备份相关的实际操作有兴趣的话,你就可以对以下的文章点击观看了。同时文章也有更多相关推荐 可以根据自己的需求自己改写:

MySQL定时数据备份;运行Java代码

<ol class="dp-xml"><li class="alt"><span><span>bash mysql_backup.sh   </span></span></li><li><span>bash mysql_backup.sh  </span></li><li class="alt"><span>Java代码   </span></li><li><span>!/bin/bash   </span></li><li class="alt"><span>This is a ShellScript For Auto DB Backup   </span></li><li><span>Powered by liuzheng   </span></li></ol>
登录后复制

系统变量定义

<ol class="dp-xml"><li class="alt"><span><span class="attribute">DBName</span><span>=</span><span class="attribute-value">Bulletin_production</span><span>   </span></span></li><li><span class="attribute">DBUser</span><span>=</span><span class="attribute-value">root</span><span>   </span></li><li class="alt"><span class="attribute">DBPasswd</span><span>=   </span></li><li><span class="attribute-value">BackupPath</span><span>=/home/worker/mysql_backup/   </span></li><li class="alt"><span class="attribute">NewFile</span><span>="$BackupPath"</span><span class="attribute-value">db</span><span>$(date +%y%m%d).tar.gz   </span></li><li><span class="attribute">DumpFile</span><span>="$BackupPath"</span><span class="attribute-value">db</span><span>$(date +%y%m%d).sql   </span></li><li class="alt"><span class="attribute">OldFile</span><span>="$BackupPath"</span><span class="attribute-value">db</span><span>$(date +%y%m%d </span><span class="attribute">--date</span><span>=</span><span class="attribute-value">'1 days ago'</span><span>).tar.gz  </span></li></ol>
登录后复制

MySQL定时数据备份:创建备份文件

<ol class="dp-xml"><li class="alt"><span><span>if [ ! -d $BackupPath ]; then   </span></span></li><li><span>mkdir $BackupPath   </span></li><li class="alt"><span>fi   </span></li><li><span>echo "---------------------------"   </span></li><li class="alt"><span>echo $(date +"%y-%m-%d %H:%M:%S")   </span></li><li><span>echo "---------------------------"  </span></li></ol>
登录后复制

删除历史文件

<ol class="dp-xml"><li class="alt"><span><span>if [ -f $OldFile ]; then   </span></span></li><li><span>rm -f $OldFile </span><span class="tag">></span><span class="tag">></span><span> $LogFile   </span></li><li class="alt"><span>echo "[$OldFile]Delete Old File Success!"   </span></li><li><span>else   </span></li><li class="alt"><span>echo "not exist old file!"   </span></li><li><span>fi  </span></li></ol>
登录后复制

新文件

<ol class="dp-xml"><li class="alt"><span><span>if [ -f $NewFile ]; then   </span></span></li><li><span>echo "[$NewFile] The Backup File is exists,Can't Backup! "   </span></li><li class="alt"><span>else   </span></li><li><span>mysqldump -u $DBUser $DBName </span><span class="tag">></span><span> $DumpFile   </span></li><li class="alt"><span>tar czvf $NewFile $DumpFile   </span></li><li><span>rm -rf $DumpFile   </span></li><li class="alt"><span>echo "[$NewFile]Backup Success!"   </span></li><li><span>fi   </span></li><li class="alt"><span>!/bin/bash  </span></li><li><span>This is a ShellScript For Auto DB Backup  </span></li><li class="alt"><span>Powered by liuzheng  </span></li></ol>
登录后复制

系统变量定义

<ol class="dp-xml"><li class="alt"><span><span class="attribute">DBName</span><span>=</span><span class="attribute-value">Bulletin_production</span><span> </span></span></li><li><span class="attribute">DBUser</span><span>=</span><span class="attribute-value">root</span><span> </span></li><li class="alt"><span class="attribute">DBPasswd</span><span>=  </span></li><li><span class="attribute-value">BackupPath</span><span>=/home/worker/mysql_backup/  </span></li><li class="alt"><span class="attribute">NewFile</span><span>="$BackupPath"</span><span class="attribute-value">db</span><span>$(date +%y%m%d).tar.gz  </span></li><li><span class="attribute">DumpFile</span><span>="$BackupPath"</span><span class="attribute-value">db</span><span>$(date +%y%m%d).sql  </span></li><li class="alt"><span class="attribute">OldFile</span><span>="$BackupPath"</span><span class="attribute-value">db</span><span>$(date +%y%m%d </span><span class="attribute">--date</span><span>=</span><span class="attribute-value">'1 days ago'</span><span>).tar.gz  </span></li></ol>
登录后复制

MySQL定时数据备份创建备份文件

<ol class="dp-xml"><li class="alt"><span><span>if [ ! -d $BackupPath ]; then  </span></span></li><li><span>mkdir $BackupPath  </span></li><li class="alt"><span>fi  </span></li><li><span>echo "---------------------------"  </span></li><li class="alt"><span>echo $(date +"%y-%m-%d %H:%M:%S")   </span></li><li><span>echo "---------------------------"   </span></li></ol>
登录后复制

删除历史文件

<ol class="dp-xml"><li class="alt"><span><span>if [ -f $OldFile ]; then  </span></span></li><li><span>rm -f $OldFile </span><span class="tag">></span><span class="tag">></span><span> $LogFile  </span></li><li class="alt"><span>echo "[$OldFile]Delete Old File Success!"  </span></li><li><span>else  </span></li><li class="alt"><span>echo "not exist old file!"  </span></li><li><span>fi </span></li></ol>
登录后复制

新文件

<ol class="dp-xml"><li class="alt"><span><span>if [ -f $NewFile ]; then  </span></span></li><li><span>echo "[$NewFile] The Backup File is exists,Can't Backup! "  </span></li><li class="alt"><span>else  </span></li><li><span>mysqldump -u $DBUser $DBName </span><span class="tag">></span><span> $DumpFile  </span></li><li class="alt"><span>tar czvf $NewFile $DumpFile   </span></li><li><span>rm -rf $DumpFile   </span></li><li class="alt"><span>echo "[$NewFile]Backup Success!"  </span></li><li><span>fi </span></li></ol>
登录后复制

声明:JavaEye文章版
 


相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号