Backup and Restore Immich from TrueNAS Scale to Docker using pg_dumpall #10906
Replies: 4 comments 12 replies
-
Hello there. |
Beta Was this translation helpful? Give feedback.
-
Hey @ra7bi , thanks for this excellent guide! There are a couple of steps that I'm a little unclear about, and I'm wondering if they're even required, given the way that I setup Immich initially (using 7 separate datasets via HostPaths per the community guide here.). Since my database is relatively easily accessible inside the pgData dataset (I can mount via SMB to copy it), do I have to do the steps of "dump"ing the database? Can I simply copy the library/upload/profile folders and put those 3 folders under UPLOAD_LOCATION=/path_to_backupLibrary, and then copy the pgData folder to DB_DATA_LOCATION=./postgres and update the .env file with these paths? Or would this not be sufficient? Sorry, I'm just a little n00b with the command line and try to avoid it when I can lol. |
Beta Was this translation helpful? Give feedback.
-
First off you are a life saver man.. this was what I needed to perform a migration from TrueNas Scale to Ubuntu Server docker compose.. I moved over my configuration and 320gbs of images (immich library). A couple things have changed since this post though.. so here is some updates. k3s is not on TrueNas Scale anymore.. you have to now use the docker comannd line. So when you perform the backup of the postgres database use this: docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=immich | gzip > "/path/to/backup/dump.sql.gz" Key side note about the command above. The offical backup and restore docs from immich will have the username as Also the part about the pod name is no longer needed if you are using docker. The command above assumes you are using Once you get that backup sql.gz file, move that some where to your new ubuntu server. I used scp to move it over.. but whatever works. Mine was 180 mbs large. On your ubuntu system, when you are first setting up your new docker compose file for the whole immich setup, you will need to make sure you are using the SAME version (docker image) for postgres. TrueNas Scale's docker file for immich uses postgres 15... the default docker compose file from the immich github is using version 14.. these have to be the same. Just manually adjust the compose.yml file and update the postgres image to whatever you need to match the TrueNas scale postgress immich image version. In TrueNas Scale you will have 7 directories for your immich data... THIS IS IMPORTANT... grab them ALL! Then put all seven folders into a new parent folder and migrate them onto your new ubuntu system. In the new docker-compose.yml file on the new system.. point the UPLOAD_LOCATION environmental variable to that parent folder. It will use all seven folders inside that new parent folder for all the data and your previous data form the TrueNas system... Make backups of everything if you can.. take your time.. and do NOT START the docker compose file yet.. Then you can actually follow the rest of the Restore docs on the offical webpage: https://immich.app/docs/administration/backup-and-restore/ . From a clean setup (so never have ran the immich docker compose file yet), run: docker compose pull # this grabs all the images for the compose file
docker compose create # this builds the containers without starting them
docker start immich_postgres # this starts the postgres database and nothing else
# update the path/to/backup to were you actually have your .sql.gz backup file
# then run this command against your docker container and you will start to see a bunch of SQL statements processing in your terminal.. wait for it to finish
gunzip --stdout "/path/to/backup/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 --dbname=postgres --username=postgres
# once the above command it done, you can start the other containers
docker compose up -d This will start up immich and then navigate to the webui port with your server hostname/ip.. you should be greated with your login page and your previous credentials and previous users will all be there and ready to login. Just login and everything will be there like it never was migrated lol... if done right immich wont even really know a difference. Hope this helps yall out.. This took me a couple trial and error runs to get correct.. so make backups and test it out a couple times. Critical things to remember.. has to be the same postgres version.. make sure you create the postgres dump correctly.. move all 7 directories into a new parent folder for the env variable. |
Beta Was this translation helpful? Give feedback.
-
This is a half baked backup solution. Who makes a backup for your personal memories and provides a below sub-par backup and restore functionality? I am stuck on a half broken truenas scale box right now that immich is the only reason it's up... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Backup and Restore Immich from TrueNAS Scale to Docker
This guide will walk you through the steps to backup your Immich database and relevant folders from a TrueNAS Scale environment and restore them to a Docker-based system.
Backup Immich Database and Folders from TrueNAS Scale
SSH into your TrueNAS Scale server:
Get the PostgreSQL pod name:
Look for the pod name that starts with
immich-postgres
.Dump the PostgreSQL database:
Move the dump file to a desired location:
Copy the required folders:
Download the dump file and backupLibrary folder to your local machine:
Use
scp
or any other method to download the dump file and backupLibrary folder to your local machine.Restore Immich Database and Folders on Docker
Copy the backupLibrary folder to your new Docker server:
Use
scp
or any other method to upload the backupLibrary folder to your new Docker server.Download and set up Immich on your Docker server:
Follow the Immich Docker installation guide to download and set up Immich.
Update the
UPLOAD_LOCATION
in your.env
file:Set the
UPLOAD_LOCATION
to point to thebackupLibrary
folder:Check the PostgreSQL version in TrueNAS Scale:
Make sure the version matches with the PostgreSQL version in your Docker setup. If not, update your Docker YAML file to match the PostgreSQL version.
Prepare the dump file:
Notes
<immich-postgres-pod-name>
with the actual PostgreSQL pod name obtained in step 2./home/xxxx
with the actual path where you want to move the dump file./path_to_backupLibrary
with the actual path to thebackupLibrary
folder on your Docker server.sed
andgzip
installed on your local machine for processing the dump file.This guide should help you smoothly backup and restore your Immich database and relevant folders between TrueNAS Scale and any Docker-based system. If you encounter any issues, please refer to the relevant PostgreSQL and Docker documentation for further assistance.
Thanks you
Beta Was this translation helpful? Give feedback.
All reactions