AnsweredAssumed Answered

Alfresco 5.0c backup script WINDOWS

Question asked by drisschelouati on May 28, 2015
Latest reply on May 29, 2015 by drisschelouati
Hi everyone,

iam currently trying to set up a beckup strategy for our installation of alfresco. Reading a lot of tutorials about alfresco backup scripts, i noticed they are mostly written for LINUX systems, and the few i could find for windows are getting slightly old.

I wanted to submit to the forum a sample script that i modified from a linux version, to get some advice from specialists, just to know if iam on the right way.

Tutorials also speak about creating a .pgpass file with the following content :


*:*:*:postgres:[DB-PASSWORD]


is this LINUX specific, or does it have to be done in WINDOWS too? if it's the case, where should i put that file?

here is the script, please tell me if everything is ok, i haven't tested it yet, not being sure of what ive wrote because it is a port of a shell script:




# Archive Dynamics script - Backup of Alfresco

# Configuration:
  CURRENT_FOLDER=$(pwd)            # Script folder
  TIMESTAMP=$( date +%Y%m%d%H%M%S )      # Create timestamp
  DUMP_NUM=10               # Number of backups to keep
  AL_FOLDER="C:\alfresco"         # Alfresco folder
  AL_DATA="C:\alfresco\alf_data"      # Alfresco data folder
  DB_HOME="C:\alfresco\postgresql"      # PostgreSQL folder


# Function - Stop Alfresco
function al_stop()
{
  $AL_FOLDER\servicerun STOP

  # If Alfresco does not stop we MUST exit script
  # Backing up files with Alfresco working may
  # corrupt data indexes!!
  if [ "$?" != "0" ]; then
    echo "Alfresco Stop FAILED - STOP SCRIPT!"
    exit 1;
  fi
}


# Function - Start Alfresco
function al_start()
{
  $AL_FOLDER\servicerun START
}


# Function - Start PostgreSQL Server
function p_start()
{
  $DB_HOME\scripts\servicerun START
}


# Verify that argument was provided
if [ -d "$1" ]; then
  # A folder has been provided, save it
  TARGET_FOLDER="$1"
else
  # No argument was provided for backup location
  echo "Usage: $0 [TARGET_PATH]"
  exit 0
fi



#—————————————-
# 1 - Begin by stopping Alfresco
#—————————————-
  al_stop


#—————————————-
# 2 - Backup the Alfresco database
#—————————————-
  # Start the postgreSQL database (which is stopped automatically
  # by the Alfresco stop script)
  p_start

  # Create a filename for the database tar
  DB_DUMP=alfresco_db_${TIMESTAMP}.tar

  # Backup the database to the target folder
  # -Ft = Export database as tar file
  $DB_HOME\bin\pg_dump -Ft alfresco > $TARGET_FOLDER\$DB_DUMP

  # Check if an error was returned
  if [ "$?" = "0" ]; then
    echo "DB EXPORT WORKED!"
  else
    echo "DB EXPORT FAILED!"
  fi

#——————————————
# 3 - Backup the Alfresco content folder
#——————————————
  # Create a file name with timestamp
  AL_DUMP=alfresco_data_${TIMESTAMP}.tgz

  # Tar the Alfresco data folder to the backup
  # to the backup folder specified
  tar zcf $TARGET_FOLDER\$AL_DUMP $AL_DATA

#——————————————
# 4 - Merge the database and data files
#——————————————

  # Create a backup filename with timestamp
  BACKUP_FILE="$alfresco_bak_${TIMESTAMP}.tgz"
  tar zcf $TARGET_FOLDER\$BACKUP_FILE $TARGET_FOLDER\$AL_DUMP $TARGET_FOLDER\$DB_DUMP

  # If files were merged, delete the duplicates
  if [ -f "$TARGET_FOLDER\$BACKUP_FILE" ]; then
    echo "BACKUP SUCCESSFUL"
    rm $TARGET_FOLDER\$AL_DUMP
    rm $TARGET_FOLDER\$DB_DUMP
    SUCCESS=1
  fi

#——————————————
# 5 - We're done, start the Alfresco service
#——————————————
  al_start

#——————————————
# 6 - Remove backups older than DUMP_NUM days
#——————————————
  if [ "$SUCCESS" = 1 ]; then
    find $TARGET_FOLDER\*.tgz -type f -mtime +${DUMP_NUM} -exec rm {} \;
  fi



As i understood, if it's ok and works, i should set the execution with a windows schedueled task. Is it recommended to script SOL4 indexes backup too?

Thanks for your help

Outcomes