From 39949bb7db472001e551749316abe4601c3ddc1b Mon Sep 17 00:00:00 2001 From: Mate Majoros Date: Tue, 13 Jan 2026 14:37:30 +0200 Subject: [PATCH] custom backup dir path can be specified from now on --- .github/workflows/restore-site.yml | 76 +++++++++++++++++------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/.github/workflows/restore-site.yml b/.github/workflows/restore-site.yml index bf4e901e..7b6240d1 100644 --- a/.github/workflows/restore-site.yml +++ b/.github/workflows/restore-site.yml @@ -17,7 +17,11 @@ on: required: true type: string backup_timestamp: - description: 'Backup timestamp (e.g., 20260109_142920) - leave empty to use latest' + description: '(Optional) Backup timestamp (e.g., 20260109_142920) - leave empty to use latest' + required: false + type: string + absolute_backup_dir_path: + description: '(Optional) Absolute path to the backup directory (the backup files contained in the directory should match the the following naming convention: --database.sql.gz, --files.tar, --private-files.tar.gz)' required: false type: string @@ -126,46 +130,50 @@ jobs: cd ${{ env.DEPLOY_PATH }} docker compose exec -T backend bash -c ' - # Check both possible archived locations - if [ -d /home/frappe/frappe-bench/archived/sites ]; then - ARCHIVED_BASE=/home/frappe/frappe-bench/archived/sites - elif [ -d /home/frappe/frappe-bench/archived_sites ]; then - ARCHIVED_BASE=/home/frappe/frappe-bench/archived_sites + if [ -n \"${{ github.event.inputs.absolute_backup_dir_path }}\" ]; then + BACKUP_DIR=\"${{ github.event.inputs.absolute_backup_dir_path }}\" else - echo \"ERROR: No archived sites directory found\" - exit 1 - fi - - # Find the archived site directory matching criteria - INPUT_TIMESTAMP=\"${{ github.event.inputs.backup_timestamp }}\" - - if [ -n \"\$INPUT_TIMESTAMP\" ]; then - echo \"Searching for archived site containing backup timestamp: \$INPUT_TIMESTAMP\" - ARCHIVED_SITE=\"\" - # Loop through all matching site directories to find one with the specific backup - for site_dir in \$(ls -d \"\$ARCHIVED_BASE\"/${{ github.event.inputs.site_name }}* 2>/dev/null); do - if ls \"\$site_dir/private/backups/\${INPUT_TIMESTAMP}\"-*-database.sql.gz 1> /dev/null 2>&1; then - ARCHIVED_SITE=\"\$site_dir\" - break + # Check both possible archived locations + if [ -d /home/frappe/frappe-bench/archived/sites ]; then + ARCHIVED_BASE=/home/frappe/frappe-bench/archived/sites + elif [ -d /home/frappe/frappe-bench/archived_sites ]; then + ARCHIVED_BASE=/home/frappe/frappe-bench/archived_sites + else + echo \"ERROR: No archived sites directory found\" + exit 1 + fi + + # Find the archived site directory matching criteria + INPUT_TIMESTAMP=\"${{ github.event.inputs.backup_timestamp }}\" + + if [ -n \"\$INPUT_TIMESTAMP\" ]; then + echo \"Searching for archived site containing backup timestamp: \$INPUT_TIMESTAMP\" + ARCHIVED_SITE=\"\" + # Loop through all matching site directories to find one with the specific backup + for site_dir in \$(ls -d \"\$ARCHIVED_BASE\"/${{ github.event.inputs.site_name }}* 2>/dev/null); do + if ls \"\$site_dir/private/backups/\${INPUT_TIMESTAMP}\"-*-database.sql.gz 1> /dev/null 2>&1; then + ARCHIVED_SITE=\"\$site_dir\" + break + fi + done + + if [ -z \"\$ARCHIVED_SITE\" ]; then + echo \"ERROR: No archived site folder for ${{ github.event.inputs.site_name }} contains backup \$INPUT_TIMESTAMP\" + exit 1 fi - done + else + # Default: take the latest archived folder + ARCHIVED_SITE=\$(ls -td \"\$ARCHIVED_BASE\"/${{ github.event.inputs.site_name }}* 2>/dev/null | head -n 1) + fi if [ -z \"\$ARCHIVED_SITE\" ]; then - echo \"ERROR: No archived site folder for ${{ github.event.inputs.site_name }} contains backup \$INPUT_TIMESTAMP\" - exit 1 + echo \"ERROR: No archived backup found for site ${{ github.event.inputs.site_name }}\" + exit 1 fi - else - # Default: take the latest archived folder - ARCHIVED_SITE=\$(ls -td \"\$ARCHIVED_BASE\"/${{ github.event.inputs.site_name }}* 2>/dev/null | head -n 1) + + BACKUP_DIR=\"\$ARCHIVED_SITE/private/backups\" fi - if [ -z \"\$ARCHIVED_SITE\" ]; then - echo \"ERROR: No archived backup found for site ${{ github.event.inputs.site_name }}\" - exit 1 - fi - - BACKUP_DIR=\"\$ARCHIVED_SITE/private/backups\" - if [ ! -d \"\$BACKUP_DIR\" ]; then echo \"ERROR: Backup directory not found: \$BACKUP_DIR\" exit 1