Move remote gnusocial backup to app script
This commit is contained in:
parent
7723c26036
commit
d27a518bca
|
@ -69,7 +69,7 @@ function gnusocial_running_script {
|
|||
}
|
||||
|
||||
function reconfigure_gnusocial {
|
||||
echo -n ''
|
||||
echo -n ''
|
||||
}
|
||||
|
||||
function upgrade_gnusocial {
|
||||
|
@ -139,7 +139,27 @@ function restore_local_gnusocial {
|
|||
}
|
||||
|
||||
function backup_remote_gnusocial {
|
||||
echo -n ''
|
||||
if grep -q "GNU Social domain" $COMPLETION_FILE; then
|
||||
MICROBLOG_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "GNU Social domain" | awk -F ':' '{print $2}')
|
||||
temp_backup_dir=/var/www/${MICROBLOG_DOMAIN_NAME}/htdocs
|
||||
if [ -d $temp_backup_dir ]; then
|
||||
function_check suspend_site
|
||||
suspend_site ${MICROBLOG_DOMAIN_NAME}
|
||||
|
||||
function_check backup_database_to_friend
|
||||
backup_database_to_friend gnusocial
|
||||
|
||||
echo $"Backing up GNU social installation"
|
||||
|
||||
function_check backup_directory_to_friend
|
||||
backup_directory_to_friend $temp_backup_dir gnusocial
|
||||
|
||||
function_check restart_site
|
||||
restart_site
|
||||
else
|
||||
echo $"GNU Social domain specified but not found in ${temp_backup_dir}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function restore_remote_gnusocial {
|
||||
|
|
|
@ -37,6 +37,12 @@ ENABLE_VERIFICATION="no"
|
|||
export TEXTDOMAIN=${PROJECT_NAME}-backup-remote
|
||||
export TEXTDOMAINDIR="/usr/share/locale"
|
||||
|
||||
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
|
||||
for f in $UTILS_FILES
|
||||
do
|
||||
source $f
|
||||
done
|
||||
|
||||
# Temporary location for data to be backed up to other servers
|
||||
SERVER_DIRECTORY=/root/remotebackup
|
||||
|
||||
|
@ -94,77 +100,6 @@ function restart_site {
|
|||
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}')
|
||||
if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then
|
||||
mkdir -p $SERVER_DIRECTORY/backup/${2}
|
||||
fi
|
||||
obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
|
||||
obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
|
||||
if [[ $ENABLE_VERIFICATION == "yes" ]]; then
|
||||
obnam verify -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
|
||||
if [ ! "$?" = "0" ]; then
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
shred -zu /root/temp${2}/*
|
||||
rm -rf /root/temp${2}
|
||||
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
|
||||
fi
|
||||
obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
|
||||
if [ ! "$?" = "0" ]; then
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
shred -zu /root/temp${2}/*
|
||||
rm -rf /root/temp${2}
|
||||
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
|
||||
shred -zu /root/temp${2}/*
|
||||
rm -rf /root/temp${2}
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
mkdir -p $SERVER_DIRECTORY/backup/${1}
|
||||
fi
|
||||
if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then
|
||||
mkdir -p $SERVER_DIRECTORY/backup/${1}data
|
||||
fi
|
||||
if [ ! -d /root/temp${1}data ]; then
|
||||
mkdir -p /root/temp${1}data
|
||||
fi
|
||||
echo "Obtaining ${1} database backup"
|
||||
mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql
|
||||
if [ ! -s /root/temp${1}data/${1}.sql ]; then
|
||||
echo $"${1} database could not be saved"
|
||||
shred -zu /root/temp${1}data/*
|
||||
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
|
||||
}
|
||||
|
||||
function backup_configuration {
|
||||
echo $"Backing up ${PROJECT_NAME} configuration files"
|
||||
if [ ! -d /root/tempbackupconfig ]; then
|
||||
|
@ -325,22 +260,6 @@ function backup_rss {
|
|||
fi
|
||||
}
|
||||
|
||||
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
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_hubzilla {
|
||||
if grep -q "Hubzilla domain" $COMPLETION_FILE; then
|
||||
HUBZILLA_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Hubzilla domain" | awk -F ':' '{print $2}')
|
||||
|
@ -645,7 +564,10 @@ if [[ $TEST_MODE == "no" ]]; then
|
|||
backup_users
|
||||
backup_letsencrypt
|
||||
backup_tor
|
||||
backup_gnusocial
|
||||
backup_web_server
|
||||
backup_admin_readme
|
||||
backup_mariadb
|
||||
|
||||
backup_rss
|
||||
backup_hubzilla
|
||||
backup_syncthing
|
||||
|
@ -656,13 +578,11 @@ if [[ $TEST_MODE == "no" ]]; then
|
|||
backup_certs
|
||||
backup_mailing_list
|
||||
backup_xmpp
|
||||
backup_web_server
|
||||
backup_admin_readme
|
||||
backup_ipfs
|
||||
backup_dlna
|
||||
backup_voip
|
||||
backup_tox
|
||||
backup_mariadb
|
||||
|
||||
backup_extra_directories
|
||||
fi
|
||||
|
||||
|
|
|
@ -281,4 +281,86 @@ function set_user_permissions {
|
|||
done
|
||||
}
|
||||
|
||||
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"
|
||||
function_check restart_site
|
||||
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}')
|
||||
if [ ! -d $SERVER_DIRECTORY/backup/${2} ]; then
|
||||
mkdir -p $SERVER_DIRECTORY/backup/${2}
|
||||
fi
|
||||
obnam force-lock -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
|
||||
obnam backup -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
|
||||
if [[ $ENABLE_VERIFICATION == "yes" ]]; then
|
||||
obnam verify -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID} ${1}
|
||||
if [ ! "$?" = "0" ]; then
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
shred -zu /root/temp${2}/*
|
||||
rm -rf /root/temp${2}
|
||||
fi
|
||||
# Send a warning email
|
||||
echo "Unable to verify ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
|
||||
function_check restart_site
|
||||
restart_site
|
||||
exit 953
|
||||
fi
|
||||
fi
|
||||
obnam forget --keep=30d -r $SERVER_DIRECTORY/backup/${2} --encrypt-with ${ADMIN_BACKUP_KEY_ID}
|
||||
if [ ! "$?" = "0" ]; then
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
shred -zu /root/temp${2}/*
|
||||
rm -rf /root/temp${2}
|
||||
fi
|
||||
# Send a warning email
|
||||
echo "Unable to backup ${2}" | mail -s "${PROJECT_NAME} backup to friends" ${ADMIN_EMAIL_ADDRESS}
|
||||
function_check restart_site
|
||||
restart_site
|
||||
exit 853
|
||||
fi
|
||||
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
|
||||
shred -zu /root/temp${2}/*
|
||||
rm -rf /root/temp${2}
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_database_remote {
|
||||
if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
|
||||
echo $"No MariaDB password was given"
|
||||
function_check restart_site
|
||||
restart_site
|
||||
exit 5783
|
||||
fi
|
||||
if [ ! -d $SERVER_DIRECTORY/backup/${1} ]; then
|
||||
mkdir -p $SERVER_DIRECTORY/backup/${1}
|
||||
fi
|
||||
if [ ! -d $SERVER_DIRECTORY/backup/${1}data ]; then
|
||||
mkdir -p $SERVER_DIRECTORY/backup/${1}data
|
||||
fi
|
||||
if [ ! -d /root/temp${1}data ]; then
|
||||
mkdir -p /root/temp${1}data
|
||||
fi
|
||||
echo "Obtaining ${1} database backup"
|
||||
mysqldump --password=$DATABASE_PASSWORD ${1} > /root/temp${1}data/${1}.sql
|
||||
if [ ! -s /root/temp${1}data/${1}.sql ]; then
|
||||
echo $"${1} database could not be saved"
|
||||
shred -zu /root/temp${1}data/*
|
||||
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
|
||||
function_check restart_site
|
||||
restart_site
|
||||
exit 5738
|
||||
fi
|
||||
}
|
||||
|
||||
function backup_database_to_friend {
|
||||
database_name=$1
|
||||
backup_database_remote $database_name
|
||||
backup_directory_to_friend /root/temp${database_name}data ${database_name}data
|
||||
}
|
||||
|
||||
# NOTE: deliberately no exit 0
|
||||
|
|
Loading…
Reference in New Issue