From 0e247a521c00295e846e22b801ba270b7de4d546 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 7 Mar 2016 17:26:46 +0000 Subject: [PATCH] Backup and restore fin files if they exist --- src/freedombone-backup-local | 50 +++++++++++++++++++--------------- src/freedombone-backup-remote | 50 +++++++++++++++++++--------------- src/freedombone-restore-local | 28 +++++++++++++++++++ src/freedombone-restore-remote | 27 ++++++++++++++++++ 4 files changed, 111 insertions(+), 44 deletions(-) diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local index b77c74b6..f5d94f16 100755 --- a/src/freedombone-backup-local +++ b/src/freedombone-backup-local @@ -289,6 +289,12 @@ function backup_users { backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME fi + # Backup fin database if it exists + if [ -d /home/$USERNAME/.fin ]; then + echo $"Backing up fin files for $USERNAME" + backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME + fi + # Backup user configs if [ -d /home/$USERNAME/.config ]; then echo $"Backing up config files for $USERNAME" @@ -506,28 +512,28 @@ function valid_backup_destination { 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" == "ttrss" || \ - "$destination_dir" == "blog" || \ - "$destination_dir" == "owncloud" || \ - "$destination_dir" == "owncloud2" || \ - "$destination_dir" == "ownclouddata" || \ - "$destination_dir" == "mailinglist" ]]; then + "$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" == "ttrss" || \ + "$destination_dir" == "blog" || \ + "$destination_dir" == "owncloud" || \ + "$destination_dir" == "owncloud2" || \ + "$destination_dir" == "ownclouddata" || \ + "$destination_dir" == "mailinglist" ]]; then is_valid="no" fi diff --git a/src/freedombone-backup-remote b/src/freedombone-backup-remote index a66235ab..27470994 100755 --- a/src/freedombone-backup-remote +++ b/src/freedombone-backup-remote @@ -208,6 +208,12 @@ function backup_users { backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME fi + # fin files + if [ -d /home/$USERNAME/.fin ]; then + echo $"Backing up fin files for $USERNAME" + backup_directory_to_friend /home/$USERNAME/.fin fin/$USERNAME + fi + # local files if [ -d /home/$USERNAME/.local ]; then echo $"Backing up local files for $USERNAME" @@ -507,7 +513,7 @@ function disperse_key_shares { # copy the fragments directory to the remote server /usr/bin/sshpass -p "$REMOTE_PASSWORD" \ - scp -r -P $REMOTE_SSH_PORT $temp_key_share_fragments $REMOTE_SERVER + scp -r -P $REMOTE_SSH_PORT $temp_key_share_fragments $REMOTE_SERVER if [ ! "$?" = "0" ]; then # Send a warning email echo "Key share to $REMOTE_SERVER failed" | \ @@ -531,27 +537,27 @@ function valid_backup_destination { 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 + "$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 diff --git a/src/freedombone-restore-local b/src/freedombone-restore-local index 4b1f92f3..b4df1be9 100755 --- a/src/freedombone-restore-local +++ b/src/freedombone-restore-local @@ -601,6 +601,33 @@ function restore_user_config { fi } +function restore_user_fin { + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userfin' ]]; then + return + fi + fi + if [ -d $USB_MOUNT/backup/fin ]; then + for d in $USB_MOUNT/backup/fin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring fin files for $USERNAME" + restore_directory_from_usb /root/tempfin fin/$USERNAME + cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempfin + unmount_drive + exit 664 + fi + rm -rf /root/tempfin + fi + done + fi +} + function restore_user_local { if [[ $RESTORE_APP != 'all' ]]; then if [[ $RESTORE_APP != 'userlocal' ]]; then @@ -1097,6 +1124,7 @@ restore_admin_readme restore_ipfs restore_user_ssh_keys restore_user_config +restore_user_fin restore_user_local restore_certs restore_personal_settings diff --git a/src/freedombone-restore-remote b/src/freedombone-restore-remote index 79bd47fb..41ef993b 100755 --- a/src/freedombone-restore-remote +++ b/src/freedombone-restore-remote @@ -481,6 +481,32 @@ function restore_user_config { done } +function restore_user_fin { + if [[ $RESTORE_APP != 'all' ]]; then + if [[ $RESTORE_APP != 'userfin' ]]; then + return + fi + fi + for d in $SERVER_DIRECTORY/backup/fin/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $6}') + if [[ $USERNAME != "git" && $USRNAME != "mirrors" ]]; then + if [ -d $SERVER_DIRECTORY/backup/fin/$USERNAME ]; then + if [ ! -d /home/$USERNAME ]; then + ${PROJECT_NAME}-adduser $USERNAME + fi + echo $"Restoring fin files for $USERNAME" + restore_directory_from_friend /root/tempfin fin/$USERNAME + cp -r /root/tempfin/home/$USERNAME/.fin /home/$USERNAME/ + if [ ! "$?" = "0" ]; then + rm -rf /root/tempfin + exit 664 + fi + rm -rf /root/tempfin + fi + fi + done +} + function restore_user_local { if [[ $RESTORE_APP != 'all' ]]; then if [[ $RESTORE_APP != 'userlocal' ]]; then @@ -950,6 +976,7 @@ restore_admin_readme restore_ipfs restore_ssh_keys restore_user_config +restore_user_fin restore_user_local restore_certs restore_personal_settings