Backup your Blackblogs or Noblogs page using a bash script

Backup your Blackblogs or Noblogs page using a bash script

Edit: There is now an import and export option in the backend settings for both Noblogs and Blackblogs. But keep reading if, for example, you lost your access credentials.

Noblogs and blackblogs are popular platforms for anonymous publishers from the subversive spectrum. You can register there and get access to your own preconfigured Wordpress instance.

For safety reasons, however, the options there are very limited. For example, it is not possible to install your own Wordpress plugins or use your own themes.

Also, it is not possible to download a full backup of your websites. You may have had a Blackblogs or Noblogs site for a long time and never thought about backing up your content.

Sometimes the sites are also exposed to DDoS attacks and cannot be reached for a long time. There is also a risk that the pages may suddenly disappear. This was shown, for example, by the repression against linksunten.indymedia.de.

For this reason I wrote a bash script that can backup all public content from your sites via the Wordpress API. Please understand that posts and pages that are in draft status or trash status cannot be saved. In general, only content that is published is backed up.

Install dependencys

# Install curl and jq
sudo apt install -y jq curl

First you have to install curl and jq. Curl is a popular HTTP client. We will use it to download all the public content from your page. Jq is a JSON parser. It will be used to parse the Wordpress API responses.

Run the backup

Download the following script and name it backup.sh Replace XXXXXXXX with the Name of your blog. Do not forget to make the script executable: chmod +x backup.sh

#!/bin/bash

HOST=https://XXXXXXXX.noblogs.org

# Create a new folder for the current date
DATE="$(date +"%Y-%m-%d")"
mkdir $DATE
cd $DATE

# Download all public data as JSON
mkdir json
cd json
curl -X GET "$HOST/wp-json/wp/v2/posts" > posts.json
curl -X GET "$HOST/wp-json/wp/v2/pages" > pages.json
curl -X GET "$HOST/wp-json/wp/v2/media" > media.json
curl -X GET "$HOST/wp-json/wp/v2/categories" > categories.json
curl -X GET "$HOST/wp-json/wp/v2/comments" > comments.json
cd ..

# Generate post HTML file
curl -X GET "$HOST/wp-json/wp/v2/posts" | jq -r '.. |.content ? | select(. != null) .rendered' > posts.html

# Generate pages HTML file
curl -X GET "$HOST/wp-json/wp/v2/pages" | jq -r '.. |.content ? | select(. != null) .rendered' > pages.html

# Download all media files
mkdir media
cd media
# Download a list of all public media and use JQ to parse the full files
curl -X GET "$HOST/wp-json/wp/v2/media" | jq -r '.. |.full ? | select(. != null) .source_url' > download-files.tmp
# Use xargs and curl again to download the file list
xargs -n 1 curl -O < download-files.tmp
rm download-files.tmp
cd ..

# Go back to start dir
cd ..

Then run the script by calling ./backup.sh

The script will automatically create a new folder with the current date as the name. Inside you will find a posts.html and a pages.html file. This files contain the HTML of all pages and posts. There is also a folder called media. This contains all the images. The json folder contains a lot of data in machine-readable format. It contains a lot of metadata about posts, pages and media.

Restore the backup

Unfortunately, this is only a pure backup solution without a simple restore function. In an emergency, you have to create all posts, pages and media again by hand. You can simply copy them from the folders and HTML files into a Wordpress backend. The important thing is that you still have them. Theoretically, it is also possible to write software that imports the JSON files again. But that's a job for experienced programmers.

Keep publishing!

Title image: Dall-E 2 "a masked hacker stealing data from a computer inside a dark server room as water color"