Backing up and Restoring Xibo Databases
Running database backups for your Xibo environment is very important. If you have ever had to rebuild a crashed system or rollback from a new upgrade, you know why backups are valuable. If you use the docker version of Xibo, then you are lucky enough to have automatic backups run daily. These backups are saved with the name ‘latest.sql.gz’ in the path: {Xibo Root}/shared/backup/db/. That being said, there are cases in which you want to execute backups on the fly and I’ll show you how you can do that in your Xibo docker environment.
First, we need to get some information. We need to know the password for the MySQL database and the container id of the Xibo web container. The database password can be found in the config.env file for Xibo under the variable name ‘MYSQL_PASSWORD’. You can find the container id of the Xibo web container by running the command ‘docker ps’ on the docker host machine. After we have the needed information, we are ready to start backing up our data.
We now need to connect to our Xibo web container via the bash terminal. For details on how to get to the container terminal, you can follow our previous blog post on the subject(https://kiwipie.net/terminal-access-to-a-xibo-docker-container.html). Once connected, we just need to run the following command:
mysqldump -u cms -h mysql -p{MYSQL Password} -P 3306 cms | gzip > /var/www/backup/db/latest.sql.gz
Remember when running the command above that you need to replace {MYSQL Password} with the password you found in the config.env file. Also, the command above will put a database backup in the path of ‘{Xibo Root}/shared/backup/db/’ on the docker host.
For you to restore your data from this backup is a straightforward process. On the docker host, bring down the Xibo containers by running the command ‘docker-compose down’. Once Xibo is down, you need to unzip the file named ‘latest.sql.gz’ and move it the folder {Xibo Root}/shared/backup/ and then delete the ‘db’ folder. You will also need to change the file name from ‘latest.sql’ to ‘import.sql’. Lastly, you will need to bring the Xibo containers back up by running the command ‘docker-compose up -d’. Once the docker containers boot, your Xibo instance will be rolled back to the imported data.
You now know how to backup and restore your database for Xibo. Hopefully, you will never need these backups, but it’s better to be safe than sorry. Good luck!