Crontab Deleted by Mistake: How to Recover from 'crontab -r'

Read the full article: Crontab Deleted by Mistake: How to Recover from ‘crontab -r’

Years ago, I learned the power of command-line mistakes the truly hard way when I ran the mother of all destructive commands: rm -rf. I refuse to believe (but can’t remember if it was actually rm -rf / or maybe I instead nuked a system directory) but it was equally bad. Let’s just say it… continue reading.
3 Likes

So that took an hour out of my morning! Has anyone else had this happen to them before? What’s the worst oops moment that you’ve had? Any suggestions or tips?

uh that’s bad.
I think timeshift is a good way to protect yourself against this.

My worst mistake?
In the early 2000s I bought a DVD burner and wanted to back up my hard disk. When I was installing the DVD drive, I dropped the hard disk.

What can I say, a backup was no longer necessary…

Hours of programming work were simply gone, forever.

2 Likes

Thanks @hydn for explanation.

I don’t remember which was for me one of worst oops moment, but I’m pretty hasty
guy and sometimes I don’t keep the correct attention while doing critical operations :frowning:

I would say one of most efficent way for manage disaster is having many backup incremental copies of your hard drive or backup images of very critical / important files.

For let you know I tried to manage a backup of a Linux hard drive with Timeshift. It went good, but when I was restoring the image system was not so responsive and it was lacking some modules.

So I think is mandatory have a complete image of hard drive, with all your installed softwares and your importand data.

Talking about Linux think for example a broken update, the one which completly broke your system, maybe with broken greeter or lightdm, you won’t be able to enter in desktop anymore.
In this case possibles solutions are:

  • Wait from repos if the developers push the correct update => this is bad because you don’t know how much time you’ll have a down system
  • Login in CLI and see if you can rollback some updates => this might be tricky
  • Take a previous snapshot and recover the entire disk, then do later the update => you can manage to recover the system, but you will lose last work done since last backup.

I’m talking about a full system disaster where you are neither able to login in desktop environment.
For just some critical files for example crontab or fstab I think the best practice consist to have a backup copy of the singles important file, in case of broken file you can recover it from backup.

But yes, with this practice you need to be constant with backup, at least one at week or better maybe by scheduling them.

1 Like

I have multiple distributions installed on most of my systems and I also have multiple systems, multiple USB Flash Drives and a variety of methods and locations of backups so no matter whether I make a mistake or I have a flood or something like that I can recover.

I wrecked a multiple distribution system once when I mistakenly installed over the entire setup. Because of fairly recent flash drive copies it wasn’t more than ninety minutes and I had all systems installed. It was only a little bit longer and I had everything 100% back to normal, perhaps two hours from mistake to 100% normal and updated.

1 Like

I remember in my young days, I was at my dad’s office computer, either DOS 6.1 or Windows 98. I was at the command prompt experimenting with some files or something. I am talking 30 years ago, so I don’t remember all the details. What I do remember I was in the C:\ drive or C:\Windows drive and I typed in del ., and pressed Enter then I froze. What the bleep!!!

Fortunately I didn’t do anything else, and the techs came got the computer and did a undelete with a recovery tool. Lesson well learned! I don’t think I ever used that command again.

2 Likes

So this morning, the mail queue on that server looked like this:

I checked the logs, read the queued emails and it’s related to the munin cron jobs. Had duplicated tasks because it was not being called from crontab file but rather via /var/spool/cron/munin.

Deleted the duplicate. Restarted crond and cleared the queue:

exim -bp | awk '{print $3}' | xargs exim -Mrm

Hopefully, this helps anyone with a similar issue.

1 Like

TimeShift is a big help. I use it regularly before any significant updates. Saved me more than once!

2 Likes

Indeed. I use on desktop as well.