[英]How do i backup all files listed in crontab
I am trying to backup the crontab entries structure and files running under crontab. 我正在尝试备份crontab条目结构和在crontab下运行的文件。
But I am stuck with how do i search files in crontab -l
and copy the scripts running under it. 但是我对如何在
crontab -l
搜索文件并复制在其下运行的脚本感到困惑。
My possible ways 我可能的方法
I have listed 我已经列出
crontab -l > test.txt
cat test.txt
But how can I search the files after listing. 但是列出后如何搜索文件。
My entries are like: 我的输入如下:
# daily pingback report
30 1 * * * php /var/opx/cron-script/daily-email-reports/pingback_report.php | curl --data-binary @- https://pxc.com/email/send
# --------------------------------------------------------------------------------------------------
# daily jobs 02+ hours
# --------------------------------------------------------------------------------------------------
# daily Failed Device Search
0 2 * * * /var/opx/cron-script/failed_device_search.sh
# daily Device Not Detected (we are not getting any of these, so commenting out)
# 5 2 * * * /var/opx/cron-script/device_not_detected.sh
# daily Failed App Search (we are not getting any of these, so commenting out)
# 10 2 * * * /var/opx/cron-script/failed_app_search.sh
# daily oss event report (uncomment when dev db issue is fixed)
10 3 * * * /var/opx/cron-script/event-analysis/daily-oss-event-report
# Copy tomcat logs from s1 and s2 , compress them and move to S3 storage
#30 21 * * * /var/opx/cron-script/log_backup.sh
I want to copy scripts running in these entries. 我想复制在这些条目中运行的脚本。
Try this: 尝试这个:
for part in $(sed 's/#.*//' test.txt | while read t1 t2 t3 t4 t5 main; do echo $main; done); do
echo $part
done | grep / | grep -v ://
For your example, this prints: 对于您的示例,将输出:
/var/opx/cron-script/daily-email-reports/pingback_report.php
/var/opx/cron-script/failed_device_search.sh
/var/opx/cron-script/event-analysis/daily-oss-event-report
I'm not proud of it, but it is fairly portable shell, and seems to work for the cases you've given. 我不为此感到骄傲,但它是可移植的外壳,似乎可以满足您的要求。 You might need a smarter parser for more complex cases, or to handle more obscure words that may exist in your crontabs.
对于更复杂的情况,或者为了处理crontab中可能存在的更晦涩的单词,您可能需要一个更智能的解析器。
This is my script useful if any one want to backup cron's 如果有人想备份cron的文件,这对我的脚本很有用
#!/bin/bash
#This Script use for backup of crontab files and entries
#Modify as per your need
mkdir -p /mnt/cron_backups
for part in $(crontab -l | grep -v "clientmqueue" | sed 's/#.*//' | while read t1 t2 t3 t4 t5 main; do echo $main; done); do
echo $part
done | grep / | grep -v :// | while read -r row
do
scp $row /mnt/cron_backups/
crontab -l > /mnt/cron_backups/backup_cron.txt
tar -cvzf /mnt/cron_backups.tar.gz /mnt/cron_backups/
done
# grep -v is used for ignoring specific script with specific words or character
Thanks to John.... 多亏约翰...。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.