Friday, 31 May 2013

Alfresco Automated Backup Script Linux

Backups are a pain and as our system is used more and more the need for more regular and controlled backups has been demanding. Doing the system manually for a while has given an idea of where the problems are. We do an automated backup every night of the whole machine, but this does not include an Alfresco database schema and when we have tried to recover the database the solar indexing has made the backups useless.
The basic backup mechanism I have given before, so here is a simple I have been using which works.

I run the script as root and have made a .pgpass file in the root directory with the database password in it.
*:*:*:postgres:topsecret
This file is chmoded at 600

The backup Script for Linux is run by a cron. Each time it is run a new dated backup is made. These are periodically removed as they get to old.

#!/bin/bash
echo "=== Set up the environment ==="

Days=`date +%Y%m%d-%H%M%S`;
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 "=== Now restarting and stopping Alfresco to stop indexing ==="

sh $Alfresco_root/alfresco.sh start
sleep 300

echo "=== Alfresco up indexed stopped. Now shutting down ==="
sh $Alfresco_root/alfresco.sh stop

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

sh $Alfresco_root/alfresco.sh start postgresql

echo "=== Make Postgres Backup ==="

pg_dump -h localhost -U $DB_USER  $alfresco_db > $Alfresco_backup_dir/alfrescodbdump$Days

sh $Alfresco_root/alfresco.sh stop postgresql
echo "=== Postgres backed up and Alfresco stopped ==="


echo "=== Creating Aflresco Repository Backup ==="


cp $Alfresco_root $Alfresco_backup_dir/alfresco-4.2.c.backup$Days -R
echo "=== copy back the properties file ==="

cp alfresco-global.properties.solr alfresco-global.properties
echo "=== Restarting Alfresco ... All done ==="

cd $Alfresco_root


sh $Alfresco_root/alfresco.sh start 

4 comments:

  1. Hi Philip,
    thanks, really useful script!

    ReplyDelete
  2. Just to ask, I do not have a 'alfresco-global.properties.solr' or 'alfresco-global.properties.noindex' file. I do of course have the ''alfresco-global.properties' however. I am on version 4.2.d. Does it matter that these files are missing or will the backup be good enough without them?
    Thanks

    ReplyDelete
    Replies
    1. The two files 'alfresco-global.properties.solr' and 'alfresco-global.properties.noindex' are copies of ''alfresco-global.properties'

      The difference in them is at the end of the file.
      alfresco-global.properties.solr
      has
      ### Solr indexing ###
      index.subsystem.name=solr
      dir.keystore=${dir.root}/keystore
      solr.port.ssl=8443

      and the alfresco-global.properties.noindex file has

      ### Solr indexing ###
      index.subsystem.name=noindex
      dir.keystore=${dir.root}/keystore
      solr.port.ssl=8443

      I should have put this in the script

      It is a lazy way of changing the contents of the file.

      Delete
  3. Hi Phillips, thanks for the reply and just to add I have tried a few other scripts since testing yours but yours works the best!
    Russ

    ReplyDelete