2018-09-18发表2023-03-17更新阿里云2 分钟读完 (大约248个字)阿里云日志文件备份 密钥访问 123* 准备备份日志的服务器ssh-keygen -t rsa -P ''ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.2.250 脚本 12345678910111213141516171819202122vim /root/sh #!/bin/bash # nettylog=/apps/echarging/log/nettylog processorlog=/apps/echarging/log/processor_1_log nettyback=/home/nettylog processorback=/home/processorlog1 nettybackR=/home/logbackup/nettylog processorbackR=/home/logbackup/processorlog1 cd $nettylog find ./ -name netty.log-`date -d yesterday +%F`."*".log -exec cp {} $nettyback \; tar -zcf $nettyback/netty-log.`date -d yesterday +%F`.tar.gz $nettyback/*.log scp $nettyback/netty-log.`date -d yesterday +%F`.tar.gz 192.168.2.250:$nettybackR rm -rf $nettyback/* cd $processorlog find ./ -name processor_1.log-`date -d yesterday +%F`."*".log -exec cp {} $processorback \; tar -zcf $processorback/processor_1.log-`date -d yesterday +%F`.tar.gz $processorback/*.log scp $processorback/processor_1.log-`date -d yesterday +%F`.tar.gz 192.168.2.250:$processorbackR rm -rf $processorback/*#本打算使用find ./ -name processor_1.log-`date -d yesterday +%F`."*".log -exec tar -zcf processor_log-`date -d yesterday +%F`.tar.gz {} \;命令来直接打包,但测试发现打出的包中只有find查到的最后一个文件。所以将命令改为了两条,先将找到的文件移到一个临时目录,再打包发送。 定时任务 123crontab -e * 4 * * * /bin/bash /root/sh/scplog.shcrontab -l 阿里云日志文件备份https://python0.netlify.app/2018/09/18/阿里云日志文件备份/作者John Doe发布于2018-09-18更新于2023-03-17许可协议#阿里云