Home > Database > Mysql Tutorial > body text

每日备份shell脚本_MySQL

WBOY
Release: 2016-06-01 13:00:09
Original
961 people have browsed it

每天固定时间用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>
Copy after login

参考

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!