How to Migrate Gateway Data to a Target Computer

I’m providing a general procedure for how to migrate all existing xx network data to a target computer. I do this with some reservations because it is impossible to write a fool-proof, step-by-step guide that does everything one wants, the way one wants it done. It just cannot be because there are too many factors. The only way I feel comfortable providing a procedure that has the least chance to fail is to include everything (the xxnetwork directory, including chain, and the relevant PostgreSQL database). You will need to use common and technical sense along with the information provided.

NOTICE #1: Do not take any action until you have reviewed this entire post thoroughly and have carefully considered the amount of time that is required. Some of the individual steps take many minutes, if not hours to complete. I feel comfortable saying the entire process will take at least a couple of hours.

NOTICE #2: For steps that require longer times to complete I provide a note, Ex: (Time Req: 3-5 min.) However, these times are estimates and depend on factors such as disk I/O, CPU and/or network connection.

NOTICE #3: You must configure the target computer as a gateway. Here is where you need to use common and technical sense. Not all steps from the Node Handbook are required. For example, you do not need to “Download Software” and “Copy Identity Information” since it’s part of the data you are migrating. However, some steps must be completed before proceeding past Step 5, such as installing the OS, " Updating Software and Installing Dependencies" and “Database Setup”.

Are you sure you’re ready? Let’s begin.

On the existing gateway computer:

Step 1: Stop, and as a precaution to avoid conflicts, disable the xx network services.

$ sudo systemctl stop xxnetwork-gateway xxnetwork-chain
$ sudo systemctl disable xxnetwork-gateway xxnetwork-chain

Step 2. Backup the gateway database into xxnetwork. (Time Req: 2+ min.)
Input the password found in the database section of /opt/xxnetwork/config/gateway.yaml

$ cd /opt/xxnetwork
$ pg_dump -h 0.0.0.0 -U cmix -d cmix_gateway > cmix_gateway.pgsql

Step 3. Compress the xxnetwork directory. (Time Req: 10+ min.)

$ cd /opt
$ sudo tar -czvf gateway-data.tar.gz xxnetwork

Step 4. Get the hash of the tarball. (Time Req: 2+ min.)
Make a note of the output. You need the hash to compare to the output of Step 7.

$ cd /opt
$ sha256sum gateway-data.tar.gz

Step 5. See NOTICE #3

Step 6. Transfer gateway-data.tar.gz to the /opt directory of the target gateway computer. You will need to determine how best to accomplish transferring many gigabytes of data from the existing computer to the target computer. I can only say this could take many minutes to many hours depending on how you transfer the data.

On the target gateway computer:

Step 7. Get the hash of the tarball. (Time Req: 2+ min.)
If the output does not match the output of Step 4, the transfer was not successful, and you must transfer the data again.

$ cd /opt
$ sha256sum gateway-data.tar.gz

Step 8. Decompress the tarball. (Time Req: 10+ min.)

$ cd /opt
$ sudo tar -xvf gateway-data.tar.gz

Step 9. Change ownership of xxnetwork.

$ sudo chown -Rv $USER:$USER /opt/xxnetwork

Step 10. Restore the gateway database. (Time Req: 2+ min.)
Assuming you used the same database password as the existing gateway, input the password found in the database section of /opt/xxnetwork/config/gateway.yaml

$ cd /opt/xxnetwork
$ psql -h 0.0.0.0 -U cmix -d cmix_gateway < cmix_gateway.pgsql

Step 11. Modify the gateway.yaml and/or service files if necessary.

Step 12. Install the service files.

$ sudo ln -s /opt/xxnetwork/xxnetwork-gateway.service /etc/systemd/system
$ sudo ln -s /opt/xxnetwork/xxnetwork-chain.service /etc/systemd/system

Step 13. Reload the systemd service files.

$ sudo systemctl daemon-reexec

Step 14. Enable the services.

$ sudo systemctl enable xxnetwork-gateway.service
$ sudo systemctl enable xxnetwork-chain.service

Step 15. Start the services.

$ sudo systemctl start xxnetwork-chain.service
$ sudo systemctl start xxnetwork-gateway.service

Step 16. Remove the tarball and gateway database backup file.
After you have verified the migration is successful and the gateway and chain processes are running properly you can remove the files used during migration.

$ sudo rm /opt/gateway-data.tar.gz
$ rm /opt/xxnetwork/cmix_gateway.pgsql
6 Likes

Thanks for the clear and helpful post, @Keith. I recently followed the instructions to migrate my gateway to a new VPS (the old one had been misbehaving lately). The entire process took me exactly 1 hour, using scp to send the 23GB gateway-data.tar.gz file. The old and new VPSs were in the same data center, though, so it might have taken longer had they been in more distant locations.

1 Like

Thanks Keith for the excellent guide. I’ve just migrated my gateway without any issues.