Automatic Backup Of A Microblog Site

Ever since the CMS behind microblog sites switched from Jekyll to Hugo the automatic backup of a site to Github has stopped working, leaving me without an automated way to backup my site. Being a little OCD about losing what I write, this situation has made me nervous. Today I figured out a way to restore automated backups.

Microblog provides the ability to export sites in either the Wordpress export format or the emerging Blog Archive Format. With the Wordpress export XML file I can import what I write for my microblog site to a Wordpress site.

To manually download the Wordpress export XML file click Posts, Export, Export in Wordpress format (.wxr). A window will open to allow you to specify the location to write the file.

We can automate the process of downloading the export file using curl in a terminal on a computer running Linux, MacOS, or Windows if you have the bash shell installed in Windows 10. First you need to gather a few pieces of information.

First, note the URL of the Export page, below is the example format:

https://micro.blog/account/export/[user number]

The user number above should be unique for each microblog user, mine is a four digit number.

Next, you need an application token to authentication access to the file. Click Account, Edit Apps and enter a name for the access as Curl backup. (Note that the Edit Apps button is near the bottom of the page.) Make note of the the application token that is generated.

I've written a bash script that runs on a Raspberry Pi to download the Wordpress export file to a directory called mb. The script creates a unique file name using the current date and time. Replace the [app token] and [user number] items in the script with the information that you gathered above.

#!/bin/bash day=`date +%a` time=`date +"%T"` current_time=$(date "+%Y.%m.%d-%H.%M.%S") curl curl -H "Authorization: Bearer [app token]" https://micro.blog/account/export/[user number]/wxr >~/mb/$current_time.export.xml

Finally, I scheduled a cron job to run the above script once an hour. The Wordpress export file is generated each time you access the URL so new posts that you write since the last time you created the export are included.

If the computer that is running the script has enough storage space you can leave the files in the directory in which they are written. In my case since I am using a Raspberry Pi3b+, I want to move the files to a NAS on my home network and so I have another script that runs once a night that creates a compressed file of all the export files in the mb directory and then copies the compressed file to the NAS.