Immich Backup and Restore with Docker Compose
Updated Nov 2026
verified on Ubuntu 26.04 · Nov 2026Back up the Immich database and photo library from a Docker Compose install, then restore both onto an empty database.
- A running Immich installed with the official docker-compose.yml and .env in ~/immich
- sudo access and enough free disk for a second copy of the library
Two halves, plus your config
Immich stores albums, faces, users and file paths in
Postgres, and the photos and videos as files under UPLOAD_LOCATION. A database
dump contains no photos, and the files alone carry no albums. You need both, and
you also need docker-compose.yml and .env.
The commands follow the layout from How to Deploy Immich on a VPS and Immich's official backup documentation. Immich changed this process in v2.5.0; for an older install, use the matching version of their docs.
Back up
Load the paths and database names from .env:
cd ~/immich
set -a; . ./.env; set +a
mkdir -p ~/backups
Dump the database first and copy the files second. In the other order, the
restored database can point at files your copy does not have. For a fully
consistent pair, run docker compose stop immich-server before and
docker compose start immich-server after.
set -o pipefail
docker exec immich_postgres pg_dump --clean --if-exists \
--dbname="$DB_DATABASE_NAME" --username="$DB_USERNAME" \
| gzip > ~/backups/immich-db.sql.gz
gunzip -t ~/backups/immich-db.sql.gz && ls -lh ~/backups/immich-db.sql.gz
sudo tar czf ~/backups/immich-files.tar.gz -C "$UPLOAD_LOCATION" .
cp docker-compose.yml .env ~/backups/
ls -lh ~/backups
Copy ~/backups off the server. It includes .env with your database password,
so treat it as a secret. For a large library, replace the tar step with an
incremental tool such as rsync, restic or Borg.
Restore
Restoring needs a database that Immich has never started against. On a new
server, put docker-compose.yml and .env into ~/immich first. Then stop the
stack and move any existing data aside:
cd ~/immich
set -a; . ./.env; set +a
docker compose down -v
for d in "$DB_DATA_LOCATION" "$UPLOAD_LOCATION"; do
if [ -d "$d" ]; then sudo mv "$d" "$d.old-$(date +%s)"; fi
done
sudo mkdir -p "$UPLOAD_LOCATION"
sudo tar xzf ~/backups/immich-files.tar.gz -C "$UPLOAD_LOCATION"
Start only Postgres, load the dump in a single transaction, then start the rest.
The sed rewrite comes from Immich's own instructions:
docker compose create
docker start immich_postgres
sleep 10
gunzip --stdout ~/backups/immich-db.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 --dbname="$DB_DATABASE_NAME" \
--username="$DB_USERNAME" --single-transaction --set ON_ERROR_STOP=on
docker compose up -d
sleep 60
docker compose ps
Check that it worked
Log in with your old account, open an album, and download an original photo.
Restore onto the same Immich version you backed up from; set IMMICH_VERSION in
.env to pin it. Once you are sure, remove the .old-… folders.
What we tested
On 2026-11-27, on Ubuntu 26.04 with Immich v3: we uploaded a photo into an
album, backed up, removed the containers, volumes, images and data, and restored
from the files in ~/backups. The login worked, the original was byte-identical
and the album still held it. This was a one-photo library, so it says nothing
about how long a large restore takes. We did not test restoring onto a different
Immich version, or the rsync, restic or Borg alternatives.
About the built-in dumps
Immich also writes database dumps into UPLOAD_LOCATION/backups on a schedule
set in the admin panel. Those cover the database only, and they sit on the same
disk as the library until you copy them elsewhere.
Next steps
Common questions
How long does it take to follow "Immich Backup and Restore with Docker Compose"?
We estimate about 30 minutes of hands-on time for "Immich Backup and Restore with Docker Compose"; this is an editorial estimate, not a measurement.
Was the "Immich Backup and Restore with Docker Compose" guide tested?
The "Immich Backup and Restore with Docker Compose" guide was verified end-to-end on Ubuntu 26.04 (Nov 2026).