Sometimes for some unknown reason alfresco crashes after I upload some documents. To be able to work with alfresco again each time this happens I need to reinstall alfresco which takes quite a long time. But basically what I want to do is to wipe alfresco database. To do it I’ve created a following script:

/opt/alfresco-5.0.a/alfresco.sh stop
echo -e "\e[32mAlfresco stopped\e[0m"
/opt/alfresco-5.0.a/postgresql/scripts/ctl.sh start
echo -e "\e[32mPostgres started\e[0m"
dropdb -h localhost -U postgres alfresco
echo -e "\e[32mDatabase dropped\e[0m"
createdb -h localhost -U postgres -O alfresco alfresco
echo -e "\e[32mDatabase created\e[0m"
/opt/alfresco-5.0.a/postgresql/scripts/ctl.sh stop
echo -e "\e[32mPostgres stopped\e[0m"
cd /opt/alfresco-5.0.a/alf_data
find -maxdepth 1 ! \( -name 'solr' -o -name 'postgresql' -o -name 'keystore' -o -name '.' \) -type d -exec rm -rf {} +
echo -e "\e[32malf_data cleaned\e[0m"
rm -rf /opt/alfresco-5.0.a/alf_data/solr/workspace/SpacesStore
rm -rf /opt/alfresco-5.0.a/alf_data/solr/archive/SpacesStore
rm -rf /opt/alfresco-5.0.a/alf_data/solr/workspace-SpacesStore/alfrescoModels
rm -rf /opt/alfresco-5.0.a/alf_data/solr/archive-SpacesStore/alfrescoModels
echo -e "\e[32mSolr cleaned\e[0m"

Here are some explanations. First thing you need to do is to stop alfresco just to be sure that it’s not running:

/opt/alfresco-5.0.a/alfresco.sh stop

Then start postgres and recreate database by dropping it and create. Be sure that the proper user owns the database you create. You can also keep the table and just drop all the tables in it. But first method works better. And then stop postgres.

/opt/alfresco-5.0.a/postgresql/scripts/ctl.sh start
dropdb -h localhost -U postgres alfresco
createdb -h localhost -U postgres -O alfresco alfresco
/opt/alfresco-5.0.a/postgresql/scripts/ctl.sh stop

And the last step is to clear Solr index. For more information you can refer to this article: Performing a full reindex with Solr.

rm -rf /opt/alfresco-5.0.a/alf_data/solr/workspace/SpacesStore
rm -rf /opt/alfresco-5.0.a/alf_data/solr/archive/SpacesStore
rm -rf /opt/alfresco-5.0.a/alf_data/solr/workspace-SpacesStore/alfrescoModels
rm -rf /opt/alfresco-5.0.a/alf_data/solr/archive-SpacesStore/alfrescoModels

That’s it!