Skip to content

Add Restore for Backups#666

Open
schlick7 wants to merge 12 commits into
LuteOrg:masterfrom
schlick7:restore
Open

Add Restore for Backups#666
schlick7 wants to merge 12 commits into
LuteOrg:masterfrom
schlick7:restore

Conversation

@schlick7

@schlick7 schlick7 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

This was coded entirely with an LLM. I tried to keep it to the point and not touch anything not needed.

I have tested it locally with various backup files from different systems and all seem to work fine. I would recommend further testing by others though to confirm.

My reason for wanting this is to smooth the transition from going between Termux when I travel and my Server when I'm home.

Summary

  • Added backup upload support on the backups page
  • Added restore and delete actions for backups
  • Expanded the backups list to show all .db.gz files so uploaded backups are visible (I can switch this to renaming the uploads instead if preferred)
  • Uploaded backups are saved with a manual_ prefix so they are not auto-pruned
  • Restore preserves the current server's backup_dir after cross-system restores

Notes

  • The backup_dir preservation is intended to avoid breaking backups after restoring a DB created on a different system with different folder paths
  • Other machine-specific paths are not touched but we may want to add them as well.

@jzohrab

jzohrab commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Hi @schlick7 - thanks for the interesting PR! In the past I'd considered doing something like this but wasn't sure if it was a good idea ... data is such a precious thing, and I thought that making restores too easy would somehow be a bad thing :-) Anyway, I'll add some comments. Responding to these comments may be out of your range of expertise, in which case we'd want someone to pick it up and run with it.

@jzohrab jzohrab left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is good work (thank you!), but it could create a real problem if a bad upload is done. This needs a whack of automated tests to ensure that it handles weird cases well.

Given the complexity of the cases that need to be handled, I wonder if this is necessary ... but that's just me, and having a graceful restore would be nice.

Comment thread lute/backup/routes.py Outdated
Comment thread lute/backup/service.py
self._remove_excess_backups(settings.backup_count, settings.backup_dir)
return f

def restore_backup(self, app_config, settings, filename):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that this code needs to handle a few different cases, all of which should be really checked in the test_service.py:

  • if I upload a .db.gz that was not a lute db, then everything will break. The code should first check that the db is in fact a valid db. It would need to connect to the code and then check for at least a few tables and columns (probably not all, just a few things should suffice)
  • if the user restores an old db, then the code has to run db migrations on it. I don't know if you'd need to do a total restart or not ... I don't think so, would need to check the startup code
  • if the db is bad, or the migrations fail (?), then the old db should be kept in place, nad the error reported back to the user

This section needs a fair amount of checking before the backup can be automated like this. At least with the user handling this manually, we can say that it's out of the code's hands, and so don't have to handle it. If the code manages it, then it has to handle everything.

Comment thread lute/backup/service.py
DatabaseBackupFile(os.path.join(outdir, f))
for f in os.listdir(outdir)
if re.match(r"(manual_)?lute_backup_", f)
if f.endswith(".db.gz")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine, but it implies that the user won't try to upload/restore a bad db :-)

Comment thread lute/backup/service.py
return DatabaseBackupFile(fullpath)

def _set_backup_dir(self, dbfilename, backup_dir):
"Preserve the local backup_dir after restore."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this refers to settings, it likely belongs in the lute/settings somewhere, and then the backup code would refer to that. This keeps all of the setting logic/structure in the same place.

Comment thread lute/backup/service.py
@jzohrab jzohrab added this to Lute-v3 Apr 8, 2026
@jzohrab jzohrab moved this to In Progress in Lute-v3 Apr 8, 2026
@jzohrab jzohrab added the question Further information is requested label Apr 8, 2026
@jzohrab

jzohrab commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Another thing that I haven't really thought about is how the restore interacts with user media (images) -- right now, the backup is just the db backup, I think, but maybe it needs to somehow be expanded to include media -- and that could be come a space drain.

@schlick7

schlick7 commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

I knocked out the couple easy ones.

Confirming the database seems like it would require a lot of code to be added. Easily done with an LLM, but it will probably be a little messy.

@schlick7

schlick7 commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

I just uploaded a first pass at a db validation before restoring. Not sure if it goes far enough for you or not.

@jzohrab

jzohrab commented May 7, 2026

Copy link
Copy Markdown
Collaborator

I’m away for three weeks, will check on return. This is a very tough feature! Cheers @schlick7 thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants