mysql备份脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
#定时删除过期备份
back_path=/home/data/mysql_backup
cd $back_path
current_date=`date +%Y%m%d`
current_date_stamp=`date -d "$current_date" +%s`

dele_date_stamp=$(($current_date_stamp-2592000))
echo $dele_date_stamp
echo "************"
for filename in `ls $back_path `;
do
file_time_stamp=`date -d "$filename" +%s`
if [ $file_time_stamp -lt $dele_date_stamp ] ; then
rm -rf $back_path/$filename
echo "delete $filename"
fi
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
#定时备份数据库
USER=root
export password=123456
back_path=/home/data/mysql_backup
date=`date +%Y%m%d`
filename=`date +%Y%m%d-%H`
mkdir -p $back_path/$date >/dev/null 2>&1
mysqldump -u$USER -p$password -A --opt -F --single-transaction
> $back_path/$date/$filename.sql


# 0 */1 * * * /root/mysql_dump.sh >/dev/null 2>&1
0 */1 * * * /root/back_script/mysql_dump.sh >/dev/null 2>&1
0 */1 * * * /root/back_script/delete_expire_file.sh >/dev/null 2>&1
坚持原创技术分享,您的支持将鼓励我继续创作!