首页 > 代码库 > 常用的shell(备份数据库、备份网站、切割访问日志)

常用的shell(备份数据库、备份网站、切割访问日志)

备份网站程序

#!/bin/bash
/bin/tar czf /mnt/backup_website/web_$(date +%Y%m%d_%H%M%S).gz.tar /mnt/wwwroot/web
cd /mnt/backup_website
find . -mtime +1 -name "*20[1-9][3-9]*" | xargs rm -f
exit 0

 

备份数据库

#!/bin/bash
/bin/tar czf /mnt/backup_website/newjiagu_$(date +%Y%m%d_%H%M%S).gz.tar /mnt/wwwroot/newjiagu
cd /mnt/backup_website
find . -mtime +1 -name "*20[1-9][3-9]*" | xargs rm -f
exit 0
[root@iZ23c93ivn4Z shell]# cat backup_database.sh 
#!/bin/bash
mysqldump -uroot -proot web > /home/database/web_$(date +%Y%m%d_%H%M%S).sql
cd /home/database
find . -mtime +7 -name "*20[1-9][3-9]*" | xargs rm -f
exit 0

 

切割日志

#!/bin/bash
LOGS_PATH=/home/wwwlogs
YESTERDAY=$(date -d "yesterday" +%Y%m%d)
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/${YESTERDAY}.log
kill -USR1 `ps axu | grep "nginx: master process" | grep -v grep | awk {print $2}`
cd ${LOGS_PATH}
find . -mtime +7 -name "*20[1-9][3-9]*" | xargs rm -f

exit 0

 

常用的shell(备份数据库、备份网站、切割访问日志)