#How to restore Immich on a new Ubuntu server?
1 messages Β· Page 1 of 1 (latest)
:wave: Hey @lethal widget,
Thanks for reaching out to us. Please follow the recommended actions below; this will help us be more effective in our support effort and leave more time for building Immich
.
References
- Container Logs:
docker compose logsdocs - Container Status:
docker compose psdocs - Reverse Proxy: https://immich.app/docs/administration/reverse-proxy
Checklist
- :blue_square: I have verified I'm on the latest release(note that mobile app releases may take some time).
- :blue_square: I have read applicable release notes.
- :blue_square: I have reviewed the FAQs for known issues.
- :blue_square: I have reviewed Github for known issues.
- :blue_square: I have tried accessing Immich via local ip (without a custom reverse proxy).
- :blue_square: I have uploaded the relevant logs, docker compose, and .env files, making sure to use code formatting.
- :blue_square: I have tried an incognito window, disabled extensions, cleared mobile app cache, logged out and back in, different browsers, etc. as applicable
(an item can be marked as "complete" by reacting with the appropriate number)
If this ticket can be closed you can use the /close command, and re-open it later if needed.
Important part:
docker start immich_postgres # Start Postgres server
yes i have read this article, thanks. BUT i dont quite understand, what about the "immich-app" folder?
re-create your /home/temal/immich-app/ folder, with the docker compose file and the .env var
As for how to restore the backup from duplicati, that's up to you to figure out
yes i know π
From your screenshot your immich-app folder also contains ./library and ./postgres, so the default locations.
just populate the ./library with the backup from duplicati. and then do the db restore with
| docker exec -i immich_postgres psql --username=postgres # Restore Backup```
This will populate the database
then you can do the docker compose up -d and it should be running
but i dont understand, on a new ubuntu machine, the first command to run would be "apt update" and then "apt upgrade", then install docker and docker compose. then i retrieve the backup data (immich-app folder and sql dump file) and put them to /restore_data/immich-app and /restore_data/dump.sql.gz. So what now? just run the docker command u sent?
If you backup the whole immich-app folder then that includes the running database in ./postgres, which is a bad idea. You could restore that, yes, then delete whatever is inside the restored ./postgres folder, then create containers + start ONLY the postgres container like stated in the docs with:
docker compose create # Create Docker containers for Immich apps without running them.
docker start immich_postgres # Start Postgres server
next up is this like stated before
So i need to install immich with docker just as usually on the new machine before restoring from the backup
Yes but don't do a docker compose up -d because that will mess things up
You can do that after the DB restore of course
let me summarize it
HOW TO RESTORE IMMICH ON A NEW SYSTEM (ubuntu):
BACKUP IMMICH DATA ON ORIGINAL SERVER:
- run sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | gzip > "dump.sql.gz"
- copy immich-app folder and sql dump file to the new machine
RESTORE FROM BACKUP TO NEW SERVER:
Pre-information:
- backed up files from the original server are stored on the new server in: /backup_data/immich-app/ and sql dump here: /backup_data/dump.sql.gz
- run sudo apt update
- run sudo apt upgrade
- install docker + docker compose on system
- cd into your home directory, e.g. /home/temal/
- copy old "immich-app" directory to new directory using **sudo cp -r /backup_data/immich-app /home/username/immich-app
- cd into the directory using cd immich-app
- if you still have your old docker-compose.yml file in the immich-app folder then skip this step! otherwise: download docker-compose.yml file using wget -O docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
- Get .env file from the backup and not the official github release, run: sudo cp -r /backup_data/immich-app/.env /home/username/immich-app/example.env
- delete the files in postgres folder using:
- delete the folder with all its content: sudo rm -rf /home/username/immich-app/postgres
- create new postgre folder: sudo mkdir /home/username/immich-app/postgres
- make sure you are in the immich-app directory, run docker compose pull
- run docker compose create
- run
gunzip < "/backup_data/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 - run docker compose up -d
@spice zinc wait i forgot a step, to copy immich library data to new one?
yep you forgot that one
im kinda confused now
postgres folder: where is the data? how does it relate to eachother?
library: pictures and related text/thumbnails/...
docker stuff: the server, the database agent, the machine learning...
so backup only library = you still have all images
also backup postgres = you have how they relate to eachother, upload dates, users etc...
bro this is so difficult, im just a newbie in ubuntu/linux
Think of it this way, immich is a grocery cart
If you want to buy the same groceries you still have to put them in the cart
You can have the groceries without the cart, it just isn't as handy to walk around the store π
Easiest way to try would be to spin up a second ubuntu VM and try the backup restore
ye i want to backup the grocery cart including the same groceries
It won't hurt your data because that's still on the original
at what step do i have to copy immich-app folder from /backup_data/immich-app/ to /home/username/immich-app
after step 4
so INSTEAD of making directory "immich-app" i copy the old immich-app dir to /home/username/immich-app?
you could do that yes, but remember to delete the /home/username/immich-app/postgres folder
On the new VM of course
The reason you have to do it this way is because restoring/copying a running database is just not a good idea
that's why you have to do a database dump + restore
how do i copy an entire path on linux?
copy file is using "cp file1 file2"
but how copy path?
just by adding / at the end?
cp -r /path/to/directory /path/to/new/directory
ah thx
actually interesting point, adding a / at the back can produce fun results
The best advice I can give is to play around on a VM you're willing to lose
also the man command will help
ye but first let me get that "newbie guide" done
is step 7 really necessary? because i already have docker-compose.yml file in my old immich-app folder
yeah not anymore if you copy it that way
same with the .env file, it should be copied with cp -r
HOW TO RESTORE IMMICH ON A NEW SYSTEM (ubuntu):
BACKUP IMMICH DATA ON ORIGINAL SERVER:
- run sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | gzip > "dump.sql.gz"
- copy immich-app folder and sql dump file to the new machine
RESTORE FROM BACKUP TO NEW SERVER:
Pre-information:
- backed up files from the original server are stored on the new server in: /backup_data/immich-app/ and sql dump here: /backup_data/dump.sql.gz
- run sudo apt update
- run sudo apt upgrade
- install docker + docker compose on system
- cd into your home directory, e.g. /home/temal/
- copy old "immich-app" directory to new directory using sudo cp -ar /backup_data/immich-app /home/username/immich-app
- cd into the directory using cd immich-app
- if you still have your old docker-compose.yml file in the immich-app folder then skip this step! otherwise: download docker-compose.yml file using wget -O docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
- Get .env file from the backup and not the official github release, run: sudo cp -ar /backup_data/immich-app/.env /home/username/immich-app/example.env
- delete the files in postgres folder using:
- delete the folder with all its content: sudo rm -rf /home/username/immich-app/postgres
- make sure you are in the immich-app directory, run docker compose pull
- run docker compose create
- run
gunzip < "/backup_data/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 - run docker compose up -d
NOW, IS EVERYTHING CORRECT?
copy old "immich-app" directory to new directory using **sudo cp -r /backup_data/immich-app /home/username/immich-app
should probably be
copy old "immich-app" directory to new directory using **sudo cp -ar /backup_data/immich-app /home/username/immich-app
sudo cp -r /backup_data/immich-app/.env /home/username/immich-app/example.env should be sudo cp -ar /backup_data/immich-app/.env /home/username/immich-app/.env
add a sudo chown username:username /home/username/immich-app/relevant_files in case the user is still root for whatever reason
No need to make a new postgres folder, docker will provide, (but can't hurt, unless it's owned by root)
what is -ar doing? whats the difference
archive, it keeps permissions/owners
otherwise if you do sudo copy it will be owned by root
ah ok thx
Notice how your ../postgres folder is "owned" by dnsmasq right now, so to fix that you could need to do chown -R 999:999 /home/username/immich-app/postgres
"sudo chown username:username /home/username/immich-app/relevant_files" what are these relevant files?
cant i just do this:
sudo chown username:username /home/username/immich-app/*?
no, for the very reason I just posted
But postgres is created by docker so just remove the folder and let docker recreate it
no need to mess with permissions
okay
so at step 9 we simply remove "create new postgre folder: sudo mkdir /home/username/immich-app/postgres" ?
π
so what are these relevant files? for example what do i have to put there? sudo chown username:username /home/username/immich-app/relevant_files
like the .env file?
because in immich-app there is only one file, the .env file and 2 folders, library and postgres
yeah don't worry just try it once
just be aware that if things don't start or error it might be because of permissions/ownership
so "sudo chown username:username /home/username/immich-app/relevant_files" is optional?
just in case smth is not wokring because of perm
Check it before you do it ls -la /home/username/immich-app after you cp -ra
should match users/owners from your original install
I really deserve to get an award for doing this shit
hahaha
well
i build the fundamental and you just repaired some broken things
ok lets do 50/50
I'm also very new to Linux and just learned a load by reading this π. Half an award each! π π
my old server just got broken (dpkg is broken and apt and some more stuff, i think i delete necessary files by accident, ill reinstall ubuntu and ill try the method to backup and restore immich)
Did you rm -rf /etc/ or something π
nah
ive done these:
sudo apt-get remove --purge pythonX.X
sudo apt-get remove --purge python3.10
sudo apt-get autoremove --purge python3
sudo apt-get autoremove --purge python3-pip
sudo rm -rf /usr/local/lib/pythonX.X/
sudo rm -rf /usr/local/lib/python3./
sudo rm -rf /usr/lib/pythonX.X/
sudo rm -rf /usr/lib/python3./
sudo apt-get remove --purge python3-pip
rm -rf ~/.pip
rm -rf ~/.cache/pip
reboot
sudo apt-get autoremove --purge
sudo rm -rf /usr/local/lib/python3.12/
sudo rm -rf /usr/local/lib/python3./ # This removes other versions if they exist
sudo rm -rf /usr/lib/python3.12/
sudo rm -rf /usr/lib/python3./ # This removes other versions if they exist
sudo rm -rf /usr/bin/python3.12
sudo rm -rf /usr/lib/python3.12
sudo find / -name 'python' -exec rm -rf {} ;
sudo mkdir -p /usr/lib
sudo touch /usr/lib/cnf-update-db
sudo chmod +x /usr/lib/cnf-update-db
and since then apt and dpgk not working anymore
Why would you ever do a python purge
You're basically telling your OS to shoot itself
because i couldnt install any python package anymore using pip, whenenver i tried to install "pip install discord.py" it says smth like that python or pip is externally managed and something with envrioment that i need to install global packages using "apt install python3-PACKAGENAME", but i wanted the normal python back
oh lol. well now my system is fucked
@spice zinc can't i just do following?
on new ubuntu machine install immich as usual with docker,
then replace "library" folder in immich-app folder with the old one,
run :
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 < "/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 --username=postgres # Restore Backup
docker compose up -d # Start remainder of Immich apps```
and done?
You've got it backwards
first run
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 < "/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 --username=postgres # Restore Backup
Then replace the libary folder
Then docker compose up -d # Start remainder of Immich apps
and before i run this i need to create docker-compose.yml file?
Yes and the .env file
how do u know so much about it? i mean ure not developer of immich and u dont have any special role on this server
Seems pretty self-explanatory to me π
Also I'm a senior linux systems development engineer lmao
how long have you been using linux for?
oh damn, may i ask how old u are?
35
Plenty of years to learn!
defo
so this is the complicated way
and this is the easy
I wouldn't call it easy/complicated, just a bit more fleshed out
ok, so basically my system broken because i tried to uninstall the external managed python thing so now i want to reinstall ubuntu, therefore i rent a storage box 1TB where i upload the database sql dump, the .env file (inside immich folder) and the "library" folder + docker-compose.yml file
i dont need to backup "postgres" folder right?
@spice zinc may i disturb u
You only need the DB dump, not the DB folder
so this is correct?
Yep
i use this command to backup:
rsync -avz --progress /home/temal/immich-app/dump.sql.gz
/home/temal/immich-app/.env
/home/temal/immich-app/.docker-compose.yml
/home/temal/immich-app/library
[email protected]:/immich/
should i really use -a archive mode?
ok ok π thanks for your many help
oh no, i think i broke my system too much i cant even run rsync anymore
exec request failed on channel 0
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]
ah wait
let me try sftp option with rsync
nah rsync not working
but scp working π
bro i have 1.2MB/s upload speed, that is gonna take ages for 250GB
so i put the old .env from the backup into the immich folder as .env file? right?
So like this:
- Install docker and docker compose file
- Create docker-compose.yml file (from backup)
- run
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 < "/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 --username=postgres # Restore Backup
- replace new created library folder by immich with old backup library folder
- put old .env backup file inside immich-app folder
- run docker compose up -d
First put the env back
then run
docker start immich_postgres
It needs the variables inside to set the DB password correctly
-
Install docker and docker compose file
-
Create docker-compose.yml file (from backup)
-
run:
docker compose pull # Update to latest version of Immich (if desired) -
put old .env backup file inside immich-app folder
-
run:
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 < "/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 --username=postgres # Restore Backup -
replace new created library folder by immich with old backup library folder
-
run docker compose up -d
correct now?
Seems all good yes
ok i backed up my immich folder using fast external ssd, its almost done then i will install ubuntu server on my machine and will try out this method
at step1, i can use the old docker-compose.yml file which i backed up,right?
Yeah
It's just that if you do a git clone or whatever at step 1 it will be the default compose and env file, so that's why step 2 is replace those with the ones you want
ye ill just use my old .env and docker compose file
That'll be fine indeed
btw is there a way to access the immich postgress database using phpmyadmin?
no, it's not php
https://www.pgadmin.org/ this is the one you want (also please don't mess around in your DB, that's a BAD idea)
pgAdmin - PostgreSQL Tools for Windows, Mac, Linux and the Web
thanks
currently at step 3
No it didn't do anything, your compose file seems to have a typo
Also copy over your env file already
so before i run "docker compose pull" i need to put .env file inside my current folder?
Shouldn't need to, but it's warning you regardless
i put .env here and ran docker compose pull again and now without warnings
next up, postgres and DB restore
at step 5, are u sure to first run docker start immich_postgress and afterwards run the sql dump file thingi?
Yes
i ran as root with sudo but still permission denied
put "sudo" also before "sed" and before "docker exec"?
yep working
(not advised)
now i replace library folder
oh ye ure right
Looks like the restore ran, I don't know what the output is supposed to look like but it seems OK
wait, bro i dont have any immich folder here
if you did sudo su - you're now in /root/
Yeah it doesn't create itself now does it
so i enter "mkdir immich-app"?
If that's what's in your .env file
my .env says "UPLOAD_LOCATION=./library"
and before on my old server i had it like this:
/home/temal/immich-app/library
/home/temal/immich-app/postgres
etc
yeah it will make a library folder right in /home/temal if you go on
first sudo docker compose down
mkdir /home/temal/immich_app
sudo mv docker-compose.yml .env postgres /home/temal/immich_app
cd /home/temal/immich_app
wait no
ure a warm soul my friend
First restore the library of course
wait
i ran all of these commands u sent
Yeah that's find
if you didn't do docker compose up yet
:3
If you did, down it goes again
then move library in place, then back up
I hope that's not a space between app/ and .env
I wouldn't mv the library, do a sudo cp -a /mnt/sandisk500/temal/immich-app/library /home/temal/immich-app
cp doesn't do progress bars like that :3
ok now its gonna take like 1h
Same as mv honestrly
i know that my immich on my old server took around 230gb so i can just "df -h" and then just take a look at current disk space in usage until it goes at like 250GB
like this yk
now it's at 81GB and if its at like 310GB its done
so i can use this as "progress bar"
in the meantime im gonna install some packages and cloudflared tunnels
yo
its done
@spice zinc now run docker compose up -d ?
yes
im excited if it works
IT WORKS!!!!!!!!!
thank you really much bro i couldn't have done this without u
hope this was a learning experience and not just copy-paste π
every senior developer says that sentence
this is such a funny thread π
but seriously I was looking at backup/restore docs and felt it is so convoluted... maybe a backup/restore command baked in?
huh
u have to do backup and restore by yourself
I was suggesting a builtin command for backing up and restoring, just a suggestion of
like docker compose exec immich-nnn immich_ctl backup (or restore)