As an Alfresco developer/administrator, you probably already made a few mistakes in your DEV environment while trying to add new features, a custom model or something like that. The result of that mistake might be a corrupted Database or Content Store. Yes I know it’s hard to recognize it! But then what can be done to solve the issue and restore an usable installation? Well if you don’t have a backup or don’t want to do that because it will take some time to restore a clean backup and you want to work immediately then a good solution might need to actually cleanup your entire installation.

Using a few commands or a simple script, your Alfresco can be cleaned very easily and quickly to let you continue your development using a fresh and working installation. In this blog, I will therefore show you a few commands that help me to clean an Alfresco environment (Community or Enterprise).

Basically when talking about corruption in Alfresco, here are the different components that can be affected:

  • Database
  • Content Store (documents in File System)
  • Search Index
  • War Files & Extensions (AMPs & extension + web-extension folders) – Not covered in this blog as this kind of corruption will be solved by deploying a corrective version of the AMP or removing the faulty configuration in the extension or web-extension folders

Cleaning an Alfresco installation is in fact just like simulating a corruption of all components mentioned above without any backup available and therefore some necessary steps need to be taken to solve this corruption.

So let’s start our simulation with the first bullet point. The first thing to do is to stop the Alfresco installation and only let the Database running. Depending on how you built your Alfresco Installation, the commands can differ a little bit: are you using one service for Alfresco + Database or one service for Alfresco or no service at all? On my DEV environment, one service is managing all Alfresco components:

[email protected]:$ service alfresco stop
[email protected]:$ service alfresco start postgresql

As you can see above, I’m using postgresql. Of course if you are using MySQL or any other Database, please adapt the commands accordingly! When Alfresco is stopped, the next step is to drop and recreate the database. This can be done using scripts provided by Alfresco:

[email protected]:$ /opt/alfresco/postgresql/bin/dropdb alfresco
       => Password asked

[email protected]:$ /opt/alfresco/postgresql/bin/createdb alfresco
       => Password asked

Or manually:

[email protected]:$ /opt/alfresco/postgresql/bin/psql
postgres=# DROP DATABASE alfresco;
postgres=# CREATE DATABASE alfresco WITH OWNER alfresco;
postgres=# GRANT ALL PRIVILEGES ON DATABASE alfresco TO alfresco;
postgres=# q

If you are using MySQL instead of PostgreSQL, then it will be something like that:

mysql> drop database alfresco;
mysql> create database alfresco default character set utf8 collate utf8_bin;
mysql> grant all on alfresco.* to 'alfresco'@'localhost' identified by 'alfresco_pwd' with grant option;

Now the Database has been cleaned and you need to align the File System to avoid inconsistencies (bullet points 2 and 3). This is really simple since we just remove the files. The following commands assume that the war file of solr4 has been deployed in the webapps folder of Tomcat and this folder /opt/alfresco/alf_data/solr4 only contain the model and index:

[email protected]:$ rm -rf /opt/alfresco/alf_data/contentstore/*
[email protected]:$ rm -rf /opt/alfresco/alf_data/contentstore.deleted/*
[email protected]:$ mv /opt/alfresco/alf_data/solr4 /opt/alfresco/alf_data/backup_solr4_$(date '+%Y%m%d_%H%M')

And… That’s all! Now you just have to restart your service and Alfresco will populate the database and create the necessary elements for the indexing during the first startup:

[email protected]:$ service alfresco stop postgresql
[email protected]:$ service alfresco start

It may take one or two minutes to boot the first time but this is usually much more faster than restoring a complete database schema! By doing that, you will of course loose any document stored in Alfresco but for a development phase, that’s usually OK.

Note: Just to let you know, doing that for an Alfresco Enterprise Edition (or Alfresco One) with a Trial License will also reset the counter to: 30 days remaining. That’s why I would recommend you to only do that with the Alfresco Community Edition on your DEV environment or if you have a valid License Key because I don’t really know if that’s authorized by Alfresco!

Thumbnail [60x60]
Morgan Patou