PeerTube platform migration
This guide describes how to migrate your PeerTube platform from one server to another. It assumes you have root access to both servers. The process takes some time - so you may want a caffeinated beverage of your choice - and there will be a short period of downtime between when you shut down the old server and point DNS at the new one.
WARNING
Do not modify anything on the old server until you have successfully migrated the platform.
Basic steps
- Setup a new PeerTube server using the production guide
- Stop PeerTube on the old server
- Dump and load the PostgreSQL database using the instructions below
- Copy or synchronize the
storage/files using the instructions below - Copy or synchronize the
config/files using the instructions below - Update or copy your nginx configuration, Let's Encrypt certificates, systemd configuration files as necessary
- Start PeerTube on the new server
- Update your DNS settings to point to the new server
- Enjoy your new PeerTube server!
Detailed steps
You may want to configure nginx to send a 503 (service unavailable) instead of a 502 (bad gateway), and answer with a custom 500.html.
You will probably want to set the DNS TTL to the lowest possible value about a day in advance. Set it to a few minutes if you can. This ensures the DNS update propagates as quickly as possible once you point it to the new IP address, resulting in less downtime.
Create a migration user on both servers
The peertube system user usually has no shell login (/usr/sbin/nologin), so you generally cannot use peertube@server over SSH for transfer commands.
Create a temporary user (for example migration) on both servers and use it for SSH transport:
sudo useradd -m -s /bin/bash migrationOn the old server, generate a dedicated SSH key for the transfer:
sudo -u migration ssh-keygen -t ed25519 -C "peertube-migration" -f /home/migration/.ssh/id_migration -N ""Copy the public key of the old server
cat /home/migration/.ssh/id_migration.pubThen authorize it on the new server:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
vim ~/.ssh/authorized_keys # Paste the public key copied from the old server
chmod 600 ~/.ssh/authorized_keysWhat data needs to be migrated
At a high level, you will need to copy over the following:
- The
/var/www/peertube/storagedirectory, which contains videos, thumbnails, previews, and so on - The
/var/www/peertube/configfile, which contains the configuration - The PostgreSQL database (using pg_dump)
You might also want to copy the following configuration items, if the new server is configured similarly to the old one:
- The peertube-specific nginx configuration (by default found at
/etc/nginx/sites-available/peertube) - The systemd config files or startup scripts, which may contain tweaks and customizations specific to your server
- Let's Encrypt certificates
Dump and load PostgreSQL
Once you have stopped your PeerTube platform, run the following command as the peertube user on the old server, to generate a text dump of the database:
sudo -u peertube pg_dump -Fc peertube_prod > /tmp/peertube_prod-dump.dbCopy the /tmp/peertube_prod-dump.db file over to the new server by running the following command on your old server
scp -i /home/migration/.ssh/id_migration /tmp/peertube_prod-dump.db migration@new.server:/tmpThen on the new server, run the following command to restore the database on the new server to the same state as on the old one:
sudo -u postgres pg_restore -c -C -d postgres /tmp/peertube_prod-dump.dbYou might see warnings that you can safely ignore.
Copy storage/ files
This will probably take a long time! We recommend using rsync to avoid unnecessary copies, but scp or any other file-copying utility is fine too.
To minimize downtime, you may want to finish an rsync run while the old server is still running, and then re-synchronize after shutting down PeerTube to capture the last few changes.
Before copying files, temporarily change ownership of the PeerTube directory on both servers so this user can read and write files directly:
sudo chown -R migration: /var/www/peertubeOn your old server, as the migration user, run:
sudo -u migration rsync -avz -e "ssh -i /home/migration/.ssh/id_migration" /var/www/peertube/storage/ migration@new.server:/var/www/peertube/storage/Copy config/ files
On your old server, as the migration user, run:
sudo -u migration rsync -avz -e "ssh -i /home/migration/.ssh/id_migration" /var/www/peertube/config/ migration@new.server:/var/www/peertube/config/After the migration is complete, restore ownership to peertube on both servers:
sudo chown -R peertube: /var/www/peertubeCopy certificates/nginx/systemd files
This is a good time to copy over any configuration files you wish to use on the new server, such as the nginx/systemd configuration files or startup scripts.
It's a good idea to copy the Let's Encrypt certs over from the old server instead of requesting a new cert. Requesting new certs takes longer, and might fail for some reason, so it's better to avoid that additional source of complication during the migration process.
After the migration
Remove the temporary migration user if you no longer need it on both servers:
sudo userdel -r migrationYou can check whatsmydns.net to see the progress of DNS propagation. To jumpstart the process, you can always edit your own /etc/hosts file to point to your new server so you can start playing around with it early and check if all is all right.
If everything is alright, you can safely shut down the old server.

