Suspend sites while backing up
This avoids backup verification failures
This commit is contained in:
parent
9fd09e55be
commit
91a670f11b
|
@ -49,13 +49,37 @@ fi
|
|||
ADMIN_USERNAME=
|
||||
ADMIN_NAME=
|
||||
|
||||
# The name of a currently suspended site
|
||||
# Sites are suspended so that verification should work
|
||||
SUSPENDED_SITE=
|
||||
|
||||
DATABASE_PASSWORD=''
|
||||
if [ -f /root/dbpass ]; then
|
||||
DATABASE_PASSWORD=$(cat /root/dbpass)
|
||||
fi
|
||||
|
||||
function suspend_site {
|
||||
# suspends a given website
|
||||
SUSPENDED_SITE="$1"
|
||||
nginx_dissite $SUSPENDED_SITE
|
||||
service nginx reload
|
||||
}
|
||||
|
||||
function restart_site {
|
||||
# restarts a given website
|
||||
if [ ! $SUSPENDED_SITE ]; then
|
||||
return
|
||||
fi
|
||||
nginx_ensite $SUSPENDED_SITE
|
||||
service nginx reload
|
||||
SUSPENDED_SITE=
|
||||
}
|
||||
|
||||
function update_domains {
|
||||
GIT_DOMAIN_NAME='gogs'
|
||||
if grep -q "Gogs domain" $COMPLETION_FILE; then
|
||||
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
|
||||
fi
|
||||
MICROBLOG_DOMAIN_NAME='microblog'
|
||||
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
||||
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
|
||||
|
@ -68,6 +92,10 @@ function update_domains {
|
|||
if grep -q "Blog domain" $COMPLETION_FILE; then
|
||||
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
|
||||
fi
|
||||
OWNCLOUD_DOMAIN_NAME='owncloud'
|
||||
if grep -q "Owncloud domain" $COMPLETION_FILE; then
|
||||
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
|
||||
fi
|
||||
}
|
||||
|
||||
function mount_drive {
|
||||
|
@ -133,6 +161,7 @@ function unmount_drive {
|
|||
function backup_database {
|
||||
if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
|
||||
echo $"No MariaDB password was given"
|
||||
restart_site
|
||||
exit 10
|
||||
fi
|
||||
if [ ! -d $USB_MOUNT/backup/${1} ]; then
|
||||
|
@ -152,6 +181,7 @@ function backup_database {
|
|||
rm -rf /root/temp${1}data
|
||||
umount $USB_MOUNT
|
||||
rm -rf $USB_MOUNT
|
||||
restart_site
|
||||
exit 5
|
||||
fi
|
||||
}
|
||||
|
@ -163,6 +193,7 @@ function backup_directory_to_usb {
|
|||
BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $"Backup key could not be found"
|
||||
restart_site
|
||||
exit 6
|
||||
fi
|
||||
MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
|
||||
|
@ -179,6 +210,7 @@ function backup_directory_to_usb {
|
|||
shred -zu ${1}/*
|
||||
rm -rf ${1}
|
||||
fi
|
||||
restart_site
|
||||
exit 71
|
||||
fi
|
||||
obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
|
||||
|
@ -189,6 +221,7 @@ function backup_directory_to_usb {
|
|||
shred -zu ${1}/*
|
||||
rm -rf ${1}
|
||||
fi
|
||||
restart_site
|
||||
exit 7
|
||||
fi
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
|
@ -326,9 +359,23 @@ function backup_directories {
|
|||
do
|
||||
# if this directory exists then backup the given database
|
||||
required_directory=$(echo $dr | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
|
||||
if [[ "$database_name" == *"hubzilla"* ]]; then
|
||||
suspend_site ${HUBZILLA_DOMAIN_NAME}
|
||||
fi
|
||||
if [[ "$database_name" == *"gnusocial"* ]]; then
|
||||
suspend_site ${MICROBLOG_DOMAIN_NAME}
|
||||
fi
|
||||
if [[ "$database_name" == *"owncloud"* ]]; then
|
||||
suspend_site ${OWNCLOUD_DOMAIN_NAME}
|
||||
fi
|
||||
if [[ "$database_name" == *"gogs"* ]]; then
|
||||
suspend_site ${GIT_DOMAIN_NAME}
|
||||
fi
|
||||
|
||||
if [[ $required_directory != "none" ]]; then
|
||||
if [ -d $required_directory ]; then
|
||||
database_name=$(echo $dr | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||
if [[ $database_name != "none" ]]; then
|
||||
backup_database $database_name
|
||||
fi
|
||||
|
@ -342,6 +389,8 @@ function backup_directories {
|
|||
echo $"Backing up $source_directory to $dest_directory"
|
||||
backup_directory_to_usb $source_directory $dest_directory
|
||||
fi
|
||||
|
||||
restart_site
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
@ -66,10 +66,32 @@ if [ ! -d $SERVER_DIRECTORY/backup ]; then
|
|||
mkdir -p $SERVER_DIRECTORY/backup
|
||||
fi
|
||||
|
||||
# The name of a currently suspended site
|
||||
# Sites are suspended so that verification should work
|
||||
SUSPENDED_SITE=
|
||||
|
||||
function suspend_site {
|
||||
# suspends a given website
|
||||
SUSPENDED_SITE="$1"
|
||||
nginx_dissite $SUSPENDED_SITE
|
||||
service nginx reload
|
||||
}
|
||||
|
||||
function restart_site {
|
||||
# restarts a given website
|
||||
if [ ! $SUSPENDED_SITE ]; then
|
||||
return
|
||||
fi
|
||||
nginx_ensite $SUSPENDED_SITE
|
||||
service nginx reload
|
||||
SUSPENDED_SITE=
|
||||
}
|
||||
|
||||
function backup_directory_to_friend {
|
||||
BACKUP_KEY_EXISTS=$(gpg --list-keys "$ADMIN_NAME (backup key)")
|
||||
if [ ! "$?" = "0" ]; then
|
||||
echo $"Backup key could not be found"
|
||||
restart_site
|
||||
exit 43382
|
||||
fi
|
||||
ADMIN_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
|
||||
|
@ -86,6 +108,7 @@ function backup_directory_to_friend {
|
|||
fi
|
||||
# Send a warning email
|
||||
echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
|
||||
restart_site
|
||||
exit 953
|
||||
fi
|
||||
obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
|
||||
|
@ -96,6 +119,7 @@ function backup_directory_to_friend {
|
|||
fi
|
||||
# Send a warning email
|
||||
echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
|
||||
restart_site
|
||||
exit 853
|
||||
fi
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
|
@ -107,6 +131,7 @@ function backup_directory_to_friend {
|
|||
function backup_database_to_friend {
|
||||
if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
|
||||
echo $"No MariaDB password was given"
|
||||
restart_site
|
||||
exit 5783
|
||||
fi
|
||||
if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then
|
||||
|
@ -126,6 +151,7 @@ function backup_database_to_friend {
|
|||
rm -rf /root/temp${1}data
|
||||
# Send a warning email
|
||||
echo $"Unable to export ${1} database" | mail -s $"${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
|
||||
restart_site
|
||||
exit 5738
|
||||
fi
|
||||
}
|
||||
|
@ -226,10 +252,12 @@ function backup_gnusocial {
|
|||
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
||||
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
|
||||
if [ -d /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs ]; then
|
||||
suspend_site ${MICROBLOG_DOMAIN_NAME}
|
||||
backup_database_to_friend gnusocial
|
||||
backup_directory_to_friend /root/tempgnusocialdata gnusocialdata
|
||||
echo $"Backing up GNU social installation"
|
||||
backup_directory_to_friend /var/www/${MICROBLOG_DOMAIN_NAME}/htdocs gnusocial
|
||||
restart_site
|
||||
else
|
||||
echo $"GNU Social domain specified but not found in /var/www/${MICROBLOG_DOMAIN_NAME}"
|
||||
fi
|
||||
|
@ -240,10 +268,12 @@ function backup_hubzilla {
|
|||
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
||||
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
|
||||
if [ -d /var/www/${HUBZILLA_DOMAIN_NAME} ]; then
|
||||
suspend_site ${HUBZILLA_DOMAIN_NAME}
|
||||
backup_database_to_friend hubzilla
|
||||
backup_directory_to_friend /root/temphubzilladata hubzilladata
|
||||
echo "Backing up Hubzilla installation"
|
||||
backup_directory_to_friend /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs hubzilla
|
||||
restart_site
|
||||
else
|
||||
echo $"Hubzilla domain specified but not found in /var/www/${HUBZILLA_DOMAIN_NAME}"
|
||||
exit 2578
|
||||
|
@ -253,16 +283,21 @@ function backup_hubzilla {
|
|||
|
||||
function backup_owncloud {
|
||||
if [ -d /etc/owncloud ]; then
|
||||
OWNCLOUD_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Owncloud domain" | awk -F ':' '{print $2}')
|
||||
suspend_site ${OWNCLOUD_DOMAIN_NAME}
|
||||
backup_database_to_friend owncloud
|
||||
backup_directory_to_friend /root/tempownclouddata ownclouddata
|
||||
echo $"Backing up Owncloud data"
|
||||
backup_directory_to_friend /var/lib/owncloud owncloud
|
||||
backup_directory_to_friend /etc/owncloud owncloud2
|
||||
restart_site
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_gogs {
|
||||
if [ -d /home/git/go/src/github.com/gogits ]; then
|
||||
GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
|
||||
suspend_site ${GIT_DOMAIN_NAME}
|
||||
backup_database_to_friend gogs
|
||||
backup_directory_to_friend /root/tempgogsdata gogsdata
|
||||
echo $"Obtaining Gogs settings backup"
|
||||
|
@ -272,6 +307,7 @@ function backup_gogs {
|
|||
backup_directory_to_friend /home/git/gogs-repositories gogsrepos
|
||||
echo $"Obtaining Gogs authorized_keys backup"
|
||||
backup_directory_to_friend /home/git/.ssh gogsssh
|
||||
restart_site
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -537,7 +573,7 @@ do
|
|||
if [ $REMOTE_SERVER ]; then
|
||||
REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
|
||||
REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
|
||||
REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
|
||||
REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
|
||||
REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $4}')
|
||||
NOW=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
|
||||
|
|
Loading…
Reference in New Issue