Immich
Note
The official backup and restore documentation for Immich is located here - https://immich.app/docs/administration/backup-and-restore/. The steps below were taken from the official documentation and adapted to our local installation.
Backup Immich
Warning
Do not backup the db_data_location folder while Immich is running. This will lead to a corrupt and unusable backup. Instead, use the following pg_dumpall command to get a clean and usable backup.
Database Backup
Run the following command to backup the Immich database
sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | gzip > "/mnt/5TB-Disk1/backup/server/immich/dump.sql.gz"
Photo / Filesystem Backup
Run the following command to backup the photos stored in Immich. This command will place a full copy of all photos into /mnt/5TB-Disk1/backup/server/immich/photos/library. Modify the destination if you want to copy them to a different destination.
sudo rsync -avz /photos/library /mnt/5TB-Disk1/backup/server/immich/photos/library
sudo rsync -avz /photos/upload /mnt/5TB-Disk1/backup/server/immich/photos/upload
sudo rsync -avz /photos/profile /mnt/5TB-Disk1/backup/server/immich/photos/profile
Immich Config Backup
Immich configuration backup is performed in the admin web interface.
Note
This is not mentioned in the official immich documentation so it may not be necessary.
- Click "Export as JSON" link in the top header of the page to download
- Move the backup file to your network backup folder.
Restore Immich
Restore Photos / Filesystem
Note
The source path below assumes the photos are located in on the backup media and that it is mounted on
/mnt/5TB-Disk1. Replace the rsync source if needed.
sudo rsync -avz /mnt/5TB-Disk1/backup/server/immich/photos/library /photos/library
sudo rsync -avz /mnt/5TB-Disk1/backup/server/immich/photos/upload /photos/upload
sudo rsync -avz /mnt/5TB-Disk1/backup/server/immich/photos/profile /photos/profile
Database Restore
The recommended way to backup and restore the Immich database is to use the pg_dumpall command. When restoring, you need to delete the DB_DATA_LOCATION folder (if it exists) to reset the database.
Warning
For the database restore to proceed properly, it requires a completely fresh install (i.e. the Immich server has never run since creating the Docker containers). If the Immich app has run, Postgres conflicts may be encountered upon database restoration (relation already exists, violated foreign key constraints, multiple primary keys, etc.).
docker compose down -v # CAUTION! Deletes all Immich data to start from scratch.
# rm -rf DB_DATA_LOCATION # CAUTION! Deletes all Immich data to start from scratch.
docker compose pull # Update to latest version of Immich (if desired)
docker compose create # Create Docker containers for Immich apps without running them.
docker start immich_postgres # Start Postgres server
sleep 10 # Wait for Postgres server to start up
gunzip < "mnt/5TB-Disk1/backup/server/immich/dump.sql.gz" \
| sed "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" \
| docker exec -i immich_postgres psql --username=postgres # Restore Backup
docker compose up -d # Start remainder of Immich apps
Authors and acknowledgment
See https://immich.app and https://github.com/immich-app/immich