It is very important to backup databases deployed using containers. Else once the container stops, all data in it will be gone.
For this exercise we will continue the example used in previous post that created a wordpress site connecting to a mariadb server. Click here to refer the post
Once the wordpress site is ready with few posts already added, let us backup the database, so that when the container is stopped and started, we can restore the database and view the contents.
To backup and restore the database we will use the mysqldump and mysql client applications in the server hosting the containers
[root@gw20-lap-doc1 ~]# yum install -y mariadb
Run the below command from the same server to backup the database (wordpress) running in the container:
[root@gw20-lap-doc1 wordpress]# docker exec <container ID> mysqldump -u root –password=root123 –all-databases > backup.sql
Run the below command from the same server to restore the database (wordpress) running in the container:
[root@gw20-lap-doc1 wordpress]# cat backup.sql | docker exec -i <container ID> /usr/bin/mysql -u root –password=root123 wordpress
An other test is to add few more posts in the wordpress site and back it with another name. Then try restoring both one by one and see the differences each restores brings to the site.