From 73cfa413522371ec36c297242426c96c76084665 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Sun, 9 Jul 2017 16:05:18 +0100
Subject: [PATCH] Backup only the necessary postactiv data

Not all the files
---
 src/freedombone-app-postactiv | 133 +++++++++++++++++++++++++---------
 1 file changed, 99 insertions(+), 34 deletions(-)

diff --git a/src/freedombone-app-postactiv b/src/freedombone-app-postactiv
index 322abe1cf..7cdae3268 100755
--- a/src/freedombone-app-postactiv
+++ b/src/freedombone-app-postactiv
@@ -391,21 +391,31 @@ function backup_local_postactiv {
         POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
     fi
 
-    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
-    if [ -d $source_directory ]; then
-        dest_directory=postactiv
-        function_check suspend_site
-        suspend_site ${POSTACTIV_DOMAIN_NAME}
+    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/backup
+    if [ ! -d $source_directory ]; then
+        mkdir $source_directory
+    fi
+    cp -p /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/config.php $source_directory
+    if [ -d /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static ]; then
+        cp -rp /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static $source_directory
+    fi
 
-        function_check backup_directory_to_usb
-        backup_directory_to_usb $source_directory $dest_directory
+    function_check suspend_site
+    suspend_site ${POSTACTIV_DOMAIN_NAME}
 
-        function_check backup_database_to_usb
-        backup_database_to_usb postactiv
+    function_check backup_directory_to_usb
+    dest_directory=postactivconfig
+    backup_directory_to_usb $source_directory $dest_directory
 
-        function_check restart_site
-        restart_site
-    fi
+    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/file
+    dest_directory=postactivfile
+    backup_directory_to_usb $source_directory $dest_directory
+
+    function_check backup_database_to_usb
+    backup_database_to_usb postactiv
+
+    function_check restart_site
+    restart_site
 }
 
 function restore_local_postactiv {
@@ -414,6 +424,7 @@ function restore_local_postactiv {
     fi
     POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
     if [ $POSTACTIV_DOMAIN_NAME ]; then
+        echo $"Restoring postactiv"
         temp_restore_dir=/root/temppostactiv
         postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
         # stop the daemons
@@ -423,55 +434,109 @@ function restore_local_postactiv {
         function_check postactiv_create_database
         postactiv_create_database
 
-        restore_database postactiv ${POSTACTIV_DOMAIN_NAME}
+        restore_database postactiv
+        if [ -d $temp_restore_dir ]; then
+            rm -rf $temp_restore_dir
+        fi
+
+        function_check restore_directory_from_usb
+        restore_directory_from_usb $temp_restore_dir postactivconfig
         if [ -d $temp_restore_dir ]; then
+            cp $temp_restore_dir$postactiv_dir/backup/config.php $postactiv_dir/
+            chown www-data:www-data $postactiv_dir/config.php
+            cp -rp $temp_restore_dir$postactiv_dir/static $postactiv_dir/
+            chown -R www-data:www-data $postactiv_dir/static
+            rm -rf $temp_restore_dir
+        fi
+
+        restore_directory_from_usb $temp_restore_dir postactivfile
+        if [ -d $temp_restore_dir ]; then
+            cp -rp $temp_restore_dir$postactiv_dir/file $postactiv_dir/
+            chown -R www-data:www-data $postactiv_dir/file
             rm -rf $temp_restore_dir
         fi
 
         gnusocial_update_after_restore postactiv ${POSTACTIV_DOMAIN_NAME}
+
+        echo $"Restore of postactiv complete"
     fi
 }
 
 function backup_remote_postactiv {
+    POSTACTIV_DOMAIN_NAME='postactiv'
     if grep -q "postactiv domain" $COMPLETION_FILE; then
         POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
-        temp_backup_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
-        if [ -d $temp_backup_dir ]; then
-            function_check suspend_site
-            suspend_site ${POSTACTIV_DOMAIN_NAME}
+    fi
 
-            function_check backup_database_to_friend
-            backup_database_to_friend postactiv
+    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/backup
+    if [ ! -d $source_directory ]; then
+        mkdir $source_directory
+    fi
+    cp -p /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/config.php $source_directory
+    if [ -d /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static ]; then
+        cp -rp /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static $source_directory
+    fi
 
-            function_check backup_directory_to_friend
-            backup_directory_to_friend $temp_backup_dir postactiv
+    function_check suspend_site
+    suspend_site ${POSTACTIV_DOMAIN_NAME}
 
-            function_check restart_site
-            restart_site
-        else
-            echo $"postactiv domain specified but not found in ${temp_backup_dir}"
-        fi
-    fi
+    function_check backup_directory_to_friend
+    dest_directory=postactivconfig
+    backup_directory_to_friend $source_directory $dest_directory
+
+    source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/file
+    dest_directory=postactivfile
+    backup_directory_to_friend $source_directory $dest_directory
+
+    function_check backup_database_to_friend
+    backup_database_to_friend postactiv
+
+    function_check restart_site
+    restart_site
 }
 
 function restore_remote_postactiv {
-    if grep -q "postactiv domain" $COMPLETION_FILE; then
-        POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
-
+    if ! grep -q "postactiv domain" $COMPLETION_FILE; then
+        return
+    fi
+    POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
+    if [ $POSTACTIV_DOMAIN_NAME ]; then
+        echo $"Restoring postactiv"
+        temp_restore_dir=/root/temppostactiv
+        postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
         # stop the daemons
-        cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
+        cd $postactiv_dir
         scripts/stopdaemons.sh
 
         function_check postactiv_create_database
         postactiv_create_database
 
         function_check restore_database_from_friend
-        restore_database_from_friend postactiv ${POSTACTIV_DOMAIN_NAME}
-        if [ -d /root/temppostactiv ]; then
-            rm -rf /root/temppostactiv
+        restore_database_from_friend postactiv
+        if [ -d $temp_restore_dir ]; then
+            rm -rf $temp_restore_dir
+        fi
+
+        function_check restore_directory_from_friend
+        restore_directory_from_friend $temp_restore_dir postactivconfig
+        if [ -d $temp_restore_dir ]; then
+            cp $temp_restore_dir$postactiv_dir/backup/config.php $postactiv_dir/
+            chown www-data:www-data $postactiv_dir/config.php
+            cp -rp $temp_restore_dir$postactiv_dir/static $postactiv_dir/
+            chown -R www-data:www-data $postactiv_dir/static
+            rm -rf $temp_restore_dir
+        fi
+
+        restore_directory_from_friend $temp_restore_dir postactivfile
+        if [ -d $temp_restore_dir ]; then
+            cp -rp $temp_restore_dir$postactiv_dir/file $postactiv_dir/
+            chown -R www-data:www-data $postactiv_dir/file
+            rm -rf $temp_restore_dir
         fi
 
         gnusocial_update_after_restore postactiv ${POSTACTIV_DOMAIN_NAME}
+
+        echo $"Restore of postactiv complete"
     fi
 }
 
-- 
GitLab