An update can fail halfway. With a backup made just before it, you can go back in minutes. This guide uses Pterodactyl as the example, but the same four parts (database, configuration with secrets, application files, data) apply to most web apps.
Store the backup on another machine, not only on the server itself: a backup on the same disk is gone when the disk or the server is.
What to back up#
| Part | Where (default) | Why |
|---|---|---|
| Panel database | the MySQL or MariaDB database panel |
users, servers, nodes, settings |
.env file |
/var/www/pterodactyl/.env |
database password and the APP_KEY |
| Panel folder | /var/www/pterodactyl |
the files of the version you run now |
| Wings configuration | /etc/pterodactyl/config.yml |
the node's settings and its key |
| Server data | /var/lib/pterodactyl/volumes on each node |
the files of every game server |
Check your own paths: the data folder of Wings is the data setting under system in /etc/pterodactyl/config.yml.
Back up the panel#
Run these on the panel server. The commands below write to /root; use any folder only root can read.
-
Put the panel in maintenance mode, so nothing changes during the backup:
cd /var/www/pterodactyl sudo php artisan down -
Dump the database:
sudo mysqldump --single-transaction --routines --triggers --result-file=/root/panel-backup.sql panelIf your database is not called
panel, look it up in.envwithout showing the rest of the file:sudo grep '^DB_DATABASE=' /var/www/pterodactyl/.envIf the command asks for a password, add
-u root -p(or the database user from.env). -
Copy the
.envfile:sudo cp /var/www/pterodactyl/.env /root/panel-backup.env -
Pack the panel folder:
sudo tar -czf /root/panel-backup-files.tar.gz -C /var/www/pterodactyl . -
Protect the files, because they contain passwords:
sudo chmod 600 /root/panel-backup.sql /root/panel-backup.env /root/panel-backup-files.tar.gz -
Copy them to another machine, for example with
scpfrom your own computer:scp root@your-server:/root/panel-backup* .If you cannot log in as root, first copy the files to your own user's home folder on the server with
sudo cp, give them to your user withsudo chown, and copy them from there. Delete that extra copy afterwards.
Leave the panel in maintenance mode if you go on with the update. Otherwise, run sudo php artisan up.
Back up the server data on a node#
The files of game servers change while the servers run. For a consistent copy, stop the servers first (in the panel, or tell your players), or make the copy at a quiet moment.
-
Copy the Wings configuration:
sudo cp /etc/pterodactyl/config.yml /root/wings-config.yml sudo chmod 600 /root/wings-config.yml -
Pack the server data. This keeps the owner and rights of every file:
sudo tar -czf /root/wings-volumes.tar.gz -C /var/lib/pterodactyl volumesThis can be large. Check the free space first with
df -hand the size of the data withsudo du -sh /var/lib/pterodactyl/volumes. If there is not enough room, write the archive straight to another disk or machine.
The panel's own backups (on the Backups tab of each server) are stored by Wings in /var/lib/pterodactyl/backups by default, or in S3 storage if you set that up. They are useful, but they are not a copy of the whole node.
Put the panel back#
Do this if an update failed and you want to return to the state of the backup.
-
Put the panel in maintenance mode:
sudo php artisan down(if that fails, go on). -
Put back the panel files. Move the broken folder aside instead of deleting it:
sudo mv /var/www/pterodactyl /var/www/pterodactyl-broken sudo mkdir /var/www/pterodactyl sudo tar -xzf /root/panel-backup-files.tar.gz -C /var/www/pterodactyl -
Put back the
.env:sudo cp /root/panel-backup.env /var/www/pterodactyl/.env -
Put back the database. To get exactly the state of the backup, empty the database first, so tables that a failed update added are gone too. The database user keeps its rights:
sudo mysql -e 'DROP DATABASE panel; CREATE DATABASE panel;' sudo sh -c 'mysql panel < /root/panel-backup.sql' -
Set the owner, clear the caches, restart the queue worker and leave maintenance mode:
cd /var/www/pterodactyl sudo chown -R www-data:www-data /var/www/pterodactyl/* sudo php artisan view:clear sudo php artisan config:clear sudo php artisan queue:restart sudo php artisan up
Put the server data back on a node#
-
Stop the game servers you restore, and stop Wings:
sudo systemctl stop wings -
Unpack the archive in place:
sudo tar -xzf /root/wings-volumes.tar.gz -C /var/lib/pterodactyl -
Start Wings again:
sudo systemctl start wings
Files from the archive overwrite the current ones, but files that were added after the backup stay. To get back exactly the state of the backup for one server, move its folder aside first.
Test your backup#
A backup you have never restored is a guess. Once in a while, restore it on a test machine and check that the panel starts and shows your servers.