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.

  1. Have a look at the logfile
  2. Take the first command and do grep commandname1 /var/log/cron
  3. Figure out the systematic behind the times the command was run
  4. put that entry to your new crontab
  5. execute cat /var/log/cron | grep -v commandname1
  6. Take the next command and grep for it
  7. Figure out the systematic behind the times the second command was run
  8. put that entry to your new crontab
  9. execute cat /var/log/cron | grep -v commandname1 | grep -v commandname2
  10. 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.