From 4c64e56cd78016285c521557f6c61f358651907e Mon Sep 17 00:00:00 2001 From: danyonsewell Date: Thu, 14 Mar 2024 02:06:05 +0000 Subject: [PATCH] Bug 36311: Add option to koha-run-backups, to only include database dump Updated patch logic to work better and zip up the database files and actually include table data instead of just the schema. Test plan: 1. Dry run koha-run-backups, to verify that both the .sql.gz and .tar.gz backups are included 2. Apply this patch 3. Run the script again, this time with the --db-only-zip flag 4. check /var/spool/koha/kohadev/ to see that only .sql.gz file has been included. Signed-off-by: David Nind --- debian/scripts/koha-dump | 13 +++++++++++++ debian/scripts/koha-run-backups | 12 +++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/debian/scripts/koha-dump b/debian/scripts/koha-dump index d994607300..b1dd02c756 100755 --- a/debian/scripts/koha-dump +++ b/debian/scripts/koha-dump @@ -47,6 +47,7 @@ $scriptname [--quiet|-q] [--exclude-indexes] instancename1 [instancename2...] $scriptname -h|--help --schema-only Dump only the database schema + --db-only-zip Dump only the database and also zip the file --exclude-indexes Include Zebra indexes on the backup --uploaded_files Include uploaded files. --uploaded_temp_files Include temporary uploaded files. @@ -85,6 +86,14 @@ dump_instance() --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | sed --expression='s/ AUTO_INCREMENT=[0-9]\+//' > "$schemadump" chown "root:$name-koha" "$schemadump" chmod g+r "$schemadump" + elif [ "$db_only_zip" = "yes" ] + then + [ "$quiet" = "no" ] && echo "* DB to $dbdump" + mysqldump $dbflag --host="$mysqlhost" --single-transaction \ + --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | + gzip > "$dbdump" + chown "root:$name-koha" "$dbdump" + chmod g+r "$dbdump" else [ "$quiet" = "no" ] && echo "* DB to $dbdump" mysqldump $dbflag --host="$mysqlhost" --single-transaction \ @@ -144,6 +153,7 @@ quiet="no" exclude_indexes="no" without_db_name="no" schema_only="no" +db_only_zip="no" while [ $# -gt 0 ]; do @@ -151,6 +161,9 @@ while [ $# -gt 0 ]; do --schema-only) schema_only="yes" shift ;; + --db-only-zip) + db_only_zip="yes" + shift ;; --exclude-indexes) exclude_indexes="yes" shift ;; diff --git a/debian/scripts/koha-run-backups b/debian/scripts/koha-run-backups index a9223844fe..8324eb7bc3 100755 --- a/debian/scripts/koha-run-backups +++ b/debian/scripts/koha-run-backups @@ -34,13 +34,16 @@ Options: (default: 2) --exclude-indexes Exclude Zebra indexes from the backups (default: false) + --db-only-zip Only include the Database dump in backup (default: false) + Note: backups produced using this tool can be restored using \`koha-restore'. EOH } exclude_indexes="" +db_only_zip="" -CMD_LINE=`getopt -o h --long days:,output:,help,exclude-indexes -n 'koha-run-backups' -- "$@"` +CMD_LINE=`getopt -o h --long days:,output:,help,exclude-indexes,db-only-zip -n 'koha-run-backups' -- "$@"` if [ $? != 0 ] ; then show_help ; exit 1 ; fi @@ -55,21 +58,20 @@ while true ; do dirname=$2; shift 2 ;; --exclude-indexes) exclude_indexes='--exclude-indexes'; shift ;; + --db-only-zip) + db_only_zip='--db-only-zip'; shift ;; --) shift ; break ;; *) echo "Unknown error parsing the command line!" ; exit 1 ;; esac done - if ! test $days -gt 0 ; then echo "Parameter --days must be an integer greater than 0" exit 1 fi - for name in $(koha-list --enabled | grep -Fxv demo) do - if koha-dump ${exclude_indexes} "$name" > /dev/null; then + if koha-dump ${exclude_indexes} ${db_only_zip} "$name" > /dev/null; then # Only delete old backups if dump script return success. - if [ -z "$dirname" ]; then backupdir="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' /etc/koha/sites/$name/koha-conf.xml )"; else -- 2.30.2