Rumah > pangkalan data > tutorial mysql > linux定时备份MySQL数据库并删除七天前的备份文件 (2014

linux定时备份MySQL数据库并删除七天前的备份文件 (2014

WBOY
Lepaskan: 2016-06-07 15:53:10
asal
1298 orang telah melayarinya

1、创建备份文件夹 #cd /bak #mkdir mysqlbak 2、编写运行脚本 #nano -w /usr/sbin/bakmysql.sh 注:如使用 nano 编辑此代码需在每行尾添加 '' 或 ';' 连接符,否则生成的文件名末尾字符为乱码 代码: #!/bin/bash # Name:bakmysql.sh # This is a ShellScri

1、创建备份文件夹
<p><span><span>#cd /bak</span>
<span>#mkdir mysqlbak</span></span></p>
Salin selepas log masuk

2、编写运行脚本
<p><span><span>#nano -w /usr/sbin/bakmysql.sh</span>
<span>注:如使用</span><span>nano</span><span>编辑此代码需在每行尾添加</span><span>'&&'</span><span>或</span><span>';'</span><span>连接符,否则生成的文件名末尾字符为乱码</span>
</span></p>
Salin selepas log masuk
代码:
<p><span><span>#!/bin/bash</span>
<span># Name:bakmysql.sh</span>
<span># This is a ShellScript For Auto DB Backup and Delete old Backup</span>
<span>#</span>
<span>backupdir</span><span>=</span><span>/bak/</span><span>mysqlbak</span>
<span>time</span><span>=</span><span>`date +%Y%m%d%H`</span>
<span>mysql_bin_dir</span><span>/</span><span>mysqldump </span><span>-</span><span>u user </span><span>-</span><span>ppassword dataname1 </span><span>|</span><span> gzip </span><span>></span><span> $backupdir</span><span>/</span><span>name1$time</span><span>.</span><span>sql</span><span>.</span><span>gz</span>
<span>mysql_bin_dir</span><span>/</span><span>mysqldump </span><span>-</span><span>u user </span><span>-</span><span>ppassword dataname2 </span><span>|</span><span> gzip </span><span>></span><span> $backupdir</span><span>/</span><span>name2$time</span><span>.</span><span>sql</span><span>.</span><span>gz</span>
<span>#</span>
<span>find $backupdir </span><span>-</span><span>name </span><span>"name_*.sql.gz"</span><span>-</span><span>type f </span><span>-</span><span>mtime </span><span>+</span><span>5</span><span>-</span><span>exec</span><span> rm </span><span>{}</span><span> \; </span><span>></span><span>/dev/</span><span>null</span><span>2</span><span>>&</span><span>1</span>
</span></p>
Salin selepas log masuk
保存退出
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