Skip to content

Conversation

@l0ll098
Copy link
Contributor

@l0ll098 l0ll098 commented Mar 5, 2025

Description

This is a small PR that exposes already present database backup machinery in a way that allow users to manually trigger a database backup, without the needing to wait for the automatic cron job to run.

This is particularly handy if your Immich instance does not run at all times (e.g. on a server/NAS) because, for example, you run it on your main computer and you start it "on demand", meaning you start Immich only when you actually need it, and stop it when your done with it.

The resulting .sql.gz file created in the backup folder will count as a database copy.
Hence, if in the system settings page you set that you only want 3 backups, manually clicking this new button four times, will result in four different backups being produced, but only the latest 3 will be kept, just like with database backups produced by the execution of the scheduled cron job to handle database backups.

I'm also attaching a screenshot of the modified Job Status page.

How Has This Been Tested?

Testing manual backups is straightforward, as you just need to click the Start button in the new section in Job Status page.

Testing manual backups and automated one is a bit more convoluted. These are the steps i followed:

  • Create a new DB backup by clicking the Start button
  • Change the "Amount of previous backups to keep" in System Settings to a smaller number, let's say 3
  • Click the button to trigger a manual database backup enough times (four times in our example)
    • We should have only the latest N backups (three in the example)
  • Edit the cron job definition to run in a reasonable amount of time and wait for a new (automatic) backup. You should see a new backup appear

Screenshots (if appropriate)

manual_backup

As you can, a new section for a new job is being rendered. When the Start button is clicked, a new database backup will occur.

API Changes

The only notable change is that /api/jobs can now be invoked with a new manual job, that is backup-database.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR.
  • I have confirmed that any new dependencies are strictly necessary.
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code
  • All code in src/services uses repositories implementations for database calls, filesystem operations, etc.
  • All code in src/repositories/ is pretty basic/simple and does not have any immich specific logic (that belongs in src/services)

@mmomjian
Copy link
Collaborator

mmomjian commented Mar 5, 2025

I’m not sure I love the fact that it kicks out the old backups right away, tbh. It would be better to have some kind of rudimentary keep last X days IMO

@l0ll098 l0ll098 changed the title Exposed a job to manually trigger database backup procedures feat(web): exposed a job to manually trigger database backup procedures Mar 5, 2025
@alextran1502
Copy link
Member

I don't imagine this job will be used very often. Perhaps we can put it under the list in Create Job button
image

@jrasm91
Copy link
Member

jrasm91 commented Mar 6, 2025

I was thinking the same thing

Copy link
Member

@danieldietzler danieldietzler left a comment

Choose a reason for hiding this comment

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

Also agree with the others in that it'd make more sense in the "create job" modal

@l0ll098
Copy link
Contributor Author

l0ll098 commented Mar 6, 2025

Hi @danieldietzler, I've moved it to the Create job modal, so now it looks like this:

image

Do you have any other suggestions?

@renovate renovate bot mentioned this pull request May 17, 2025
1 task
savely-krasovsky pushed a commit to savely-krasovsky/immich that referenced this pull request Jun 8, 2025
…es (immich-app#16622)

* feat(web): exposed a new job to create a manual database backup

* chore(server): added a new test case

* chore(server): moved job to backup db into the create job popup

* remove irrelevant change

* openapi

* chore: formatting

* docs: trigger backup documentation

---------

Co-authored-by: Lorenzo Montanari <[email protected]>
Co-authored-by: Alex Tran <[email protected]>
Co-authored-by: Zack Pollard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants