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

时间:2025-03-14 08:07:19
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-
── statistics
│   └── access.log- tree /mnt/logs/nginx/
/mnt/logs/nginx/
└── info_access_2018--.log
写入定时任务,每天做日志处理

crontab -l

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

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