首页 >数据库 >mysql教程 >每日备份shell脚本_MySQL

每日备份shell脚本_MySQL

WBOY
WBOY原创
2016-06-01 13:00:09996浏览

每天固定时间用mysqldump 备份mysql数据。

<code class="hljs bash">#!/bin/bash
#每天早上4点, mysql备份数据 orangleliu
#chmod 700 backup.sh
#crontab -e
#0 4 * * * /home/erya/run/moniter/mysql_backup.sh

user="radius"
password=""
host="localhost"
db_name="radius"

#backup directory 
base_dir="/home/backup"
backup_log="${base_dir}/mysql_backup.log"
backup_path=${base_dir}

#file info
date=$(date +"%Y-%m-%d")
filename=$backup_path/$db_name-$date.sql.gz
umask 177

#back up 
mysqldump --user=$user --password=$password --host=$host $db_name | gzip > $filename
#Delete files older than 10 days
find $backup_path/* -mtime +10 -exec rm {} \;
echo "backup finished at $(date +&#39;%Y-%m-%d %H:%M:%S&#39;)" >> "$backup_log"</code>

参考

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn