Migrating Infrastructure to Another VPS

9. Migrating the Infrastructure to Another VPS

In this chapter we describe the process to migrate the complete infrastructure to a new VPS. The process is simple: we stop the services, compress the data directory, copy it to the new server, and bring it back up.

You may need to move the infrastructure to another service provider at some point, or simply the contracted VPS is about to expire and it is preferable to acquire a new one.

9.1 Stopping the Infrastructure

We should always warn in advance when performing tasks of this type to avoid users being left mid-operation.

cd cashu4cs-deploy/
docker-compose stop

At this point, the infrastructure is stopped and no one will be able to use the services.

9.2 Backing Up the cashu4cs-deploy Directory

We will use the tar zcvf command to perform a compressed backup.

tar zcvf cashu4cs-deploy.tar.gz cashu4cs-deploy/
cashu4cs-deploy/
cashu4cs-deploy/get_public_ip.sh
cashu4cs-deploy/.git/
cashu4cs-deploy/.git/logs/
cashu4cs-deploy/.git/logs/HEAD
cashu4cs-deploy/.git/logs/refs/
cashu4cs-deploy/.git/logs/refs/remotes/
cashu4cs-deploy/.git/logs/refs/remotes/origin/
cashu4cs-deploy/.git/logs/refs/remotes/origin/HEAD
cashu4cs-deploy/.git/logs/refs/heads/
cashu4cs-deploy/.git/logs/refs/heads/main
...
...
...
cashu4cs-deploy/app-data/lnbits/db/
cashu4cs-deploy/app-data/cashu/
cashu4cs-deploy/app-data/cashu/.env
cashu4cs-deploy/app-data/cashu/certs/
cashu4cs-deploy/app-data/cashu/certs/client_cert.pem
cashu4cs-deploy/app-data/cashu/certs/ca_private.pem
cashu4cs-deploy/app-data/cashu/certs/generate_certificates.sh
cashu4cs-deploy/app-data/cashu/certs/server_private.pem
cashu4cs-deploy/app-data/cashu/certs/server_cert.pem
cashu4cs-deploy/app-data/cashu/certs/client_private.pem
cashu4cs-deploy/app-data/cashu/certs/ca_cert.pem
cashu4cs-deploy/recreate.sh

If the previous operation completed correctly, list the directory contents.

ls .
cashu4cs-deploy cashu4cs-deploy.tar.gz

This compressed file is our entire infrastructure, which we can copy to the new VPS.

Important: You cannot forget that the destination VPS must have the necessary requirements for the infrastructure as seen in the first steps.

9.3 Copying and Extracting cashu4cs-deploy.tar.gz on the New VPS

Execute the following command:

scp cashu4cs-deploy.tar.gz root@<new vps ip>:/root/

If the copy completed correctly, we proceed to connect to the server.

ssh root@<new vps ip>
# After connecting, extract the file
tar zxvf cashu4cs-deploy.tar.gz
# Move to the directory
cd cashu4cs-deploy/

You might wonder why we didn't start everything from the previous step, and that's because there is a detail here. The new VPS has a different IP, so we need to update the DNS records of our domain and the lnd.conf file, specifically externalip.

And how do we get the IP of the new VPS? Very easily; we can find it in the VPS service provider panel or use the following script:

./get_public_ip.sh
12.45.128.56

In the example, the obtained IP is 12.45.128.56; this is the one we must update in the externalip parameter and in the DNS records. Now we can proceed to the next step.

9.4 Starting the Infrastructure

Execute the following:

docker-compose up -d

At this point, the images are downloaded again, and the containers are built with the information they already had, so we would have the infrastructure operational again in minutes. If the process doesn't fail, we can verify with the following command:

docker ps
CONTAINER ID   IMAGE                                              COMMAND                  CREATED         STATUS                  PORTS                                                                                                                                       NAMES
c0ec55b00d9c   lnbits/lnbits:v1.5.3                               "sh -c 'uv run lnbit…"   30 seconds ago   Up 30 seconds            5000/tcp                                                                                                                                    app_lnbits
86eada0916e5   jc21/nginx-proxy-manager:latest                    "/init"                  30 seconds ago    Up 30 seconds            0.0.0.0:80->80/tcp, [::]:80->80/tcp, 0.0.0.0:443->443/tcp, [::]:443->443/tcp, 81/tcp                                                        nginx_proxy_manager
fb888e103a82   ghcr.io/orangeshyguy21/orchard-mintdb-sqlite:1.5   "docker-entrypoint.s…"   30 seconds ago   Up 30 seconds             3321/tcp                                                                                                                                    app_orchard
5ff40c0146ab   lightninglabs/lightning-terminal:v0.16.1-alpha     "litd --configfile=/…"   30 seconds ago   Up 30 seconds             8443/tcp, 9735/tcp, 10009/tcp                                                                                                               lightning_terminal
aa7146e0961d   cashubtc/nutshell:0.20.0                           "poetry run mint"        30 seconds ago   Up 30 seconds                                                                                                                                                        app_cashu
a538285ac7bd   lightninglabs/lnd:v0.20.1-beta                     "lnd --configfile=/r…"   30 seconds ago   Up 30 seconds             0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp, 0.0.0.0:9735->9735/tcp, [::]:9735->9735/tcp, 0.0.0.0:10009->10009/tcp, [::]:10009->10009/tcp   node_lnd
da4838d5f798   postgres:14.18-bookworm                            "docker-entrypoint.s…"   30 seconds ago   Up 30 seconds             5432/tcp                                                                                                                                    postgres_lnbits
e20eecdc0df8   redis:8.4.0                                        "docker-entrypoint.s…"   30 seconds ago   Up 30 seconds (healthy)   6379/tcp                                                                                                                                    redis
7de5f6d082cf   dockurr/tor                                        "tor"                    30 seconds ago   Up 30 seconds (healthy)   9050-9051/tcp                                                                                                                               proxy_tor