From 313fb432d321b3f09646de791952ea6b1c489b5c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 1 Nov 2016 20:33:12 +0000 Subject: [PATCH] Tidying --- src/freedombone-utils-backup | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/freedombone-utils-backup b/src/freedombone-utils-backup index 0e7b619f..8520f076 100755 --- a/src/freedombone-utils-backup +++ b/src/freedombone-utils-backup @@ -475,19 +475,20 @@ function restore_database_from_friend { if [ -d $SERVER_DIRECTORY/backup/${1} ]; then echo $"Restoring ${1} database" - restore_directory_from_friend /root/temp${1}data ${1}data - if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then + local_database_dir=/root/temp${1}data + restore_directory_from_friend ${local_database_dir} ${1}data + if [ ! -f ${local_database_dir}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then echo $"Unable to restore ${1} database" - rm -rf /root/temp${1}data + rm -rf ${local_database_dir} exit 503 fi - mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) + mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < ${local_database_dir}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) if [ ! "$?" = "0" ]; then echo "$mysqlsuccess" exit 964 fi - shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/* - rm -rf /root/temp${1}data + shred -zu ${local_database_dir}/${RESTORE_SUBDIR}/temp${1}data/* + rm -rf ${local_database_dir} echo $"Restoring ${1} installation" restore_directory_from_friend /root/temp${1} ${1} RESTORE_SUBDIR="var" @@ -519,18 +520,19 @@ function restore_database { if [ -d $USB_MOUNT/backup/${1} ]; then echo $"Restoring ${1} database" + local_database_dir=/root/temp${1}data function_check restore_directory_from_usb - restore_directory_from_usb "/root/temp${1}data" "${1}data" + restore_directory_from_usb "${local_database}" "${1}data" if [ ! -f /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql ]; then echo $"Unable to restore ${1} database" - rm -rf /root/temp${1}data + rm -rf ${local_database} function_check set_user_permissions set_user_permissions function_check backup_unmount_drive backup_unmount_drive exit 503 fi - mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) + mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < ${local_database}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql) if [ ! "$?" = "0" ]; then echo "$mysqlsuccess" function_check set_user_permissions @@ -539,8 +541,8 @@ function restore_database { backup_unmount_drive exit 964 fi - shred -zu /root/temp${1}data/${RESTORE_SUBDIR}/temp${1}data/* - rm -rf /root/temp${1}data + shred -zu ${local_database}/${RESTORE_SUBDIR}/temp${1}data/* + rm -rf ${local_database} echo $"Restoring ${1} installation" if [ ! -d /root/temp${1} ]; then mkdir /root/temp${1}