Резервное копирование и восстановление (Backup and recovery) Alfresco Community Edition
Буду признателен, если в данной теме кто-либо поделится опытом резервирования и восстановления серверов Alfresco.
В свою очередь предлагаю на обозрение несколько скриптов:
1) Холодное резервное копирование: есть отступление от официальной документации, т.к. выполняется простой файловый бэкап директории установки альфреско при полностью остановленном сервере. Можно просто настроить бэкапирование через rsync демон чразу на резервный хост, это будет более правильно, т.к. не будет расходоваться локальныное место под архив. Пример будет в следующем скрипте (для горячего резервного копирования.
#!/bin/bash
# This script perform cold full backup Alfresco CMS
# Start 17.01.2013
# Outputs the time the backup started, for log/tracking purposes
echo Time backup started = $(date +%T)
before="$(date +%s)"
# Live sync before stopping Alfresco to minimize sync time with the services down
# Comment out the following 2 lines if you want to try single cold-sync only
echo "Syncronize beafore backup ..."
rsync -aHK --delete /opt/alfresco/ /opt/backup/alfresco
# which is the same as: /opt/alfresco /opt/backup/alfresco
# Including --delete option gets rid of files in the dest folder that don't exist at the src.
# this prevents logfile/extraneous bloat from building up overtime.
# Now we need to shut down Alfresco to rsync any files that were/are locked
# whilst backing up when the server was up and running.
before2="$(date +%s)"
# Stop Alfresco Services
echo Time befor stop Alfresco services = $(date +%T)
echo "Stop Alfresco services ..."
/opt/alfresco/alfresco.sh stop
sleep 10
echo Time after stop Alfresco services = $(date +%T)
# Sync to backup directory
echo "Syncronize to backup directory ..."
rsync -aHK --delete /opt/alfresco/ /opt/backup/alfresco
# Start Alfresco Services
echo Time befor start Alfresco services = $(date +%T)
echo "Start Alfresco services ..."
cd /opt/alfresco/tomcat/logs
/opt/alfresco/alfresco.sh start
echo Time after start Alfresco services = $(date +%T)
# Calculates and outputs amount of time the server was down for
after="$(date +%s)"
elapsed="$(expr $after - $before2)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Server was down: "$hours hours $minutes minutes $seconds seconds"
# Create a txt file in the backup directory that'll contains the current Alfresco properties
# server version. Handy for knowing what version of Alfresco a backup can be restored to.
cp /opt/alfresco/properties.ini /opt/backup/alfresco/alfresco_version.txt
# Display Alfresco services status
echo Displaying Alfresco services status...
/opt/alfresco/alfresco.sh status
# Create archive of backed-up directory for offsite transfer
echo "Create archive of backed-up directory for offsite transfer..."
tar -zcf /opt/alfresco.tar.gz -C /opt/backup/alfresco .
# Transfer backup to FTP server
echo "Transfer backup archive to ftp server ..."
cd /opt
curl -T /opt/alfresco.tar.gz ftp://user:<pwd>@server
# Delete archive
rm /opt/alfresco.tar.gz
# Outputs the time the backup finished
echo Time backup finished = $(date +%T)
# Calculates and outputs total time taken
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Time taken: "$hours hours $minutes minutes $seconds seconds"
2) Скрипт для горячего резервного копирования с использованием rsync демона на удаленной машине:
#!/bin/bash
# This script perform hot backup Alfresco CMS to remote host
# 24.01.2013: Start AlexG
# Outputs the time the backup started, for log/tracking purposes
echo Time backup started = $(date +%T)
### Time when backup is started
before="$(date +%s)"
########################
# Set environment:
########################
### SQL env ###############
# Optional hostname to adhere to pg_hba policies. Will default to "localhost" if none specified.
HOSTNAME="localhost"
#Optional port to connect to database. Will default to "5432" if none specified.
PGPORT="5432"
# Optional username to connect to database as. Will default to "postgres" if none specified.
USERNAME="postgres"
# PG password
export PGPASSWORD=<pwd>
# This dir will be created if it doesn't exist. This must be writable by the user the script is running as.
BACKUP_DIR="/opt/backup/sql/"
# Optional database name to connect. Will default to "alfresco" if none specified.
DATABASE="alfresco"
### Transfer env ###########
# remote host for transfering
RHOST="<IP_address>"
# Remote user for connect to remote host
RUSER=<r_user>
# Sourse directory for bakuping
FILE_FROM=/opt/alfresco/alf_data/
# SQL dump share on remote host
SQL_DUMP=sql_dump
# Share on remote host to content files
SHARE_DIR_TO=alf_data
###################
# SQL Backup #
###################
echo "Start SQL backup ..."
## Initialise defaults:
if [ ! $HOSTNAME ]; then
HOSTNAME="localhost"
fi;
if [ ! $USERNAME ]; then
USERNAME="postgres"
fi;
if [ ! $PGPORT ]; then
PGPORT="5432"
fi;
if [ ! $DATABASE ]; then
DATABASE="alfresco"
fi;
## Dump Database
/opt/alfresco/postgresql/bin/pg_dump -h "$HOSTNAME" -p "$PGPORT" -U "$USERNAME" -Fc "$DATABASE" > "$BACKUP_DIR"alfresco.dump
#############################################################
# File directory backup and transfer backupset (content+sql)#
#############################################################
echo Transfer DB dump ...
rsync -auvHK --delete "$BACKUP_DIR" $RUSER@$RHOST::$SQL_DUMP
echo Time after Backup and transfer DB = $(date +%T)
# Sync to backup directory
echo "Backup and transfer File directory ..."
rsync -auvHK --delete --exclude='postgresql*' $FILE_FROM $RUSER@$RHOST::$SHARE_DIR_TO
echo Time after backup and transfer File directory = $(date +%T)
echo Backup finished.
##########################################
# Calculates and outputs total time taken#
##########################################
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Time taken: "$hours hours $minutes minutes $seconds seconds"
3) Скрипт для восстановления. Подразумевается, что имя и IP уже установлены в значения как у боевого сервера, а файлы копировались rsync-ом сразу в alf_data, т.е. их восстанавливать не надо:
#!/bin/bash
# This script automate restore Alfresco CMS after remote backup via rsync. Restore procedure include next steps:
# 1. Restore the database from the database backups and update statistics for all tables in the Alfresco
# schema (consult your DBA for the details on how to do this, as it varies from database to database).
# 2. Start Alfresco
# Changes:
# 24.01.2013: Start AlexG
# 1. Restore the database from the database backups and update statistics for all tables in the Alfresco
# schema (consult your DBA for the details on how to do this, as it varies from database to database).
######################
# Restore SQL Backup #
######################
## Set environment:
# Optional hostname to adhere to pg_hba policies. Will default to "localhost" if none specified.
HOSTNAME="localhost"
#Optional port to connect to database. Will default to "5432" if none specified.
PGPORT="5432"
# Optional username to connect to database as. Will default to "postgres" if none specified.
USERNAME="postgres"
export PGPASSWORD=<our pwd>
# This dir will be created if it doesn't exist. This must be writable by the user the script is running as.
BACKUP_DIR="/opt/backup/sql/"
# Optional database name to connect. Will default to "alfresco" if none specified.
DATABASE="alfresco"
## Initialise defaults:
if [ ! $HOSTNAME ]; then
HOSTNAME="localhost"
fi;
if [ ! $USERNAME ]; then
USERNAME="postgres"
fi;
if [ ! $PGPORT ]; then
PGPORT="5432"
fi;
if [ ! $DATABASE ]; then
DATABASE="alfresco"
fi;
# Start POSTGRESQL
su - postgres -c "/opt/alfresco/postgresql/bin/pg_ctl start -w -D /opt/alfresco/alf_data/postgresql"
## Restore Database dump
/opt/alfresco/postgresql/bin/pg_restore -h "$HOSTNAME" -p "$PGPORT" -U "$USERNAME" -c -d "$DATABASE" "$BACKUP_DIR"alfresco.dump
# Stop POSTGRESQL
su - postgres -c "/opt/alfresco/postgresql/bin/pg_ctl stop -D /opt/alfresco/alf_data/postgresql"
echo Time after Restore Backup SQL = $(date +%T)
# 2. Start Alfresco
echo Time befor start Alfresco services = $(date +%T)
echo "Start Alfresco services ..."
cd /opt/alfresco/tomcat/logs
/opt/alfresco/alfresco.sh start
echo Time after start Alfresco services = $(date +%T)
В свою очередь предлагаю на обозрение несколько скриптов:
1) Холодное резервное копирование: есть отступление от официальной документации, т.к. выполняется простой файловый бэкап директории установки альфреско при полностью остановленном сервере. Можно просто настроить бэкапирование через rsync демон чразу на резервный хост, это будет более правильно, т.к. не будет расходоваться локальныное место под архив. Пример будет в следующем скрипте (для горячего резервного копирования.
#!/bin/bash
# This script perform cold full backup Alfresco CMS
# Start 17.01.2013
# Outputs the time the backup started, for log/tracking purposes
echo Time backup started = $(date +%T)
before="$(date +%s)"
# Live sync before stopping Alfresco to minimize sync time with the services down
# Comment out the following 2 lines if you want to try single cold-sync only
echo "Syncronize beafore backup ..."
rsync -aHK --delete /opt/alfresco/ /opt/backup/alfresco
# which is the same as: /opt/alfresco /opt/backup/alfresco
# Including --delete option gets rid of files in the dest folder that don't exist at the src.
# this prevents logfile/extraneous bloat from building up overtime.
# Now we need to shut down Alfresco to rsync any files that were/are locked
# whilst backing up when the server was up and running.
before2="$(date +%s)"
# Stop Alfresco Services
echo Time befor stop Alfresco services = $(date +%T)
echo "Stop Alfresco services ..."
/opt/alfresco/alfresco.sh stop
sleep 10
echo Time after stop Alfresco services = $(date +%T)
# Sync to backup directory
echo "Syncronize to backup directory ..."
rsync -aHK --delete /opt/alfresco/ /opt/backup/alfresco
# Start Alfresco Services
echo Time befor start Alfresco services = $(date +%T)
echo "Start Alfresco services ..."
cd /opt/alfresco/tomcat/logs
/opt/alfresco/alfresco.sh start
echo Time after start Alfresco services = $(date +%T)
# Calculates and outputs amount of time the server was down for
after="$(date +%s)"
elapsed="$(expr $after - $before2)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Server was down: "$hours hours $minutes minutes $seconds seconds"
# Create a txt file in the backup directory that'll contains the current Alfresco properties
# server version. Handy for knowing what version of Alfresco a backup can be restored to.
cp /opt/alfresco/properties.ini /opt/backup/alfresco/alfresco_version.txt
# Display Alfresco services status
echo Displaying Alfresco services status...
/opt/alfresco/alfresco.sh status
# Create archive of backed-up directory for offsite transfer
echo "Create archive of backed-up directory for offsite transfer..."
tar -zcf /opt/alfresco.tar.gz -C /opt/backup/alfresco .
# Transfer backup to FTP server
echo "Transfer backup archive to ftp server ..."
cd /opt
curl -T /opt/alfresco.tar.gz ftp://user:<pwd>@server
# Delete archive
rm /opt/alfresco.tar.gz
# Outputs the time the backup finished
echo Time backup finished = $(date +%T)
# Calculates and outputs total time taken
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Time taken: "$hours hours $minutes minutes $seconds seconds"
2) Скрипт для горячего резервного копирования с использованием rsync демона на удаленной машине:
#!/bin/bash
# This script perform hot backup Alfresco CMS to remote host
# 24.01.2013: Start AlexG
# Outputs the time the backup started, for log/tracking purposes
echo Time backup started = $(date +%T)
### Time when backup is started
before="$(date +%s)"
########################
# Set environment:
########################
### SQL env ###############
# Optional hostname to adhere to pg_hba policies. Will default to "localhost" if none specified.
HOSTNAME="localhost"
#Optional port to connect to database. Will default to "5432" if none specified.
PGPORT="5432"
# Optional username to connect to database as. Will default to "postgres" if none specified.
USERNAME="postgres"
# PG password
export PGPASSWORD=<pwd>
# This dir will be created if it doesn't exist. This must be writable by the user the script is running as.
BACKUP_DIR="/opt/backup/sql/"
# Optional database name to connect. Will default to "alfresco" if none specified.
DATABASE="alfresco"
### Transfer env ###########
# remote host for transfering
RHOST="<IP_address>"
# Remote user for connect to remote host
RUSER=<r_user>
# Sourse directory for bakuping
FILE_FROM=/opt/alfresco/alf_data/
# SQL dump share on remote host
SQL_DUMP=sql_dump
# Share on remote host to content files
SHARE_DIR_TO=alf_data
###################
# SQL Backup #
###################
echo "Start SQL backup ..."
## Initialise defaults:
if [ ! $HOSTNAME ]; then
HOSTNAME="localhost"
fi;
if [ ! $USERNAME ]; then
USERNAME="postgres"
fi;
if [ ! $PGPORT ]; then
PGPORT="5432"
fi;
if [ ! $DATABASE ]; then
DATABASE="alfresco"
fi;
## Dump Database
/opt/alfresco/postgresql/bin/pg_dump -h "$HOSTNAME" -p "$PGPORT" -U "$USERNAME" -Fc "$DATABASE" > "$BACKUP_DIR"alfresco.dump
#############################################################
# File directory backup and transfer backupset (content+sql)#
#############################################################
echo Transfer DB dump ...
rsync -auvHK --delete "$BACKUP_DIR" $RUSER@$RHOST::$SQL_DUMP
echo Time after Backup and transfer DB = $(date +%T)
# Sync to backup directory
echo "Backup and transfer File directory ..."
rsync -auvHK --delete --exclude='postgresql*' $FILE_FROM $RUSER@$RHOST::$SHARE_DIR_TO
echo Time after backup and transfer File directory = $(date +%T)
echo Backup finished.
##########################################
# Calculates and outputs total time taken#
##########################################
after="$(date +%s)"
elapsed="$(expr $after - $before)"
hours=$(($elapsed / 3600))
elapsed=$(($elapsed - $hours * 3600))
minutes=$(($elapsed / 60))
seconds=$(($elapsed - $minutes * 60))
echo Time taken: "$hours hours $minutes minutes $seconds seconds"
3) Скрипт для восстановления. Подразумевается, что имя и IP уже установлены в значения как у боевого сервера, а файлы копировались rsync-ом сразу в alf_data, т.е. их восстанавливать не надо:
#!/bin/bash
# This script automate restore Alfresco CMS after remote backup via rsync. Restore procedure include next steps:
# 1. Restore the database from the database backups and update statistics for all tables in the Alfresco
# schema (consult your DBA for the details on how to do this, as it varies from database to database).
# 2. Start Alfresco
# Changes:
# 24.01.2013: Start AlexG
# 1. Restore the database from the database backups and update statistics for all tables in the Alfresco
# schema (consult your DBA for the details on how to do this, as it varies from database to database).
######################
# Restore SQL Backup #
######################
## Set environment:
# Optional hostname to adhere to pg_hba policies. Will default to "localhost" if none specified.
HOSTNAME="localhost"
#Optional port to connect to database. Will default to "5432" if none specified.
PGPORT="5432"
# Optional username to connect to database as. Will default to "postgres" if none specified.
USERNAME="postgres"
export PGPASSWORD=<our pwd>
# This dir will be created if it doesn't exist. This must be writable by the user the script is running as.
BACKUP_DIR="/opt/backup/sql/"
# Optional database name to connect. Will default to "alfresco" if none specified.
DATABASE="alfresco"
## Initialise defaults:
if [ ! $HOSTNAME ]; then
HOSTNAME="localhost"
fi;
if [ ! $USERNAME ]; then
USERNAME="postgres"
fi;
if [ ! $PGPORT ]; then
PGPORT="5432"
fi;
if [ ! $DATABASE ]; then
DATABASE="alfresco"
fi;
# Start POSTGRESQL
su - postgres -c "/opt/alfresco/postgresql/bin/pg_ctl start -w -D /opt/alfresco/alf_data/postgresql"
## Restore Database dump
/opt/alfresco/postgresql/bin/pg_restore -h "$HOSTNAME" -p "$PGPORT" -U "$USERNAME" -c -d "$DATABASE" "$BACKUP_DIR"alfresco.dump
# Stop POSTGRESQL
su - postgres -c "/opt/alfresco/postgresql/bin/pg_ctl stop -D /opt/alfresco/alf_data/postgresql"
echo Time after Restore Backup SQL = $(date +%T)
# 2. Start Alfresco
echo Time befor start Alfresco services = $(date +%T)
echo "Start Alfresco services ..."
cd /opt/alfresco/tomcat/logs
/opt/alfresco/alfresco.sh start
echo Time after start Alfresco services = $(date +%T)
Комментарии
30/01/2013 - 10:08
Alfresco Cold Backup