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

WBOY
Lepaskan: 2016-06-07 16:09:43
asal
1155 orang telah melayarinya

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

以下的文章主要介绍的是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>
Salin selepas log masuk

系统变量定义

<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>
Salin selepas log masuk

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>
Salin selepas log masuk

删除历史文件

<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>
Salin selepas log masuk

新文件

<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>
Salin selepas log masuk

系统变量定义

<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>
Salin selepas log masuk

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>
Salin selepas log masuk

删除历史文件

<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>
Salin selepas log masuk

新文件

<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>
Salin selepas log masuk

声明:JavaEye文章版
 


sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan