Monthly Archives: September 2015

Accidentally deleted cron jobs :( How to recover?

I don’t know exactly, why on earth crontab default key for edit(-e) and remove(-r) was designed sitting next to each other. Accidentally all cron jobs may be removed by entering -r, while trying to edit. So be careful!

How to recover:

  1. If you have backups, that’s great, restore from there.
  2. If no backup, find the cron jobs from log file using command:$ cat /var/log/cron | grep -v your_command.
  3. Repeatedly recover commands from log file.

Future Proof:

Always maintain a file containing all crontab entries and keep it in code repository(e.g git). Then at any time, you can get from repo and re-store in unix.

Advertisements