程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 每日備份shell腳本

每日備份shell腳本

編輯:MySQL綜合教程

每日備份shell腳本


每天固定時間用mysqldump 備份mysql數據。

#!/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 +'%Y-%m-%d %H:%M:%S')" >> "$backup_log"

參考

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved