#How to restore Immich on a new Ubuntu server?

1 messages Β· Page 1 of 1 (latest)

lethal widget
#

Hello, I have backed up the database in "dump.sql.gz". And I also backed up the entire "immich-app" folder with all it's subfiles and subdirectories.
Now I am on a new Ubuntu machine, how do I install Immich and restore all my photos/videos etc. on this new machine?

austere loomBOT
#

: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 immich.

References

Checklist

  1. :blue_square: I have verified I'm on the latest release(note that mobile app releases may take some time).
  2. :blue_square: I have read applicable release notes.
  3. :blue_square: I have reviewed the FAQs for known issues.
  4. :blue_square: I have reviewed Github for known issues.
  5. :blue_square: I have tried accessing Immich via local ip (without a custom reverse proxy).
  6. :blue_square: I have uploaded the relevant logs, docker compose, and .env files, making sure to use code formatting.
  7. :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.

spice zinc
#

Important part:

docker start immich_postgres    # Start Postgres server
lethal widget
#

yes i have read this article, thanks. BUT i dont quite understand, what about the "immich-app" folder?

spice zinc
#

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

spice zinc
#

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

lethal widget
spice zinc
#

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
spice zinc
lethal widget
#

So i need to install immich with docker just as usually on the new machine before restoring from the backup

spice zinc
#

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

lethal widget
#

let me summarize it

lethal widget
#

HOW TO RESTORE IMMICH ON A NEW SYSTEM (ubuntu):

BACKUP IMMICH DATA ON ORIGINAL SERVER:

  1. run sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | gzip > "dump.sql.gz"
  2. 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
  1. run sudo apt update
  2. run sudo apt upgrade
  3. install docker + docker compose on system
  4. cd into your home directory, e.g. /home/temal/
  5. copy old "immich-app" directory to new directory using **sudo cp -r /backup_data/immich-app /home/username/immich-app
  6. cd into the directory using cd immich-app
  7. 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
  8. 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
  9. 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
  10. make sure you are in the immich-app directory, run docker compose pull
  11. run docker compose create
  12. 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
  13. run docker compose up -d
#

@spice zinc wait i forgot a step, to copy immich library data to new one?

spice zinc
#

yep you forgot that one

lethal widget
#

im kinda confused now

spice zinc
#

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...

lethal widget
#

bro this is so difficult, im just a newbie in ubuntu/linux

spice zinc
#

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

lethal widget
#

ye i want to backup the grocery cart including the same groceries

spice zinc
#

It won't hurt your data because that's still on the original

lethal widget
spice zinc
#

after step 4

lethal widget
#

so INSTEAD of making directory "immich-app" i copy the old immich-app dir to /home/username/immich-app?

spice zinc
#

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

lethal widget
#

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?

spice zinc
#

cp -r /path/to/directory /path/to/new/directory

lethal widget
#

ah thx

spice zinc
#

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

lethal widget
#

ye but first let me get that "newbie guide" done

spice zinc
#

e.g. man cp gives you the man pages on cp

#

man = manual

lethal widget
spice zinc
#

yeah not anymore if you copy it that way

#

same with the .env file, it should be copied with cp -r

lethal widget
#

HOW TO RESTORE IMMICH ON A NEW SYSTEM (ubuntu):

BACKUP IMMICH DATA ON ORIGINAL SERVER:

  1. run sudo docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | gzip > "dump.sql.gz"
  2. 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
  1. run sudo apt update
  2. run sudo apt upgrade
  3. install docker + docker compose on system
  4. cd into your home directory, e.g. /home/temal/
  5. copy old "immich-app" directory to new directory using sudo cp -ar /backup_data/immich-app /home/username/immich-app
  6. cd into the directory using cd immich-app
  7. 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
  8. 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
  9. delete the files in postgres folder using:
    • delete the folder with all its content: sudo rm -rf /home/username/immich-app/postgres
  10. make sure you are in the immich-app directory, run docker compose pull
  11. run docker compose create
  12. 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
  13. run docker compose up -d
#

NOW, IS EVERYTHING CORRECT?

spice zinc
#

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)

lethal widget
spice zinc
#

archive, it keeps permissions/owners

#

otherwise if you do sudo copy it will be owned by root

lethal widget
#

ah ok thx

spice zinc
#

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

lethal widget
spice zinc
#

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

lethal widget
#

okay

lethal widget
spice zinc
#

πŸ‘Œ

lethal widget
#

like the .env file?

#

because in immich-app there is only one file, the .env file and 2 folders, library and postgres

spice zinc
#

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

lethal widget
#

so "sudo chown username:username /home/username/immich-app/relevant_files" is optional?

#

just in case smth is not wokring because of perm

spice zinc
#

Check it before you do it ls -la /home/username/immich-app after you cp -ra

#

should match users/owners from your original install

lethal widget
spice zinc
#

I think you confused I with you in this*

#

😏

lethal widget
#

hahaha

#

well

#

i build the fundamental and you just repaired some broken things

#

ok lets do 50/50

void moat
#

I'm also very new to Linux and just learned a load by reading this πŸ˜‚. Half an award each! πŸ… πŸ…

lethal widget
spice zinc
#

Did you rm -rf /etc/ or something πŸ‘€

lethal widget
#

nah

lethal widget
# spice zinc Did you rm -rf /etc/ or something πŸ‘€

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

spice zinc
#

Why would you ever do a python purge

#

You're basically telling your OS to shoot itself

lethal widget
#

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

lethal widget
lethal widget
# lethal widget HOW TO RESTORE IMMICH ON A NEW SYSTEM (ubuntu): **BACKUP IMMICH DATA ON ORIGINA...

@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?
spice zinc
#

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

lethal widget
spice zinc
#

Yes and the .env file

lethal widget
spice zinc
#

Seems pretty self-explanatory to me πŸ‘€

#

Also I'm a senior linux systems development engineer lmao

lethal widget
lethal widget
spice zinc
#

35

lethal widget
#

holy...

#

i'm only 17

spice zinc
#

Plenty of years to learn!

lethal widget
#

defo

lethal widget
spice zinc
#

I wouldn't call it easy/complicated, just a bit more fleshed out

lethal widget
#

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

spice zinc
#

You only need the DB dump, not the DB folder

lethal widget
spice zinc
#

Yep

lethal widget
#

ok, ill start the backup process of about 250GB now

#

in Mraedis we trust

lethal widget
# spice zinc 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?

spice zinc
#

-a is archive in rsync

#

that's good

lethal widget
#

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

lethal widget
#

So like this:

  1. Install docker and docker compose file
  2. Create docker-compose.yml file (from backup)
  3. 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

  1. replace new created library folder by immich with old backup library folder
  2. put old .env backup file inside immich-app folder
  3. run docker compose up -d
spice zinc
#

First put the env back

#

then run

docker start immich_postgres
#

It needs the variables inside to set the DB password correctly

lethal widget
#
  1. Install docker and docker compose file

  2. Create docker-compose.yml file (from backup)

  3. run:
    docker compose pull # Update to latest version of Immich (if desired)

  4. put old .env backup file inside immich-app folder

  5. 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

  6. replace new created library folder by immich with old backup library folder

  7. run docker compose up -d

spice zinc
#

Seems all good yes

lethal widget
#

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

lethal widget
spice zinc
#

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

lethal widget
#

ye ill just use my old .env and docker compose file

spice zinc
#

That'll be fine indeed

lethal widget
#

btw is there a way to access the immich postgress database using phpmyadmin?

spice zinc
#

no, it's not php

lethal widget
#

thanks

lethal widget
#

@spice zinc

#

is that ok?

lethal widget
spice zinc
#

No it didn't do anything, your compose file seems to have a typo

#

Also copy over your env file already

lethal widget
#

so before i run "docker compose pull" i need to put .env file inside my current folder?

spice zinc
#

Shouldn't need to, but it's warning you regardless

lethal widget
#

i put .env here and ran docker compose pull again and now without warnings

spice zinc
#

next up, postgres and DB restore

lethal widget
spice zinc
#

Yes

lethal widget
#

i ran as root with sudo but still permission denied

#

put "sudo" also before "sed" and before "docker exec"?

lethal widget
spice zinc
#

You could skip all of the sudo-ness with a straight

#

sudo su - and go root πŸ˜‚

lethal widget
spice zinc
#

(not advised)

lethal widget
#

now i replace library folder

lethal widget
spice zinc
#

Looks like the restore ran, I don't know what the output is supposed to look like but it seems OK

lethal widget
#

wait, bro i dont have any immich folder here

spice zinc
#

if you did sudo su - you're now in /root/

lethal widget
#

in /home/temal there is no immich-app folder

spice zinc
#

Yeah it doesn't create itself now does it

lethal widget
#

so i enter "mkdir immich-app"?

spice zinc
#

If that's what's in your .env file

lethal widget
#

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

spice zinc
#

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

lethal widget
#

ure a warm soul my friend

spice zinc
#

First restore the library of course

lethal widget
#

wait

lethal widget
spice zinc
#

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

lethal widget
#

correct?

spice zinc
#

I hope that's not a space between app/ and .env

lethal widget
#

no there is no space

#

immich-app/.env

spice zinc
#

I wouldn't mv the library, do a sudo cp -a /mnt/sandisk500/temal/immich-app/library /home/temal/immich-app

lethal widget
#

alright boss

#

ah

#

i see no progress bar 😒

spice zinc
#

cp doesn't do progress bars like that :3

lethal widget
#

ok now its gonna take like 1h

spice zinc
#

Same as mv honestrly

lethal widget
#

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 ?

spice zinc
#

yes

lethal widget
#

im excited if it works

#

IT WORKS!!!!!!!!!

#

thank you really much bro i couldn't have done this without u

spice zinc
#

hope this was a learning experience and not just copy-paste πŸ‘€

lethal widget
fast salmon
#

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?

lethal widget
fast salmon
#

like docker compose exec immich-nnn immich_ctl backup (or restore)