Ask a Ninja: Automated WordPress blog backup using Git

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:

D:<br />
cd<br />
SET PATH=%PATH%;D:MariaDBbin<br />
del backup.sql<br />
mysqldump --skip-dump-date -u backup &gt; backup.sql<br />
git add .<br />
git commit -m &quot;Automatic backup&quot;<br />
git push origin<br />
git push backup master<br />
exit<br />

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.