From a8ae880ccdc6d026a9efe6deb09f723ef615d123 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 11 Dec 2015 16:25:43 +0000 Subject: [PATCH] Check that any extra directories being backed up are not the same as existing ones --- src/freedombone-backup-local | 42 +++++++++++++++++++++++++++++++++- src/freedombone-backup-remote | 42 +++++++++++++++++++++++++++++++++- src/freedombone-restore-local | 12 ++++++++++ src/freedombone-restore-remote | 12 ++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local index beec7f6d..b91acada 100755 --- a/src/freedombone-backup-local +++ b/src/freedombone-backup-local @@ -368,6 +368,9 @@ function backup_configuration { fi cp -f $CONFIG_FILE /root/tempbackupconfig cp -f $COMPLETION_FILE /root/tempbackupconfig + if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then + cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig + fi backup_directory_to_usb /root/tempbackupconfig config } @@ -414,6 +417,38 @@ function backup_mariadb { fi } +function valid_backup_destination { + destination_dir="$1" + is_valid="yes" + + if [[ "$destination_dir" == "hubzilla" || \ + "$destination_dir" == "hubzilladata" || \ + "$destination_dir" == "gogs" || \ + "$destination_dir" == "gogsrepos" || \ + "$destination_dir" == "gogsssh" || \ + "$destination_dir" == "gnusocial" || \ + "$destination_dir" == "gnusocialdata" || \ + "$destination_dir" == "mariadb" || \ + "$destination_dir" == "config" || \ + "$destination_dir" == "letsencrypt" || \ + "$destination_dir" == "wiki" || \ + "$destination_dir" == "wiki2" || \ + "$destination_dir" == "xmpp" || \ + "$destination_dir" == "ipfs" || \ + "$destination_dir" == "dlna" || \ + "$destination_dir" == "tox" || \ + "$destination_dir" == "ssl" || \ + "$destination_dir" == "blog" || \ + "$destination_dir" == "owncloud" || \ + "$destination_dir" == "owncloud2" || \ + "$destination_dir" == "ownclouddata" || \ + "$destination_dir" == "mailinglist" ]]; then + is_valid="no" + fi + + echo $is_valid +} + function backup_extra_directories { if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then return @@ -425,7 +460,12 @@ function backup_extra_directories { backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') if [ -d "$backup_dir" ]; then destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - backup_directory_to_usb "$backup_dir" "$destination_dir" + if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then + backup_directory_to_usb "$backup_dir" "$destination_dir" + else + echo $"WARNING: The backup directory $destination_dir is already used." + echo $"Choose a different destination name for backing up $backup_dir" + fi else echo $"WARNING: Directory $backup_dir does not exist" fi diff --git a/src/freedombone-backup-remote b/src/freedombone-backup-remote index 3708372d..1b0b5cff 100755 --- a/src/freedombone-backup-remote +++ b/src/freedombone-backup-remote @@ -127,6 +127,9 @@ function backup_configuration { fi cp -f $CONFIG_FILE /root/tempbackupconfig cp -f $COMPLETION_FILE /root/tempbackupconfig + if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then + cp -f $BACKUP_EXTRA_DIRECTORIES /root/tempbackupconfig + fi backup_directory_to_friend /root/tempbackupconfig config } @@ -439,6 +442,38 @@ function disperse_key_shares { fi } +function valid_backup_destination { + destination_dir="$1" + is_valid="yes" + + if [[ "$destination_dir" == "hubzilla" || \ + "$destination_dir" == "hubzilladata" || \ + "$destination_dir" == "gogs" || \ + "$destination_dir" == "gogsrepos" || \ + "$destination_dir" == "gogsssh" || \ + "$destination_dir" == "gnusocial" || \ + "$destination_dir" == "gnusocialdata" || \ + "$destination_dir" == "mariadb" || \ + "$destination_dir" == "config" || \ + "$destination_dir" == "letsencrypt" || \ + "$destination_dir" == "wiki" || \ + "$destination_dir" == "wiki2" || \ + "$destination_dir" == "xmpp" || \ + "$destination_dir" == "ipfs" || \ + "$destination_dir" == "dlna" || \ + "$destination_dir" == "tox" || \ + "$destination_dir" == "ssl" || \ + "$destination_dir" == "blog" || \ + "$destination_dir" == "owncloud" || \ + "$destination_dir" == "owncloud2" || \ + "$destination_dir" == "ownclouddata" || \ + "$destination_dir" == "mailinglist" ]]; then + is_valid="no" + fi + + echo $is_valid +} + function backup_extra_directories { if [ ! -f $BACKUP_EXTRA_DIRECTORIES ]; then return @@ -450,7 +485,12 @@ function backup_extra_directories { backup_dir=$(echo "$backup_line" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') if [ -d "$backup_dir" ]; then destination_dir=$(echo "$backup_line" | awk -F ',' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - backup_directory_to_friend "$backup_dir" "$destination_dir" + if [[ $(valid_backup_destination "$destination_dir") == "yes" ]]; then + backup_directory_to_friend "$backup_dir" "$destination_dir" + else + echo $"WARNING: The backup directory $destination_dir is already used." + echo $"Choose a different destination name for backing up $backup_dir" + fi else echo $"WARNING: Directory $backup_dir does not exist" fi diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local index 2b900076..bf7fc321 100755 --- a/src/freedombone-restore-local +++ b/src/freedombone-restore-local @@ -232,6 +232,7 @@ function restore_configuration { if [ -d $USB_MOUNT/backup/config ]; then echo $"Restoring configuration files" restore_directory_from_usb /root/tempconfig config + cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE if [ ! "$?" = "0" ]; then unmount_drive @@ -242,12 +243,23 @@ function restore_configuration { # install according to the config file freedombone -c $CONFIG_FILE fi + cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE if [ ! "$?" = "0" ]; then unmount_drive rm -rf /root/tempconfig exit 6382 fi + + if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then + cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 62121 + fi + fi + rm -rf /root/tempconfig fi } diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index 6d4c6125..2e10a89e 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -142,6 +142,7 @@ function restore_configuration { if [ -d $SERVER_DIRECTORY/backup/config ]; then echo $"Restoring configuration files" restore_directory_from_friend /root/tempconfig config + cp -f /root/tempconfig/root/${PROJECT_NAME}.cfg $CONFIG_FILE if [ ! "$?" = "0" ]; then unmount_drive @@ -152,12 +153,23 @@ function restore_configuration { # install according to the config file freedombone -c $CONFIG_FILE fi + cp -f /root/tempconfig/root/${PROJECT_NAME}-completed.txt $COMPLETION_FILE if [ ! "$?" = "0" ]; then unmount_drive rm -rf /root/tempconfig exit 7252 fi + + if [ -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ]; then + cp -f /root/tempconfig${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES} + if [ ! "$?" = "0" ]; then + unmount_drive + rm -rf /root/tempconfig + exit 62121 + fi + fi + rm -rf /root/tempconfig fi }