Backing it up – Docker

This is actually the second instance of this website.  The first failed when I updated the site using docker and lost the previous configuration.

This post will document the backup strategies that can be used to save my posts and data.

The first backup strategy I will employ is using a cron job to automatically backup the website’s docker volume.

For this I use the following docker image.

The first step is to locate the name of the docker volume to save.  To do this use the docker volume ls command.


docker volume ls

You will see a number of volumes and it will look similar to the following

DRIVER VOLUME NAME
local wordpress_db_data

In this case we will want to save the wordpress_db_data volume.

To save the volume I issue the following command.


docker run -v wordpress_db_data:/volume -v ~/wdmycloud/docker-backup:/backup --rm loomchild/volume-backup backup wordpress_db_data

Replace wordpress_db_data with the name of the volume to save. The next argument ~/wdmycloud/docker-backup:/backup points to the location on my network where I want to save the docker volume.

You will want to start a cron job to periodically backup the volume. In this case, I’ll backup once a day at 1 am.


#/bin/sh

docker run -v wordpress_db_data:/volume -v ~/wdmycloud/docker-backup:/backup --rm loomchild/volume-backup backup wordpress_db_data

Use chmod +x to make the script executable.

Enter the previous command into a script and create a cron entry. The cron entry will look similar to the following:


0 1 * * * ~/system_scripts/docker-backup.sh > /dev/null 2>&1

This runs the script named docker-backup.sh every day at 1 am.

Leave a Reply

Your email address will not be published. Required fields are marked *