Sunday, 11 August 2013

The Linux Alfresco Restore Script

For a few who wanted the equivalent restore script to the backup script Here it is. Tried and tested.

#!/bin/bash
e cho "=== Set up the environment ==="

Alfresco_root="/opt/alfresco-4.2.c";
Alfresco_repository="$Alfresco_root/alf_data/";
Alfresco_backup_dir="/home/philip/backup/";
DB_USER="postgres";
alfresco_db="alfresco";

echo "=== Stopping Alfresco ==="

sh $Alfresco_root/alfresco.sh stop
sleep 240

cd $Alfresco_root/tomcat/shared/classes

echo "=== copying the global properties file ==="
cp alfresco-global.properties.noindex alfresco-global.properties


echo "===  Alfresco stopped... ==="
echo "=== Starting Alfresco in Postgres only mode ==="

sh $Alfresco_root/alfresco.sh start postgresql


echo "=== Starting to restore the database ==="


dropdb -U $DB_USER  $alfresco_db -h localhost
createdb -U $DB_USER -T template0 $alfresco_db -h localhost


psql -h localhost -U $DB_USER  $alfresco_db < $Alfresco_backup_dir/alfrescodbdump*


sh $Alfresco_root/alfresco.sh stop postgresql

echo "=== Postgres is stopped Ready to copy over the database ==="

cd $Alfresco_root/alf_data
rm -rf contentstore
rm-rf contentstore.deleted
cp -r $Alfresco_backup_dir/alfresco-4.2.c.backup*/alf_data/contentstore  $Alfresco_root/alf_data/contentstore
cp -r $Alfresco_backup_dir/alfresco-4.2.c.backup*/alf_data/contentstore.deleted $Alfresco_root/alf_data/contentstore.deleted

echo "=== Put the global properties file back ==="

cd $Alfresco_root/tomcat/shared/classes
cp alfresco-global.properties.solr alfresco-global.properties

echo "=== Set up indexing ==="
rm -rf $Alfresco_root/alf_data/solr/workspace/SpacesStore
rm -rf $Alfresco_root/alf_data/solr/archive/SpacesStore
rm -rf $Alfresco_root/alf_data/solr/workspace-SpacesStore/alfrescoModels
rm -rf $Alfresco_root/alf_data/solr/archive-SpacesStore/alfrescoModels

echo "=== Restart Alfresco Building indices ==="

cd $Alfresco_root

sh $Alfresco_root/alfresco.sh start

3 comments:

  1. Hi Philipp,

    Thanks very much for your script !

    I've two comments/questions:

    Set up the environment:
    one should code Alfresco_backup_dir="/home/philip/backup"; instead of Alfresco_backup_dir="/home/philip/backup/";

    Files copying:
    Is it not better to use cp with option -p in oder to prserve permissions ?

    Best regards.

    ReplyDelete
  2. sorry, I forgot to sign my reply:

    Jean-Pierre Buttet

    Best regards.

    ReplyDelete
  3. As for your comments on the backdir yes it probably is better. My linux seems to be very forgiving on the extra /.
    I tried the cp -p option and thank you it seems to be better.

    ReplyDelete