From 96152ab7b1304c03ad06bbd91aa99394525f6897 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 20 Sep 2015 13:41:58 +0100 Subject: [PATCH] Tidying backup script --- src/freedombone | 118 ++++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 85 deletions(-) diff --git a/src/freedombone b/src/freedombone index f849667d..14259afb 100755 --- a/src/freedombone +++ b/src/freedombone @@ -2438,6 +2438,33 @@ function backup_directory_to_usb { fi } +function backup_database { + echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "if [ ! -d $USB_MOUNT/backup/${1} ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " mkdir -p $USB_MOUNT/backup/${1}" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "if [ ! -d $USB_MOUNT/backup/${1}data ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " mkdir -p $USB_MOUNT/backup/${1}data" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "if [ ! -d /root/temp${1}data ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " mkdir -p /root/temp${1}data" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "echo \"Obtaining ${1} database backup\"" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo -n 'mysqldump --password=$DATABASE_PASSWORD ' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "${1} > /root/temp${1}data/${1}.sql" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "if [ ! -s /root/temp${1}data/${1}.sql ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " echo \"${1} database could not be saved\"" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " echo 'No MariaDB password was given'" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " fi" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " shred -zu /root/temp${1}data/*" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " rm -rf /root/temp${1}data" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo ' exit 296' >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "fi" >> /usr/bin/$BACKUP_SCRIPT_NAME +} + function create_backup_script { if grep -Fxq "create_backup_script" $COMPLETION_FILE; then return @@ -2517,28 +2544,7 @@ function create_backup_script { echo '' >> /usr/bin/$BACKUP_SCRIPT_NAME if grep -Fxq "install_gnu_social" $COMPLETION_FILE; then BACKUP_INCLUDES_DATABASES="yes" - echo "if [ ! -d $USB_MOUNT/backup/gnusocial ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/gnusocial" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d $USB_MOUNT/backup/gnusocialdata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/gnusocialdata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d /root/tempgnusocialdata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p /root/tempgnusocialdata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'echo "Obtaining GNU Social database backup"' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'mysqldump --password=$DATABASE_PASSWORD gnusocial > /root/tempgnusocialdata/gnusocial.sql' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -s /root/tempgnusocialdata/gnusocial.sql ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' echo "GNU social database could not be saved"' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " echo 'No MariaDB password was given'" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " fi" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' shred -zu /root/tempgnusocialdata/*' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' rm -rf /root/tempgnusocialdata' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' exit 296' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "fi" >> /usr/bin/$BACKUP_SCRIPT_NAME + backup_database gnusocial backup_directory_to_usb /root/tempgnusocialdata gnusocialdata echo 'echo "Backing up GNU social installation"' >> /usr/bin/$BACKUP_SCRIPT_NAME backup_directory_to_usb /var/www/$MICROBLOG_DOMAIN_NAME/htdocs gnusocial @@ -2546,28 +2552,7 @@ function create_backup_script { fi if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then BACKUP_INCLUDES_DATABASES="yes" - echo "if [ ! -d $USB_MOUNT/backup/hubzilla ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/hubzilla" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d $USB_MOUNT/backup/hubzilladata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/hubzilladata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d /root/temphubzilladata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p /root/temphubzilladata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'echo "Obtaining Hubzilla database backup"' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'mysqldump --password=$DATABASE_PASSWORD hubzilla > /root/temphubzilladata/hubzilla.sql' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -s /root/temphubzilladata/hubzilla.sql ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' echo "Hubzilla database could not be saved"' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " echo 'No MariaDB password was given'" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " fi" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' shred -zu /root/temphubzilladata/*' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' rm -rf /root/temphubzilladata' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' exit 378' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "fi" >> /usr/bin/$BACKUP_SCRIPT_NAME + backup_database hubzilla backup_directory_to_usb /root/temphubzilladata hubzilladata echo 'echo "Backing up Hubzilla installation"' >> /usr/bin/$BACKUP_SCRIPT_NAME backup_directory_to_usb /var/www/$HUBZILLA_DOMAIN_NAME/htdocs hubzilla @@ -2575,30 +2560,10 @@ function create_backup_script { fi if grep -Fxq "install_owncloud" $COMPLETION_FILE; then BACKUP_INCLUDES_DATABASES="yes" - echo "if [ ! -d $USB_MOUNT/backup/owncloud ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/owncloud" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME echo "if [ ! -d $USB_MOUNT/backup/owncloud2 ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME echo " mkdir -p $USB_MOUNT/backup/owncloud2" >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d $USB_MOUNT/backup/ownclouddata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/ownclouddata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d /root/tempownclouddata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p /root/tempownclouddata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'mysqldump --password=$DATABASE_PASSWORD owncloud > /root/tempownclouddata/owncloud.sql' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -s /root/tempownclouddata/owncloud.sql ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' echo "Owncloud database could not be saved"' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " echo 'No MariaDB password was given'" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " fi" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' shred -zu /root/tempownclouddata/*' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' rm -rf /root/tempownclouddata' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' exit 377' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "fi" >> /usr/bin/$BACKUP_SCRIPT_NAME + backup_database owncloud backup_directory_to_usb /root/tempownclouddata ownclouddata echo 'echo "Obtaining Owncloud data backup"' >> /usr/bin/$BACKUP_SCRIPT_NAME backup_directory_to_usb /var/lib/owncloud owncloud @@ -2607,30 +2572,13 @@ function create_backup_script { fi if grep -Fxq "install_gogs" $COMPLETION_FILE; then BACKUP_INCLUDES_DATABASES="yes" - echo "if [ ! -d $USB_MOUNT/backup/gogs ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/gogs" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME echo "if [ ! -d $USB_MOUNT/backup/gogsrepos ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME echo " mkdir -p $USB_MOUNT/backup/gogsrepos" >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d $USB_MOUNT/backup/gogsdata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p $USB_MOUNT/backup/gogsdata" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo "if [ ! -d $USB_MOUNT/backup/gogsssh ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME + echo " mkdir -p $USB_MOUNT/backup/gogsssh" >> /usr/bin/$BACKUP_SCRIPT_NAME echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -d /root/tempgogsdata ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " mkdir -p /root/tempgogsdata" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'fi' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo 'mysqldump --password=$DATABASE_PASSWORD gogs > /root/tempgogsdata/gogs.sql' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "if [ ! -s /root/tempgogsdata/gogs.sql ]; then" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' echo "Gogs database could not be saved"' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' if [ ! $DATABASE_PASSWORD ]; then' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " echo 'No MariaDB password was given'" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " fi" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' shred -zu /root/tempgogsdata/*' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' rm -rf /root/tempgogsdata' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " umount $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo " rm -rf $USB_MOUNT" >> /usr/bin/$BACKUP_SCRIPT_NAME - echo ' exit 377' >> /usr/bin/$BACKUP_SCRIPT_NAME - echo "fi" >> /usr/bin/$BACKUP_SCRIPT_NAME + backup_database gogs backup_directory_to_usb /root/tempgogsdata gogsdata echo 'echo "Obtaining Gogs settings backup"' >> /usr/bin/$BACKUP_SCRIPT_NAME backup_directory_to_usb /home/git/go/src/github.com/gogits/gogs/custom gogs