Local backup of gnusocial

This commit is contained in:
Bob Mottram 2016-07-07 11:20:10 +01:00
parent 6b287ba099
commit 8a165eddb9
No known key found for this signature in database
GPG Key ID: BA68F26108DC9F87
5 changed files with 695 additions and 629 deletions

File diff suppressed because it is too large Load Diff

View File

@ -97,81 +97,6 @@ function update_domains {
fi
}
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
mkdir -p $USB_MOUNT/backup/${1}
fi
if [ ! -d $USB_MOUNT/backup/${1}data ]; then
mkdir -p $USB_MOUNT/backup/${1}data
fi
if [ ! -d /root/temp${1}data ]; then
mkdir -p /root/temp${1}data
fi
echo $"Obtaining ${1} database backup"
mysqldump --lock-tables --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
umount $USB_MOUNT
rm -rf $USB_MOUNT
restart_site
exit 5
fi
}
function backup_directory_to_usb {
if [ ! -d ${1} ]; then
echo $"WARNING: directory does not exist: ${1}"
else
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}')
if [ ! -d $USB_MOUNT/backup/${2} ]; then
mkdir -p $USB_MOUNT/backup/${2}
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_BACKUP_VERIFICATION == "yes" ]]; then
obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
if [ ! "$?" = "0" ]; then
umount $USB_MOUNT
rm -rf $USB_MOUNT
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/*
rm -rf ${1}
fi
restart_site
exit 71
fi
fi
obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
if [ ! "$?" = "0" ]; then
umount $USB_MOUNT
rm -rf $USB_MOUNT
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/*
rm -rf ${1}
fi
restart_site
exit 7
fi
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/*
rm -rf ${1}
fi
fi
}
function make_backup_directory {
# make a backup directory on the drive
if [ ! -d $USB_MOUNT/backup ]; then
@ -245,6 +170,15 @@ function backup_users {
fi
fi
# Backup emacs
if [ -d /home/$USERNAME/.emacs.d ]; then
echo $"Backing up Emacs config for $USERNAME"
if [ -f /home/$USERNAME/.emacs ]; then
cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
fi
backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
fi
# Backup user configs
if [ -d /home/$USERNAME/.config ]; then
echo $"Backing up config files for $USERNAME"
@ -369,7 +303,7 @@ function backup_directories {
if [[ $required_directory != "none" ]]; then
if [ -d $required_directory ]; then
if [[ $database_name != "none" ]]; then
backup_database $database_name
backup_database_local $database_name
fi
fi
fi

View File

@ -609,6 +609,34 @@ function restore_user_config {
fi
}
function restore_user_emacs {
if [[ $RESTORE_APP != 'all' ]]; then
if [[ $RESTORE_APP != 'useremacs' ]]; then
return
fi
fi
if [ -d $USB_MOUNT/backup/emacs ]; then
for d in $USB_MOUNT/backup/emacs/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
if [ ! -d /home/$USERNAME ]; then
${PROJECT_NAME}-adduser $USERNAME
fi
echo $"Restoring Emacs config for $USERNAME"
restore_directory_from_usb /root/tempemacs emacs/$USERNAME
cp -r /root/tempemacs/home/$USERNAME/.emacs.d /home/$USERNAME/
if [ ! "$?" = "0" ]; then
rm -rf /root/tempemacs
unmount_drive
exit 664
fi
cp -f /root/tempemacs/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
rm -rf /root/tempemacs
fi
done
fi
}
function gpg_pubkey_from_email {
key_owner_username=$1
key_email_address=$2
@ -1264,6 +1292,7 @@ restore_admin_readme
restore_ipfs
restore_user_ssh_keys
restore_user_config
restore_user_emacs
restore_user_monkeysphere
restore_user_fin
restore_user_local

View File

@ -28,6 +28,26 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# whether a given site is being suspended during backup
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 configure_backup_key {
if grep -Fxq "configure_backup_key" $COMPLETION_FILE; then
return
@ -162,4 +182,83 @@ function backup_unmount_drive {
echo $"Backup to USB drive is complete. You can now unplug it."
}
function backup_database_local {
if [ ${#DATABASE_PASSWORD} -lt 2 ]; then
echo $"No MariaDB password was given"
function_check restart_site
restart_site
exit 10
fi
if [ ! -d $USB_MOUNT/backup/${1} ]; then
mkdir -p $USB_MOUNT/backup/${1}
fi
if [ ! -d $USB_MOUNT/backup/${1}data ]; then
mkdir -p $USB_MOUNT/backup/${1}data
fi
if [ ! -d /root/temp${1}data ]; then
mkdir -p /root/temp${1}data
fi
echo $"Obtaining ${1} database backup"
mysqldump --lock-tables --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
umount $USB_MOUNT
rm -rf $USB_MOUNT
restart_site
exit 6835872
fi
}
function backup_directory_to_usb {
if [ ! -d ${1} ]; then
echo $"WARNING: directory does not exist: ${1}"
else
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 6
fi
MY_BACKUP_KEY_ID=$(gpg --list-keys "$ADMIN_NAME (backup key)" | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
if [ ! -d $USB_MOUNT/backup/${2} ]; then
mkdir -p $USB_MOUNT/backup/${2}
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_BACKUP_VERIFICATION == "yes" ]]; then
obnam verify -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID ${1}
if [ ! "$?" = "0" ]; then
umount $USB_MOUNT
rm -rf $USB_MOUNT
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/*
rm -rf ${1}
fi
function_check restart_site
restart_site
exit 683252
fi
fi
obnam forget --keep=30d -r $USB_MOUNT/backup/${2} --encrypt-with $MY_BACKUP_KEY_ID
if [ ! "$?" = "0" ]; then
umount $USB_MOUNT
rm -rf $USB_MOUNT
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/*
rm -rf ${1}
fi
function_check restart_site
restart_site
exit 7
fi
if [[ ${1} == "/root/temp"* || ${1} == *"tempbackup" ]]; then
shred -zu ${1}/*
rm -rf ${1}
fi
fi
}
# NOTE: deliberately no exit 0

View File

@ -53,9 +53,6 @@ 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
@ -551,21 +548,4 @@ 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