大部分的日记切割和备份机制的都是一样:下面是nginx的日记切割脚本
#!/bin/bash
logpath = ‘/home/nginx/log‘
nglogs = ‘/opt/nginx/logs
mkdir -p $logpath/$(date +%Y)/$(date +%m)
mv $nglogs/access.log $logpath/$(date +%Y)/$(date +%m)/access.$(date +%Y%m%d).log
mv $nglogs/error.log $logpath/$(date +%Y)/$(date +%m)/error.$(date +%Y%m%d).log
kill -USR1 ‘cat /opt/nginx/logs/nginx.pid
kill -USR ‘cat /opt/nginx/logs/nginx.pid’ 通过nginx的信号USR实现日记的自动切换方案
mysql定期备份的方案:
#!/bin/sh
echo ‘start backup db ...‘
DM=`date +%a`
if [ -f /opt/backup/xxx.$DM.dmp ]; then
mv /opt/backup/xxx.dmp mv /opt/backup/xxx.dmp.old
fi
mysqldump -h ipaddress --password=xxxx > /opt/backup/xxx.dmp
if [ $? -eq 0 -a -f /home/smecloud/db_backup/kdrive.$DM.dmp.old ]; then
rm /home/smecloud/db_backup/kdrive.$DM.dmp.old
echo ‘backup xxx ok....‘
fi
echo ‘end backup db ...‘
date的常用参数:
date +%Y 年
date +%m 月
date +%d 日
date +%a 星期