I just learned something the hard way about the Automation Editor.
I have a test system where I experiment with configurations, automations, etc. I’ve always used the VS Code editor and not the Automation Editor.
My automations.yaml contains many, many automations that were created in the course of helping other people solve their automation issues. These many automations were commented out.
Today I used the Automation Editor to create one simple automation … and saved it. It didn’t just append the new automation to automations.yaml, it also deleted all the comments. So all of the commented out automations were deleted; dozens and dozens of automations instantly removed.
As luck would not have it, this is my test system … where I rarely do backups. So my library of handy automations is now history.
I’m still in the denial stage, believing that there may be some way to recover the original file, but my rational mind knows that it is gone. I need time to mourn the loss of all of that work … and start backing up my test system on a regular basis.
That’s the first, and last, time I use the Automation Editor …
Some good news to report. I managed to recover what appears to be, at first glance, most if not all of the deleted automations.
After an Internet search for ‘recover overwritten file Ubuntu’, I ran the following command:
sudo grep -I -a -B100 -A100 'trigger' /dev/sda1 | strings | /var/tmp/my-recovered-file
which produced an enormous file (~2 GB). I opened it with VS Code and proceeded to search for remnants of my lost automations. Basically that meant looking for lines starting with the
# comment character. I found a contiguous stretch of commented YAML automation code (about 1974 lines). I’m not certain it is all of the original automations file but it certainly appears to be. Either way, it’s far better than nothing.
In fact, I found six instances of the original automations file’s contents. Two instances contain 1986 lines which leads me to believe I’ve recovered most of the original file. It’s going to be a good day after all …