Local backup function for blog

This commit is contained in:
Bob Mottram 2016-07-07 09:58:21 +01:00
parent f17bdebb10
commit d919518eb9
No known key found for this signature in database
GPG Key ID: BA68F26108DC9F87
3 changed files with 51 additions and 24 deletions

View File

@ -47,11 +47,31 @@ function upgrade_blog {
}
function backup_local_blog {
echo ''
FULLBLOG_DOMAIN_NAME='blog'
if grep -q "Blog domain" $COMPLETION_FILE; then
FULLBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Blog domain" | awk -F ':' '{print $2}')
fi
source_directory=/var/www/${FULLBLOG_DOMAIN_NAME}/htdocs
if [ -d $source_directory ]; then
dest_directory=blog
echo $"Backing up $source_directory to $dest_directory"
function_check suspend_site
suspend_site ${FULLBLOG_DOMAIN_NAME}
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
function_check restart_site
restart_site
echo $"Backup to $dest_directory complete"
fi
}
function backup_remote_blog {
echo ''
echo ''
}
function remove_blog {

View File

@ -31,11 +31,18 @@
PROJECT_NAME='freedombone'
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
ENABLE_VERIFICATION="no"
ENABLE_BACKUP_VERIFICATION="no"
export TEXTDOMAIN=${PROJECT_NAME}-backup-local
export TEXTDOMAINDIR="/usr/share/locale"
# include utils which allow function_check
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
do
source $f
done
USB_DRIVE=/dev/sdb1
USB_MOUNT=/mnt/usb
@ -63,26 +70,6 @@ if [ -f /root/dbpass ]; then
DATABASE_PASSWORD=$(cat /root/dbpass)
fi
function suspend_site {
# suspends a given website
if [[ $ENABLE_VERIFICATION != "yes" ]]; then
return
fi
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 {
RSS_READER_DOMAIN_NAME='ttrss'
if grep -q "RSS reader domain" $COMPLETION_FILE; then
@ -214,7 +201,7 @@ function backup_directory_to_usb {
fi
obnam force-lock -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
obnam backup -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
if [[ $ENABLE_VERIFICATION == "yes" ]]; then
if [[ $ENABLE_BACKUP_VERIFICATION == "yes" ]]; then
obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
if [ ! "$?" = "0" ]; then
umount $USB_MOUNT

View File

@ -53,6 +53,9 @@ MAX_PHP_MEMORY=64
# logging level for Nginx
WEBSERVER_LOG_LEVEL='warn'
# whether a given site is being suspended during backup
SUSPENDED_SITE=
# test a domain name to see if it's valid
function validate_domain_name {
# count the number of dots in the domain name
@ -548,4 +551,21 @@ function install_command_line_browser {
echo 'install_command_line_browser' >> $COMPLETION_FILE
}
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=
}
# NOTE: deliberately no exit 0