#!/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