Tweaking the Backup & Restore Script

First of all apologies to @foosel and others who write some pretty amazing stuff for OctoPrint. I was a linux and network admin before I retired - and there are probably much better ways to do this than my hack, but I thought I'd share anyway...

I run OctoPrint on a couple of pi's one on my Ender 3 and one on a Core XY machine I'm building/playing with. We recently had a brown out which wiped out the pi on the Ender 3 and I inadvertently restored the backup from the other machine. No big deal but had to remove the newly installed plugins and restore from the correct backup.

To stop me falling down this hole again and having to remember to rename the backup files I made the following changes to plugins/backup/__init__.py

Added import socket to the list of imports and tweaked def build_backup_filename(): to read:
return "{}-{}-{}.zip".format(BACKUP_FILE_PREFIX, socket.gethostname(), time.strftime(BACKUP_DATE_TIME_FMT))

So now my backups include the pi's hostname in the filename and I don't need to remember to rename the files when I download them.

Just thought others may find this useful...

Andy B.

2 Likes