Jan 022016
 
Docker Backup

I changed slightly the way to start my containers. Now they always contain the backup volume too:

docker run --name blog-mysql -v blog-backup:/backup \
-v blog-mysql-data:/var/lib/mysql -d mysql/mysql-server:5.7
docker run --name blog-app -v blog-backup:/backup \
-e WORDPRESS_DB_PASSWORD=DBPASSWORD -e WORDPRESS_DB_USER=WPDBACCOUNT \
--link blog-mysql:mysql -v wordpress-data:/var/www/html -p 80:80 \
-w /var/www/html/wordpress -d wordpress:latest

The reason is that I can run a backup job inside the container. Important for the DB backup as now I can use msqldump. Before it was: stop mysql, tar up the DB files, start MySQL again.

Making a backup in each container:

tar -C /var/www/html -z -f /backup/blog-wp-`data +%Y-%m-%d.tar.gz .

resp.

mysqldump -pROOTMYSQLASSWORD --all-databases | gzip >/backup/blog-db-`date +%Y-%m-%d`.tar.gz

Now the problem is how to get those files out and to where…

Dropbox/Google Cloud don’t offer access via ftp/scp/etc. Time to look into the various storage offerings from Google/Amazon/Azure.

Jan 022016
 
Moving dockerized WordPress

One advantage of Docker is the easy move to other Docker providers. In my case: Moving from Google Cloud to Amazon’s AWS. Same instance size, same OS (CoreOS 877). The main difference is the location: Google’s one is in TW, AWS’s one is in JP.

So I start with my MySQL/Wordpress instance from here to AWS.

  1. Create a t1.micro instance with CoreOS 877 (1 shared CPU, 0.6 GB RAM)
  2. Set up ssh authentication for the main user (core for CoreOS, root usually)
  3. Create 3 docker containers and populate them with the last backup of the current instance of MySQL/Wordpress.
    1. Stop WordPress/MySQL. Mount the data volumes to the backup volume. Run a backup.
    2. Start MySQL/WordPress again
  4. Copy those 2 tar files to the new CoreOS AWS server.
  5. Restore the data volumes.
  6. Here wish that Docker would allow copying data volumes from A to B.
  7. Run the very same docker commands to run MySQL and WordPress.
  8. Change DNS (or test by faking a DNS change on the desktop client which runs the browser)

And lo-and-behold, it worked as expected. No issue at all.

When you can read this, then this blog already moved to run on AWS. I’ll keep it here for a while.