Copyright © 2017 Bart Massey
Blog Escape is a database scraper for Drupal sites. It digs the content out of a site by scraping the database and deposits it in well-formatted static files, ready for deployment elsewhere. It was intended for my blog, but will try to rescue as much of the Drupal site as possible.
Drupal breaks all the time. I used it as my blog site for many years (Drupal 4 through Drupal 7), but eventually it got to the point where it would neither run nor upgrade. This software is my solution for getting my old blog content back. (Except — LOL — my Drupal install mysteriously started working again the other day, with no obvious intervention on my part. I'm still going to finish this project, though.)
Blog Escape is written in Python 3 and currently targeted at Drupal 7 MySQL content.
This is a work in progress. Its current functionality is minimal, and its design is still in flux.
We will assume that the domain name of your sitename is
drupal.example.org.
-
This software requires the Python 3
MySQLDBmodule. Install it from your distro or withpip3. It also requires themistuneMarkdown parser, thebbcodeBBCode parser and thephpserializePHP deserializer, which can be installed in the same way. -
You will want to create a fresh copy of the Drupal database, just to avoid accidents. This should not be necessary, but better safe than sorry. If you're not familiar with creating a MySQL database, you may want to look at the manual before you start.
Create the database and user like this:
mysql <<<'EOF' CREATE DATABASE example_database; GRANT ALL ON example_database.* TO 'example_user'@'localhost' IDENTIFIED BY "example_password"; EOF -
Create
drupal-example-org.my.cnfwith the username, database name and password.[client] user="example_user" database="example_database" password="example_password" -
Use
mysql-dumpfrom your old database and then restore the dump into a new database using the config file you just created.mysql --defaults-extra-file=drupal-example-org.my.cnf <dump.sqlDanger: your old Drupal database and the new one are probably both completely screwed up with respect to the MySQL
utf8,utf8mb4andlatin1encodings. Dig around in the excellent series of reference cards starting here to figure out how to get a copy of the database with Unicode preserved. -
Find the
filesdirectory under your site directory in your Drupal installation. Copy it over andcdinto it. Usemv -f images/* . ; rmdir imagesto get all the old nested images out. Hope that there are no name collisions between images with different content. You can also remove thefiles→.symbolic link if you have one and would like. -
Run
python3 blog-escape.py drupal.example.org. -
Move the resulting
sitedirectory to the root of your new archive website. Adjust your webserver configuration as needed.
See the GitHub Development Project Board for pending and completed development tasks.
-
Currently only works (read "has been tested") for Drupal sites that use a site-specific domain name for the root URL.
-
Please see the GitHub Issues for other pending issues.
This work is made available under the MIT license. Please
see the file COPYING in this distribution for license terms.