Gingter Ale

Fluent stories of a software engineer

Ask a Ninja: Automated Wordpress blog backup using Git

2013-06-11

I thought I had posted this already, but the article list of my blog tells otherwise. Early this year I posted how I moved this blog from the old server to the current one. After that I thought I also could automate the backup this way.

So, what are the required steps?

  • Create a dump of the database.
  • Add the dump and all local modifications to the local repository.
  • Commit the changes to the local repo.
  • Push to a remote repository.

In my case I like to go sure and push to two remote repositories.

So, this is the script that will backup my blog and push it to my repos: [shell]D: cd D:Websgingter.org SET PATH=%PATH%;D:MariaDBbin del backup.sql mysqldump –skip-dump-date -u backup blog_gingter.org > backup.sql git add . git commit -m “Automatic backup” git push origin git push backup master exit [/shell]

To automate the backup I just created a simple scheduled task to execute this script once a day. Restoring the blog from the backup is as easy as described in my blog post about the move.