Can I restore accidentally deleted crontab entries?
I was trying to create a cron on the production environment and so I created crontab.txt
file with my new cron command and ran crontab crontab.txt
file but instead of appending to existing cron job list, it accidently deleted all crons and now I only have my cron on prod.
How can I retreive earlier crons that were set and append my new cron to it.
Thanks.
Would it add insult to injury to suggest restoring your crontab from backups?
First of all: Always make backups!
Second:
You can try to have a look at /var/log/cron and build your crontab again.
- Have a look at the logfile
- Take the first command and do
grep commandname1 /var/log/cron
- Figure out the systematic behind the times the command was run
- put that entry to your new crontab
- execute
cat /var/log/cron | grep -v commandname1
- Take the next command and grep for it
- Figure out the systematic behind the times the second command was run
- put that entry to your new crontab
- execute
cat /var/log/cron | grep -v commandname1 | grep -v commandname2
- Repeat until you covered all commands
Now you should also execute the grep on older cronlogs to find out jobs that might be run only once in a month.