From 13d8fda169c91a9322c3cd96f13c99127edaf3d1 Mon Sep 17 00:00:00 2001 From: mreid-tt <943378+mreid-tt@users.noreply.github.com> Date: Sat, 21 Oct 2023 22:37:03 -0400 Subject: [PATCH] Redesign backup and restore --- spk/owncloud/src/service-setup.sh | 191 ++++++++++-------- .../src/wizard_templates/install_uifile.sh | 127 ++++++++++-- .../src/wizard_templates/install_uifile.yml | 13 +- .../wizard_templates/install_uifile_fre.yml | 13 +- .../src/wizard_templates/uninstall_uifile.sh | 64 +----- .../src/wizard_templates/uninstall_uifile.yml | 4 - .../wizard_templates/uninstall_uifile_fre.yml | 4 - .../src/wizard_templates/upgrade_uifile.sh | 9 - 8 files changed, 240 insertions(+), 185 deletions(-) diff --git a/spk/owncloud/src/service-setup.sh b/spk/owncloud/src/service-setup.sh index f001b935050..f08d6aa58b0 100755 --- a/spk/owncloud/src/service-setup.sh +++ b/spk/owncloud/src/service-setup.sh @@ -15,6 +15,7 @@ SQLITE="/bin/sqlite3" JQ="/bin/jq" SED="/bin/sed" SYNOSVC="/usr/syno/sbin/synoservice" +VER_NUM=$(echo ${SYNOPKG_PKGVER} | cut -d'-' -f1) if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then GROUP="http" @@ -59,6 +60,50 @@ exec_occ() { return $? } +setup_owncloud_instance() +{ + if [ "${SYNOPKG_PKG_STATUS}" = "INSTALL" ]; then + # Setup configuration file + exec_occ maintenance:install \ + --database "sqlite" \ + --database-name "${SYNOPKG_PKGNAME}" \ + --data-dir "${DATA_DIR}" \ + --admin-user "${wizard_owncloud_admin_username}" \ + --admin-pass "${wizard_owncloud_admin_password}" 2>&1 + + # Get the trusted domains + DOMAINS="$(exec_occ config:system:get trusted_domains)" + + # Fix trusted domains array + line_number=0 + echo "${DOMAINS}" | while read -r line; do + if [ "$(echo "$line" | grep -cE ':5000|:5001')" -gt 0 ]; then + # Remove ":5000" or ":5001" from the line and update the trusted_domains array + new_line=$(echo "$line" | ${SED} -E 's/(:5000|:5001)//') + exec_occ config:system:set trusted_domains $line_number --value="$new_line" + fi + line_number=$((line_number+1)) + done + # Add user specified trusted domains + line_number=$(( $(echo -ne "$DOMAINS" | wc -l) + 1 )) + for var in wizard_owncloud_trusted_domain_1 wizard_owncloud_trusted_domain_2 wizard_owncloud_trusted_domain_3; do + val="${!var}" + if [ -n "$val" ]; then + exec_occ config:system:set trusted_domains $line_number --value="$val" + line_number=$((line_number+1)) + fi + done + + # Add HTTP to HTTPS redirect to Apache configuration file + APACHE_CONF="${OCROOT}/.htaccess" + if [ -f "${APACHE_CONF}" ]; then + echo "RewriteEngine On" >> ${APACHE_CONF} + echo "RewriteCond %{HTTPS} off" >> ${APACHE_CONF} + echo "RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]" >> ${APACHE_CONF} + fi + fi +} + service_postinst () { if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then @@ -145,43 +190,47 @@ service_postinst () set_owncloud_permissions ${OCROOT} ${DATA_DIR} fi - # Setup configuration file - exec_occ maintenance:install \ - --database "sqlite" \ - --database-name "${SYNOPKG_PKGNAME}" \ - --data-dir "${DATA_DIR}" \ - --admin-user "${wizard_owncloud_admin_username}" \ - --admin-pass "${wizard_owncloud_admin_password}" 2>&1 - - # Get the trusted domains - DOMAINS="$(exec_occ config:system:get trusted_domains)" - - # Fix trusted domains array - line_number=0 - echo "${DOMAINS}" | while read -r line; do - if [ "$(echo "$line" | grep -cE ':5000|:5001')" -gt 0 ]; then - # Remove ":5000" or ":5001" from the line and update the trusted_domains array - new_line=$(echo "$line" | ${SED} -E 's/(:5000|:5001)//') - exec_occ config:system:set trusted_domains $line_number --value="$new_line" - fi - line_number=$((line_number+1)) - done - # Add user specified trusted domains - line_number=$(( $(echo -ne "$DOMAINS" | wc -l) + 1 )) - for var in wizard_owncloud_trusted_domain_1 wizard_owncloud_trusted_domain_2 wizard_owncloud_trusted_domain_3; do - val="${!var}" - if [ -n "$val" ]; then - exec_occ config:system:set trusted_domains $line_number --value="$val" - line_number=$((line_number+1)) + # Check backup file path + if [ -n "${wizard_backup_file}" ] && [ -f "${wizard_backup_file}" ]; then + filename=$(basename "${wizard_backup_file}") + expected_prefix="${SYNOPKG_PKGNAME}_backup_v" + # Check backup file prefix + if [[ $filename == ${expected_prefix}* ]]; then + echo "The backup filename starts with the expected prefix, performing restore." + # Extract archive to temp folder + TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}" + ${MKDIR} "${TEMPDIR}" + /bin/tar -xzvf "${wizard_backup_file}" -C "${TEMPDIR}" 2>&1 + + # Restore configuration files and directories + rsync -Aax --update -I "${TEMPDIR}/configs/root/.user.ini" "${TEMPDIR}/configs/root/.htaccess" "${OCROOT}/" 2>&1 + rsync -Aax --update -I "${TEMPDIR}/configs/config" "${TEMPDIR}/configs/data" "${TEMPDIR}/configs/apps" "${TEMPDIR}/configs/apps-external" "${OCROOT}/" 2>&1 + + # Restore user data + echo "Restoring user data to ${DATA_DIR}" + rsync -Aax --update -I "${TEMPDIR}/data" "${DATA_DIR}/" 2>&1 + + # Place server in maintenance mode + exec_occ maintenance:mode --on + + # Restore the Database + [ -f "${DATA_DIR}/${SYNOPKG_PKGNAME}.db" ] && ${RM} "${DATA_DIR}/${SYNOPKG_PKGNAME}.db" + ${SQLITE} "${DATA_DIR}/${SYNOPKG_PKGNAME}.db" < "${TEMPDIR}/database/${SYNOPKG_PKGNAME}.db" 2>&1 + + # Update the systems data-fingerprint after a backup is restored + exec_occ maintenance:data-fingerprint + + # Disable maintenance mode + exec_occ maintenance:mode --off + + # Clean-up temporary files + ${RM} "${TEMPDIR}" + else + echo "The backup filename does not start with the expected prefix, performing new install." + setup_owncloud_instance fi - done - - # Add HTTP to HTTPS redirect to Apache configuration file - APACHE_CONF="${OCROOT}/.htaccess" - if [ -f "${APACHE_CONF}" ]; then - echo "RewriteEngine On" >> ${APACHE_CONF} - echo "RewriteCond %{HTTPS} off" >> ${APACHE_CONF} - echo "RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]" >> ${APACHE_CONF} + else + setup_owncloud_instance fi # Fix permissions @@ -205,52 +254,37 @@ service_preuninst () fi # Prepare archive structure - TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}-backup_$(date +"%Y%m%d")" + TEMPDIR="${SYNOPKG_PKGTMP}/${SYNOPKG_PKGNAME}_backup_v$(VER_NUM)_$(date +"%Y%m%d")" ${MKDIR} "${TEMPDIR}" - # Check database export - if [ "${wizard_export_database}" = "true" ]; then - echo "Copying previous database from ${DATADIR}" - ${MKDIR} "${TEMPDIR}/database" - ${SQLITE} "${DATADIR}/${SYNOPKG_PKGNAME}.db" ".backup '${TEMPDIR}/database/${SYNOPKG_PKGNAME}.db'" 2>&1 - fi + # Place server in maintenance mode + exec_occ maintenance:mode --on - # Check configuration export - if [ "${wizard_export_configs}" = "true" ]; then - echo "Copying previous configuration from ${OCROOT}" - ${MKDIR} "${TEMPDIR}/configs" - ${CP} "${OCROOT}/.user.ini" "${TEMPDIR}/configs/" - ${CP} "${OCROOT}/.htaccess" "${TEMPDIR}/configs/" - ${MKDIR} "${TEMPDIR}/configs/config" - source="${OCROOT}/config" - patterns=( - "*config.php" - "*.json" - ) - target="${TEMPDIR}/configs/config" - # Process each pattern of files in the source directory - for pattern in "${patterns[@]}"; do - files=$(find "$source" -type f -name "$pattern") - if [ -n "$files" ]; then - for file in "${files[@]}"; do - ${CP} "$file" "$target/" - done - fi - done - fi + # Backup the Database + echo "Copying previous database from ${DATADIR}" + ${MKDIR} "${TEMPDIR}/database" + ${SQLITE} "${DATADIR}/${SYNOPKG_PKGNAME}.db" ".backup '${TEMPDIR}/database/${SYNOPKG_PKGNAME}.db'" 2>&1 - # Check user data export - if [ "${wizard_export_userdata}" = "true" ]; then - echo "Copying previous user data from ${DATADIR}" - ${CP} "${DATADIR}" "${TEMPDIR}/" - fi + # Backup Directories + echo "Copying previous configuration from ${OCROOT}" + ${MKDIR} "${TEMPDIR}/configs/root" + rsync -Aax "${OCROOT}/.user.ini" "${OCROOT}/.htaccess" "${TEMPDIR}/configs/root/" 2>&1 + rsync -Aax "${OCROOT}/config" "${OCROOT}/data" "${OCROOT}/apps" "${OCROOT}/apps-external" "${TEMPDIR}/configs/" 2>&1 + + # Backup user data + echo "Copying previous user data from ${DATADIR}" + rsync -Aax "${DATADIR}" "${TEMPDIR}/" 2>&1 + + # Disable maintenance mode + exec_occ maintenance:mode --off # Create backup archive archive_name="$(basename "$TEMPDIR").tar.gz" echo "Creating compressed archive of ownCloud data in file $archive_name" - /bin/tar -czvf "${SYNOPKG_PKGTMP}/$archive_name" "$TEMPDIR" 2>&1 + /bin/tar -C "$TEMPDIR" -czvf "${SYNOPKG_PKGTMP}/$archive_name" . 2>&1 # Move archive to export directory + ${MKDIR} "${wizard_export_path}" if ${RSYNC} "${SYNOPKG_PKGTMP}/$archive_name" "${wizard_export_path}/"; then echo "Backup file copied successfully to ${wizard_export_path}." else @@ -378,9 +412,8 @@ service_restore () if [ -f ${SYNOPKG_TEMP_UPGRADE_FOLDER}/.datadirectory ]; then DATAPATH="$(cat ${SYNOPKG_TEMP_UPGRADE_FOLDER}/.datadirectory)" # Data directory inside owncloud directory and needs to be restored - [ -d ${OCROOT}/${DATAPATH} ] && ${RM} ${OCROOT}/${DATAPATH} echo "Restore previous data directory from ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/${DATAPATH}" - rsync -aX ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/${DATAPATH} ${OCROOT}/ 2>&1 + rsync -aX --update -I ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/${DATAPATH} ${OCROOT}/ 2>&1 ${RM} ${SYNOPKG_TEMP_UPGRADE_FOLDER}/.datadirectory fi @@ -397,19 +430,15 @@ service_restore () files=$(find "$source" -type f -name "$pattern") if [ -n "$files" ]; then for file in "${files[@]}"; do - file_name=$(basename "$file") - [ -f $target/$file_name ] && ${RM} $target/$file_name - rsync -aX "$file" "$target/" 2>&1 + rsync -aX --update -I "$file" "$target/" 2>&1 done fi done if [ -f ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/.user.ini ]; then - [ -f ${OCROOT}/.user.ini ] && ${RM} ${OCROOT}/.user.ini - rsync -aX ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/.user.ini ${OCROOT}/ 2>&1 + rsync -aX --update -I ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/.user.ini ${OCROOT}/ 2>&1 fi if [ -f ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/.htaccess ]; then - [ -f ${OCROOT}/.htaccess ] && ${RM} ${OCROOT}/.htaccess - rsync -aX ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/.htaccess ${OCROOT}/ 2>&1 + rsync -aX --update -I ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}/.htaccess ${OCROOT}/ 2>&1 fi echo "Restore manually installed apps from ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${SYNOPKG_PKGNAME}" diff --git a/spk/owncloud/src/wizard_templates/install_uifile.sh b/spk/owncloud/src/wizard_templates/install_uifile.sh index 005fe23af3e..f0bfed81d94 100644 --- a/spk/owncloud/src/wizard_templates/install_uifile.sh +++ b/spk/owncloud/src/wizard_templates/install_uifile.sh @@ -1,14 +1,9 @@ #!/bin/bash -WEB_DIR="/var/services/web_packages" # for backwards compatability -if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 7 ]; then - WEB_DIR="/var/services/web" -fi if [ -z ${SYNOPKG_PKGDEST_VOL} ]; then SYNOPKG_PKGDEST_VOL="/volume1" fi -OCROOT="${WEB_DIR}/${SYNOPKG_PKGNAME}" SHAREDIR="${SYNOPKG_PKGNAME}" DIR_VALID="/^[\\w _-]+$/" @@ -27,30 +22,98 @@ page_append () fi } +BACKUP_FILE_PATH="wizard_backup_file" + +getBackupFile() +{ + BACKUP_FILE=$(/bin/cat<= 0 ; i--) { + var step = wizardDialog.getStep(wizardDialog.customuiIds[i]); + if (title === step.headline) { + return step; + } + } + return null; + } + function isRestoreChecked(wizardDialog) { + var restoreStep = findStepByTitle(wizardDialog, "{{{OWNCLOUD_INSTALL_RESTORE_STEP_TITLE}}}"); + if (!restoreStep) { + return false; + } else { + return restoreStep.items.items[1].checked; + } + } +EOF +) + +getActiveate() +{ + ACTIVAETE=$(/bin/cat<WARNING: Uninstalling the ownCloud package will result in the removal of the ownCloud server, along with all associated user accounts, data, and configurations." OWNCLOUD_BACKUP_EXPORT_LOCATION_DESCRIPTION: "Before uninstalling, if you want to keep a backup of your data, please specify the directory where you would like to export to. Ensure that the user 'sc-owncloud' has write permissions to that directory. To skip exporting, leave this field blank." OWNCLOUD_BACKUP_EXPORT_LOCATION_LABEL: "Export location" -OWNCLOUD_BACKUP_ITEMS_DESCRIPTION: "Please choose the items that you want to include in the backup." -OWNCLOUD_BACKUP_ITEM_DATABASE_LABEL: "Include database" -OWNCLOUD_BACKUP_ITEM_CONFIGS_LABEL: "Include configuration files" -OWNCLOUD_BACKUP_ITEM_USERDATA_LABEL: "Include user data (${DATASIZE})" diff --git a/spk/owncloud/src/wizard_templates/uninstall_uifile_fre.yml b/spk/owncloud/src/wizard_templates/uninstall_uifile_fre.yml index bee131023c3..91bf55d574a 100644 --- a/spk/owncloud/src/wizard_templates/uninstall_uifile_fre.yml +++ b/spk/owncloud/src/wizard_templates/uninstall_uifile_fre.yml @@ -4,7 +4,3 @@ OWNCLOUD_BACKUP_SERVER_STEP_TITLE: "Sauvegarder le serveur ownCloud" OWNCLOUD_BACKUP_SERVER_DESCRIPTION: "AVERTISSEMENT: La désinstallation du package ownCloud entraînera la suppression du serveur ownCloud, ainsi que de tous les comptes d'utilisateurs, données et configurations associés." OWNCLOUD_BACKUP_EXPORT_LOCATION_DESCRIPTION: "Avant la désinstallation, si vous souhaitez conserver une sauvegarde de vos données, veuillez spécifier le répertoire vers lequel vous souhaitez exporter. Assurez-vous que l'utilisateur 'sc-owncloud' dispose des autorisations d'écriture dans ce répertoire. Pour ignorer l'exportation, laissez ce champ vide." OWNCLOUD_BACKUP_EXPORT_LOCATION_LABEL: "Emplacement d'exportation" -OWNCLOUD_BACKUP_ITEMS_DESCRIPTION: "Choisissez les éléments que vous souhaitez inclure dans la sauvegarde." -OWNCLOUD_BACKUP_ITEM_DATABASE_LABEL: "Inclure la base de données" -OWNCLOUD_BACKUP_ITEM_CONFIGS_LABEL: "Inclure les fichiers de configuration" -OWNCLOUD_BACKUP_ITEM_USERDATA_LABEL: "Inclure les données utilisateur (${DATASIZE})" diff --git a/spk/owncloud/src/wizard_templates/upgrade_uifile.sh b/spk/owncloud/src/wizard_templates/upgrade_uifile.sh index 55b0f68cf8f..b1e8c006322 100644 --- a/spk/owncloud/src/wizard_templates/upgrade_uifile.sh +++ b/spk/owncloud/src/wizard_templates/upgrade_uifile.sh @@ -1,14 +1,5 @@ #!/bin/bash -WEB_DIR="/var/services/web_packages" -# for backwards compatability -if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 7 ]; then - WEB_DIR="/var/services/web" - if [ -z ${SYNOPKG_PKGNAME} ]; then - SYNOPKG_PKGNAME="owncloud" - fi -fi -OCROOT="${WEB_DIR}/${SYNOPKG_PKGNAME}" OC_NEW_VER=$(echo ${SYNOPKG_PKGVER} | cut -d'-' -f1) OC_OLD_VER=$(echo ${SYNOPKG_OLD_PKGVER} | cut -d'-' -f1)