shell定期转移日志文件到云盘并定期删除云盘文件

shell 脚本定期处理如下:

cat  /home/backup/logs_delete.sh

#!/bin/bash


/bin/find /data/logs/nginx/ -name "*.log*" -mtime +4 -type f -print0 |xargs -0 mv -t /mnt/logs/nginx/
/bin/find /data/logs/uwsgi/ -name "*.log*" -mtime +4 -type f -print0 |xargs -0 mv -t /mnt/logs/uwsgi/
/bin/find /data/logs/uwsgi/statistics/ -name "*.log*" -mtime +4 -type f -print0 |xargs -0 mv -t /mnt/logs/uwsgi/statistics/

/bin/find /mnt/logs/nginx/ -name "*.log*" -mtime +30 -type f|xargs rm -rf
/bin/find /mnt/logs/uwsgi/ -name "*.log*" -mtime +30 -type f|xargs rm -rf
/bin/find /mnt/logs/uwsgi/statistics/ -name "*.log*" -mtime +30 -type f|xargs rm -rf

 

 

查看执行结果

tree  /mnt/logs/uwsgi/

/mnt/logs/uwsgi/
── access.log-20180507
── statistics
│   └── access.log-20180507


tree /mnt/logs/nginx/
/mnt/logs/nginx/
└── info_access_2018-05-07.log

 

写入定时任务,每天做日志处理

crontab -l

0 4 * * * /bin/bash /home/backup/logs_delete.sh

 

参考文章:https://unix.stackexchange.com/questions/83711/moving-files-with-find-xargs-target-is-not-a-directory

posted @ 2018-05-01 10:31  Oops!#  阅读(265)  评论(0编辑  收藏  举报