handling the case when we have multiple archived directories with the same name

This commit is contained in:
Mate Majoros 2026-01-12 11:12:38 +02:00
parent 396cc3f2a5
commit 905d8f5f91

View file

@ -154,7 +154,7 @@ jobs:
fi fi
# Drop the site (this will create backup files automatically) # Drop the site (this will create backup files automatically)
docker compose exec -T backend bench drop-site ${{ github.event.inputs.site_name }} --db-root-password \$MARIADB_ROOT_PASSWORD --archived-sites-path /home/frappe/frappe-bench/archived/sites/${{ github.event.inputs.site_name }} --force docker compose exec -T backend bench drop-site ${{ github.event.inputs.site_name }} --db-root-password \$MARIADB_ROOT_PASSWORD --force
" "
- name: Verify site removal - name: Verify site removal
@ -181,8 +181,8 @@ jobs:
ssh ${{ env.HETZNER_USER }}@${{ env.HETZNER_HOST }} " ssh ${{ env.HETZNER_USER }}@${{ env.HETZNER_HOST }} "
cd ${{ env.DEPLOY_PATH }} cd ${{ env.DEPLOY_PATH }}
# Remove the backup files # Remove the backup files (there could be multiple same site name backup folders with incremented numbers at the end in case of multiple removals)
docker compose exec -T backend rm -rf ~/frappe-bench/archived/sites/${{ github.event.inputs.site_name }} docker compose exec -T backend rm -rf /home/frappe/frappe-bench/archived/sites/${{ github.event.inputs.site_name }}*
" "
@ -197,16 +197,28 @@ jobs:
cd ${{ env.DEPLOY_PATH }} cd ${{ env.DEPLOY_PATH }}
BACKUP_INFO=\$(docker compose exec -T backend bash -c \" BACKUP_INFO=\$(docker compose exec -T backend bash -c \"
cd ~/frappe-bench/archived/sites/${{ github.event.inputs.site_name }}/private/backups 2>/dev/null || exit 1 # Match the site directory in archived/sites (it might have an incremented suffix)
cd /home/frappe/frappe-bench/archived/sites/ 2>/dev/null || exit 1
# Get the latest timestamp (from any file) # Find latest directory matching site_name* (sorted by time)
LATEST_TIMESTAMP=\\\$(ls -t *.sql.gz 2>/dev/null | head -n 1 | cut -d'-' -f1) LATEST_DIR=\\\$(ls -td ${{ github.event.inputs.site_name }}* 2>/dev/null | head -n 1)
if [ -n \\\"\\\$LATEST_TIMESTAMP\\\" ]; then if [ -n \\\"\\\$LATEST_DIR\\\" ]; then
echo \\\"TIMESTAMP=\\\$LATEST_TIMESTAMP\\\" echo \\\"ARCHIVED_DIR=\\\$LATEST_DIR\\\"
ls -lh \\\${LATEST_TIMESTAMP}-* 2>/dev/null | awk '{print \\\$9, \\\$5}' || echo 'No files found' cd \\\"\\\$LATEST_DIR/private/backups\\\" 2>/dev/null || exit 1
# Get the latest timestamp (from any file)
LATEST_TIMESTAMP=\\\$(ls -t *.sql.gz 2>/dev/null | head -n 1 | cut -d'-' -f1)
if [ -n \\\"\\\$LATEST_TIMESTAMP\\\" ]; then
echo \\\"TIMESTAMP=\\\$LATEST_TIMESTAMP\\\"
ls -lh \\\${LATEST_TIMESTAMP}-* 2>/dev/null | awk '{print \\\$9, \\\$5}' || echo 'No files found'
else
echo 'No backups found'
fi
else else
echo 'No backups found' echo 'No archived directory found'
exit 1
fi fi
\") \")
@ -222,7 +234,7 @@ jobs:
echo \"✅ Site removed successfully!\" echo \"✅ Site removed successfully!\"
echo \"\" echo \"\"
echo \"📦 Backup location:\" echo \"📦 Backup location:\"
echo \" ~/frappe-bench/archived/sites/${{ github.event.inputs.site_name }}/private/backups/\" echo \" /home/frappe/frappe-bench/archived/sites/\$ARCHIVED_DIR/private/backups/\"
echo \"\" echo \"\"
echo \"📋 Backup files (timestamp: \$TIMESTAMP):\" echo \"📋 Backup files (timestamp: \$TIMESTAMP):\"
echo \"\$FILES\" | sed 's/^/ - /' echo \"\$FILES\" | sed 's/^/ - /'