05-28-2015 07:23 AM
*:*:*:postgres:[DB-PASSWORD]
# 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
05-28-2015 11:45 AM
05-29-2015 06:07 AM
05-29-2015 12:12 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.