mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-02-18 16:36:27 +00:00
Update flask_server.py
This commit is contained in:
@@ -5650,19 +5650,36 @@ def api_create_backup(vmid):
|
|||||||
notes = notes.replace('{{vmid}}', str(vmid))
|
notes = notes.replace('{{vmid}}', str(vmid))
|
||||||
notes = notes.replace('{{node}}', node or '')
|
notes = notes.replace('{{node}}', node or '')
|
||||||
|
|
||||||
# Build vzdump command directly (more reliable than pvesh for backups)
|
# Check if storage is PBS (Proxmox Backup Server)
|
||||||
|
is_pbs = False
|
||||||
|
try:
|
||||||
|
storage_result = subprocess.run(
|
||||||
|
['pvesh', 'get', f'/storage/{storage}', '--output-format', 'json'],
|
||||||
|
capture_output=True, text=True, timeout=10
|
||||||
|
)
|
||||||
|
if storage_result.returncode == 0:
|
||||||
|
storage_info = json.loads(storage_result.stdout)
|
||||||
|
is_pbs = storage_info.get('type') == 'pbs'
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Build pvesh command: pvesh create /nodes/<NODE>/vzdump --vmid <ID> --storage <STORAGE> --mode <MODE> [--compress <COMPRESS>]
|
||||||
cmd = [
|
cmd = [
|
||||||
'vzdump', str(vmid),
|
'pvesh', 'create', f'/nodes/{node}/vzdump',
|
||||||
|
'--vmid', str(vmid),
|
||||||
'--storage', storage,
|
'--storage', storage,
|
||||||
'--mode', mode,
|
'--mode', mode
|
||||||
'--compress', compress
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Only add --compress for non-PBS storage (PBS handles compression/deduplication internally)
|
||||||
|
if not is_pbs:
|
||||||
|
cmd.extend(['--compress', compress])
|
||||||
|
|
||||||
# Add protected flag if enabled (use 1 for true)
|
# Add protected flag if enabled (use 1 for true)
|
||||||
if protected:
|
if protected:
|
||||||
cmd.extend(['--protected', '1'])
|
cmd.extend(['--protected', '1'])
|
||||||
|
|
||||||
# Add notes if provided (use --description for compatibility)
|
# Add notes if provided
|
||||||
if notes:
|
if notes:
|
||||||
cmd.extend(['--notes-template', notes])
|
cmd.extend(['--notes-template', notes])
|
||||||
|
|
||||||
@@ -5670,16 +5687,16 @@ def api_create_backup(vmid):
|
|||||||
if pbs_change_detection and pbs_change_detection != 'default' and vm_type == 'lxc':
|
if pbs_change_detection and pbs_change_detection != 'default' and vm_type == 'lxc':
|
||||||
cmd.extend(['--pbs-change-detection-mode', pbs_change_detection])
|
cmd.extend(['--pbs-change-detection-mode', pbs_change_detection])
|
||||||
|
|
||||||
# Execute vzdump - it will create a Proxmox task automatically
|
# Execute pvesh command - this creates a task in Proxmox
|
||||||
# Run in background using shell
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
|
||||||
cmd_str = ' '.join(cmd)
|
|
||||||
subprocess.Popen(
|
if result.returncode != 0:
|
||||||
cmd_str,
|
error_msg = result.stderr or result.stdout or 'Unknown error'
|
||||||
shell=True,
|
return jsonify({
|
||||||
stdout=subprocess.DEVNULL,
|
'success': False,
|
||||||
stderr=subprocess.DEVNULL,
|
'error': f'Backup failed: {error_msg}',
|
||||||
start_new_session=True
|
'command': ' '.join(cmd)
|
||||||
)
|
}), 500
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'success': True,
|
'success': True,
|
||||||
@@ -5688,7 +5705,8 @@ def api_create_backup(vmid):
|
|||||||
'mode': mode,
|
'mode': mode,
|
||||||
'compress': compress,
|
'compress': compress,
|
||||||
'protected': protected,
|
'protected': protected,
|
||||||
'notes': notes
|
'notes': notes,
|
||||||
|
'task': result.stdout.strip() if result.stdout else None
|
||||||
})
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user