Learn how to import Wikibase items and properties from one with into another.
Transferring items and properties from one wiki to another is not that difficult if you know which steps to take. This post describes a 3 step process using the primary import/export mechanism of MediaWiki. This process retains your item and property IDs and (optionally) your revision history. It also works well between different versions of MediaWiki and Wikibase.
Step 1: create an XML dump
php maintenance/dumpBackup.php --full --quiet --filter=namespace:120,122 > wikibase.xml
This command needs to be run on the command line from the root directory of your wiki. It creates a wikibase.xml
file which we will need in step 2.
If you wish to only export items, remove 122
(the property namespace) and the comma. Likewise, you can remove 120
(the item namespace) to only export properties. To export all wiki content, including talk pages, remove --filter=namespace:120,122
from the command. For more information, read the dumpBackup.php documentation.
If you do not have access to the wikis server, you can get an XML dump via Special:Export.
Step 2: import the XML dump
Copy the wikibase.xml
file to the root directory of the wiki where you wish to do the import. Then run this command on the command line:
php maintenance/importDump.php < ../wikibase.xml
For large imports, it will take a while for the script to finish. If it completes without an error it outputs “Done!”. Likely you will get the following error instead:
To avoid ID conflicts, the import of Wikibase entities is not supported. You can enable imports using the “allowEntityImport” setting.
This error is expected, as Wikibase by default, and for good reason, does not allow importing items and properties. To temporarily enable such imports, add the following to the end of LocalSettings.php
and rerun the importDump.php
command. After the command has run, disable imports again by removing the line from LocalSettings.php
.
$wgWBRepoSettings['allowEntityImport'] = true;
For more information, read the MediaWiki XML import documentation.
Step 3: run rebuild scripts
Run these commands from the root directory of the wiki where you did the import:
php maintenance/rebuildall.php
php maintenance/runJobs.php
php maintenance/initSiteStats.php --update
Step 4: optionally enable entity creation
After the import, creating new items or properties via pages such as Special:NewItem will fail. This is because Wikibase will try to create Item:Q1, without realizing it already exists.
If that is an issue for your wiki, you will need to fix the values in the wb_id_counters
table. This can be done via a script we created.
First download the script to your wiki root directory. For instance with curl:
curl https://gist.githubusercontent.com/JeroenDeDauw/c86a5ab7e2771301eb506b246f1af7a6/raw/rebuildWikibaseIdCounters.sql -o rebuildWikibaseIdCounters.sql
Then execute it with
php maintenance/sql.php rebuildWikibaseIdCounters.sql
The script might take a long time to run if you have many items.
Leave a comment with your experiences or questions below this post.
We provide many professional Wikibase services, including import/export.
Can I use php maintenance/importDump.php to import a full JSON dump file from here?
If you are talking about a Wikidata JSON dump, then no. The JSON dump has a different structure. It only contains the entity data, and no information about the page or its revisions. It can thus not be imported via the standard MediaWiki mechanism (importDump.php).
Do you have any suggestion about how can I import some PNodes and QNodes from Wikidata?
Thanks for this very useful post.
I use it for backup/restore.
But after restoring data from scratch using those steps (2, 3 and 4) import and rebuild, the blazegragh is not updated and so SPARQL query results are empty.
Do you have any clue to propagate import into blazegraph?