General Actions:
| Tool for porting attachments from the database to the flesystem store |
| Type | Snippet |
| Developed by | Caleb James DeLisle |
| License | GNU Lesser General Public License 2.1 |
| Compatibility | version 2.0: 3.4+ |
Table of contents
With the new filesystem based attachment storage engine, you can save attachments without placing load on the database. You can also save very large (over 1 gigabyte) attachments. However all of your existing attachments are still in the database and schemes such as checking the filesystem and then the database or automatically porting the attachments out were judged to be complex and magical, both attributes which in storage we want to avoid, the answer is to use a script to move all of the attachments under the administrator's supervision.
When running the script, it will walk you through the process but a preview of the steps are as follows:
Edit your xwiki.cfg file by modifying the attachment store lines to read as follows:
Also make sure they are not commented out.
The storage section of my xwiki.cfg file reads as follows:
Since data is going to be stored on the filesystem, you need to make the directory where it is stored is backed up regularly.
Now you are ready to copy the data over from your database to the filesystem. It is prudent to leave the attachments in the database since in most situations the attachment data is not bothersome just sitting in the database (The only risk of attachments left in the database is that they will bloat the size of the database files). As such, this script contains no facility to delete entries from the database.
If anything goes wrong in this function, it will fail with an error message and you should get the stack trace, keep it to confuse and humiliate the developer with. No harm should be done since this only loads from the database and only saves to the filesystem.
Checking for corruption is recommended using the "dry run" option, you can also enable "verbose" to watch the list of attachments be printed to the screen as they are processed.
Once you click the "start" button, it will do the work in 20 second chunks and print the results of each chunk. It is doing something.
Check to make sure your attachments are still there, if an attachment is broken, it will appear to be there but on opening it will tell you the attachment does not exist. If something goes terribly wrong with filesystem attachment store, you may have your old attachment system back simply by changing the lines in the xwiki.cfg file and restarting the container. HOWEVER: This will not preserve attachments which were uploaded after switching to filesystem attachments so as users edit the system you will become locked in to filesystem attachments unless a script is written to do the inverse of this one.
Despite being experimental, the filesystem attachment storage is quite stable and the risk of actually losing something so that it is unrecoverable is very remote.
NOTE: This must be run seperately in each subwiki.
And that's all it is.
Copy the code snippet to a page and save it.
Release notes for version 2.0:
Handles large wikis much better, doing work in 20 second chunks.
Javascript front end prints attachments as they are processed.
Errors are explained better and stack traces are printed to the window rather than the log.
Dry run option to scan for corruption without saving files.