Change : Backup pick

This commit is contained in:
2026-06-21 00:20:37 +01:00
parent c3e3a3b28c
commit bf9c4a01b2
3 changed files with 219 additions and 24 deletions

View File

@@ -43,6 +43,10 @@ app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
restore_jobs = {}
backup_jobs = {}
# Whitelist of apps the restore script knows how to selectively restore.
# Anything not in this set is silently dropped before it ever reaches a shell string.
ALLOWED_RESTORE_APPS = {'frappe', 'odoo', 'nextcloud', 'mautic', 'n8n'}
def _stream_restore(job_id, cmd):
restore_jobs[job_id] = {'status': 'running', 'log': [], 'started': time.time()}
@@ -732,6 +736,20 @@ def restore_start():
if not backup_file:
return jsonify({'error': 'No backup file specified'}), 400
# ── Selective app restore ────────────────────────────────────
# `apps` is optional. Empty/missing => full restore (all apps).
# Anything not in ALLOWED_RESTORE_APPS is dropped before it can
# reach a shell string.
raw_apps = data.get('apps', [])
if isinstance(raw_apps, str):
raw_apps = [a.strip() for a in raw_apps.split(',') if a.strip()]
selected_apps = sorted({
a.strip().lower() for a in raw_apps
if isinstance(a, str) and a.strip().lower() in ALLOWED_RESTORE_APPS
})
apps_flag = f" --apps {','.join(selected_apps)}" if selected_apps else ""
apps_label = ','.join(selected_apps) if selected_apps else 'ALL'
# ── Resolve backup path by source ────────────────────────────
if backup_source == 'cloud':
backup_path = f"/tmp/{backup_file}"
@@ -794,12 +812,13 @@ def restore_start():
cmd = (
f"set -e && "
f"echo 'Restoring on this server ({hostname})...' && "
f"echo 'Apps: {apps_label}' && "
f"mkdir -p {session_dir} && "
f"echo 'Extracting backup...' && "
f"tar -xzf {backup_path} -C {session_dir} --strip-components=1 && "
f"cp {restore_script_local} {session_dir}/restore-myapps.sh && "
f"chmod +x {session_dir}/restore-myapps.sh && "
f"cd {session_dir} && bash restore-myapps.sh ; "
f"cd {session_dir} && bash restore-myapps.sh{apps_flag} ; "
f"EXIT=$? ; rm -rf {session_dir} ; exit $EXIT"
)
else:
@@ -821,6 +840,7 @@ def restore_start():
remote_dest = f"/backups/restore-session-{uuid.uuid4().hex[:8]}"
cmd = (
f"echo 'Connecting to {remote_user}@{remote_ip}:{remote_port}...' && "
f"echo 'Apps: {apps_label}' && "
f"{ssh_prefix} {remote_user}@{remote_ip} 'mkdir -p {remote_dest}' && "
f"echo 'Connected.' && "
f"echo 'Copying backup archive...' && "
@@ -831,7 +851,7 @@ def restore_start():
f"{ssh_prefix} {remote_user}@{remote_ip} "
f"'set -e && cd {remote_dest} && "
f"tar -xzf {backup_file} --strip-components=1 && "
f"chmod +x restore-myapps.sh && bash restore-myapps.sh' ; "
f"chmod +x restore-myapps.sh && bash restore-myapps.sh{apps_flag}' ; "
f"EXIT=$? ; "
f"{ssh_prefix} {remote_user}@{remote_ip} 'rm -rf {remote_dest}' 2>/dev/null ; "
f"exit $EXIT"