当前位置: 移动技术网 > IT编程>数据库>Mysql > 定时备份mysql, 定时切割nginx access log的方法

定时备份mysql, 定时切割nginx access log的方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

青川人事网,菲茨的气息,野兔电影

定时备份mysql
放入 /etc/cron.hourly/
复制代码 代码如下:

#!/bin/bash
dump=/usr/local/webserver/mysql/bin/mysqldump
out_dir=/data1/backup/
db_name=数据库名
db_user=数据库用户
db_pass=数据库密码
#how much days backup most
days=3
#12 hours ago
mins=720
#core of script
cd $out_dir
date=`date +%y-%m-%d-%h`
out_sql="$date.sql"
tar_sql="db-$date.tar.gz"
$dump --default-character-set=utf8 --opt -u$db_user -p$db_pass $db_name > $out_sql
tar -czf $tar_sql ./$out_sql
rm -f $out_sql

find ./ -name "db*" -type f -mmin +$mins -exec rm {} \;
#find ./ -name "db*" -type f -mtime +$days -exec rm {} \;
exit 0;

定时切割nginx access.log,只保留3天前的记录
放入 /etc/cron.hourly/
复制代码 代码如下:

#!/bin/bash
# this script run at 00:00

# the nginx logs path
#logs_path="/usr/local/webserver/nginx/logs/"
logs_path="/data1/logs/"
#how much days backup most
days=3

#core of script
cd $logs_path
date=`date +%y-%m-%d-%h`
src_file="access.log"
tar_file="access-$date.tar.gz"
tar -czf $tar_file $src_file
rm -f $src_file

find ./ -name "access-*" -type f -mtime +$days -exec rm {} \;
kill -usr1 `cat /usr/local/webserver/nginx/nginx.pid`
exit 0;

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网