Bug 21903: koha-dump can export uploaded and temporary uploaded files
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Wed, 10 Apr 2019 09:38:45 +0000 (11:38 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 5 Jul 2022 14:46:37 +0000 (11:46 -0300)
Sponsored-by: Orex
Test plan:
 - Apply the patch
 - Try using koha-dump without any option
 - Try using koha-dump with --uploaded_files
 - Try using koha-dump with --uploaded_temp_files
 - Try using koha-dump with both of the options above

Expected results: the .tar.gz dump will include uploaded and/or temporary
uploaded files if requested.

Signed-off-by: Hugo Agud <hagud@orex.es>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
debian/scripts/koha-dump
debian/scripts/koha-functions.sh

index f8d2ad1..7484523 100755 (executable)
@@ -48,6 +48,8 @@ $scriptname -h|--help
 
     --schema-only         Dump only the database schema
     --exclude-indexes     Include Zebra indexes on the backup
+    --uploaded_files      Include uploaded files.
+    --uploaded_temp_files Include temporary uploaded files.
     --quiet|-q            Make the script avoid printing to STDOUT
                           (useful for calling from another scripts)
     --help|-h             Display this help message
@@ -95,11 +97,22 @@ dump_instance()
 
         # Dump configs, logs, etc.
         metadump="$backupdir/$name-$date.tar.gz"
-        [ "$quiet" = "no" ] && echo "* configs, logs to $metadump"
+        [ "$quiet" = "no" ] && echo "* configs, files, logs to $metadump"
 
         if [ "$exclude_indexes" = "yes" ]; then
             excludes="--exclude=var/lib/koha/$name/biblios \
-                      --exclude=var/lib/koha/$name/authorities"
+                  --exclude=var/lib/koha/$name/authorities"
+        fi
+
+        if [ "$uploaded_files" = "yes" ]; then
+            # Remove leading /
+            uploaded_files_dir=$(echo $(get_upload_path $name) | cut -c 2-)
+        fi
+
+        if [ "$uploaded_temp_files" = "yes" ]; then
+            # Remove leading /
+            tempdir=$(echo $(get_tmp_path $name) | cut -c 2-)
+            uploaded_temp_files_dir="$tempdir/koha_${name}_upload"
         fi
 
         tar -czf "$metadump" -C / $excludes \
@@ -107,13 +120,14 @@ dump_instance()
             "etc/apache2/sites-available/$instancefile" \
             "etc/apache2/sites-enabled/$instancefile" \
             "var/lib/koha/$name" \
-            "var/log/koha/$name"
+            "var/log/koha/$name" \
+            $uploaded_files_dir \
+            $uploaded_temp_files_dir
 
         chown "root:$name-koha" "$metadump"
         chmod g+r "$metadump"
 
         [ "$quiet" = "no" ] && echo "Done."
-
     fi
 }
 
@@ -135,6 +149,12 @@ while [ $# -gt 0 ]; do
         --without-db-name)
             without_db_name="yes"
             shift ;;
+       --uploaded_files)
+            uploaded_files="yes"
+            shift ;;
+        --uploaded_temp_files)
+            uploaded_temp_files="yes"
+            shift ;;
         -h|--help)
             usage ; exit 0 ;;
         -q|--quiet)
index 12832cb..5b81d17 100755 (executable)
@@ -379,6 +379,26 @@ get_max_record_size()
     fi
 }
 
+get_tmp_path()
+{
+    local instancename=$1
+    local retval=$(run_safe_xmlstarlet $instancename tmp_path)
+    if [ "$retval" != "" ]; then
+        echo "$retval"
+        return 0
+    fi
+}
+
+get_upload_path()
+{
+    local instancename=$1
+    local retval=$(run_safe_xmlstarlet $instancename upload_path)
+    if [ "$retval" != "" ]; then
+        echo "$retval"
+        return 0
+    fi
+}
+
 get_tmpdir()
 {
     if [ "$TMPDIR" != "" ]; then