Created
April 13, 2013 13:22
-
-
Save tullo/5378388 to your computer and use it in GitHub Desktop.
Creates a cold backup of Alfresco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cold backup of Alfresco. | |
# | |
# Configuration. | |
ALF_HOME="/path/to/alfresco" | |
NUM_DUMP=10 | |
ALF_DATA_SUBDIR="alf_data" | |
DB_TYPE="postgresql" | |
DBNAME="alfresco" | |
DBUSER="alfresco" | |
# Check | |
if [ -d "$1" ]; then | |
TARGET_FOLDER="$1" | |
CURRENT_FOLDER="$(pwd)" | |
TIMESTAMP="$(date +%F_%H-%M)" | |
CHECK=1 | |
# 1) Alfresco stop. | |
service alfresco stop | |
# 2) Backup of the Alfresco database. | |
DB_DUMP=${TIMESTAMP}_alfresco_${DB_TYPE}.tar | |
if [ "$DB_TYPE" = "postgresql" ]; then | |
cd $TARGET_FOLDER | |
export PGPASSWORD="youralfrescodbpwd" | |
#echo "db.dump 'pg_dump -Ft -b -w -U $DBUSER $DBNAME > $TARGET_FOLDER/$DB_DUMP'" | |
pg_dump -Ft -b -w -U $DBUSER $DBNAME > $TARGET_FOLDER/$DB_DUMP | |
cd $CURRENT_FOLDER | |
if [ ! -f "$TARGET_FOLDER/$DB_DUMP" ]; then | |
CHECK=0 | |
fi | |
else | |
echo "Unknown database type '${DB_TYPE}'" | |
CHECK=0 | |
fi | |
# 3) Backup of Alfresco data folder. | |
if [ "$CHECK" = 1 ]; then | |
ALF_DUMP=${TIMESTAMP}_alfresco_data.tgz | |
cd $ALF_HOME | |
tar zcf $TARGET_FOLDER/$ALF_DUMP $ALF_DATA_SUBDIR | |
cd $CURRENT_FOLDER | |
if [ ! -f "$TARGET_FOLDER/$ALF_DUMP" ]; then | |
CHECK=0 | |
fi | |
fi | |
# 4) Merge the database and contentstore backups. | |
if [ "$CHECK" = 1 ]; then | |
BACKUP_FILE="${TIMESTAMP}_alfresco_dump.tgz" | |
cd $TARGET_FOLDER | |
tar zcf $BACKUP_FILE $ALF_DUMP $DB_DUMP | |
if [ ! -f "$BACKUP_FILE" ]; then | |
CHECK=0 | |
else | |
rm $ALF_DUMP | |
rm $DB_DUMP | |
fi | |
cd $CURRENT_FOLDER | |
fi | |
# 5) Alfresco start. | |
service alfresco start | |
# 6) Delete previous dumps older than a certains number of days. | |
if [ "$CHECK" = 1 ]; then | |
find $TARGET_FOLDER/*.tgz -type f -mtime +${NUM_DUMP} -exec rm {} \; | |
fi | |
else | |
echo "usage: $0 [targetPath]" | |
fi | |
# ./alfrescoBackup.sh /path/to/backup/folder | |
# | |
# origin @FrkCorti |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment