所以,就脚本而言,我是一个完全的新手,就像这是我的第一个。我创建了以下脚本:
# This simply declares which states we are using to create tarballs from
for blah in ar ky ms ny;
do
# This will go into each tomcat-state directory and create a tarball in /home/ec-user for all files older than 90 days
find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 | xargs tar -cvzf /home/ec2-user/archive-${blah}.tar.gz;
# This creates a master archive tarball containing all the archive-state.tar.gz files
tar -cvzf /home/ec2-user/ebd-log-archives.tar.gz /home/ec2-user/archive-${blah}.tar;
# Since in step one, we archives all files older than 90 days, this step removes them.
# find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 -exec rm {} \;
# And since we have the master archive file, this removes the archive-state files
rm /home/ec2-user/archive-${blah}.tar.gz;
done
我已经注释掉删除日志以进行测试。
问题是,当我得到 master tarball 时,里面只有 NY,或者我把哪个放在循环中的最后一个(我测试了这个以确保它不仅仅是一个奇怪的 NY 东西)
不确定发生了什么,我在该服务器上的措辞上针对与此类似的旧脚本进行了测试,并且该脚本运行良好。
编辑:感谢您的回复,我已将脚本更新为:
# This creates the master tarball we will be using
tar -cvzf /home/ec2-user/ebd-log-archives.tar.gz
# This simply declares which states we are using to create tarballs from
for blah in ar ky ms ny;
do
# This will go into each tomcat-state directory and create a tarball in /home/ec-user for all files older than 90 days
find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 | xargs tar -cvzf /home/ec2-user/archive-${blah}.tar.gz;
# This creates a master archive tarball containing all the archive-state.tar.gz files
tar -rvzf /home/ec2-user/ebd-log-archives.tar.gz /home/ec2-user/archive-${blah}.tar;
# Since in step one, we archives all files older than 90 days, this step removes them.
# find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 -exec rm {} \;
# And since we have the master archive file, this removes the archive-state files
rm /home/ec2-user/archive-${blah}.tar.gz;
done
我会尝试运行这个并发布更新