Add dry-run functionality and complete backup workflow
- Comprehensive dry-run mode with detailed preview - Complete backup process orchestration - Service restart in finally block for reliability - Archive preview showing what would be backed up - Detailed configuration summary in dry-run mode
This commit is contained in:
@@ -282,6 +282,75 @@ class Docker2PBS:
|
|||||||
elif self.dry_run:
|
elif self.dry_run:
|
||||||
print(f"[DRY-RUN] Would remove temporary file: {paths_file}")
|
print(f"[DRY-RUN] Would remove temporary file: {paths_file}")
|
||||||
|
|
||||||
|
def show_dry_run_summary(self) -> None:
|
||||||
|
"""Show summary of what would be done in dry-run mode"""
|
||||||
|
print("\n=== DRY-RUN SUMMARY ===")
|
||||||
|
print(f"Service: {self.service_name}")
|
||||||
|
print(f"Compose file: {self.compose_file}")
|
||||||
|
print(f"Volumes found: {len(self.volumes)}")
|
||||||
|
print(f"Networks found: {len(self.networks)}")
|
||||||
|
|
||||||
|
print("\nVolumes configuration:")
|
||||||
|
for i, volume in enumerate(self.volumes, 1):
|
||||||
|
vol_type = volume.get('type', 'bind')
|
||||||
|
source = volume.get('source', 'N/A')
|
||||||
|
target = volume.get('target', 'N/A')
|
||||||
|
external = " (external)" if volume.get('external') else ""
|
||||||
|
print(f" {i}. {vol_type}: {source} -> {target}{external}")
|
||||||
|
|
||||||
|
print("\nNetworks configuration:")
|
||||||
|
for i, network in enumerate(self.networks, 1):
|
||||||
|
name = network.get('name', 'N/A')
|
||||||
|
external = " (external)" if network.get('external') else ""
|
||||||
|
print(f" {i}. {name}{external}")
|
||||||
|
|
||||||
|
print(f"\nPBS Repository: {self.pbs_config['repository']}")
|
||||||
|
print("\n=== END SUMMARY ===")
|
||||||
|
|
||||||
|
def run_backup(self) -> None:
|
||||||
|
"""Run the complete backup process"""
|
||||||
|
try:
|
||||||
|
mode_str = "[DRY-RUN] " if self.dry_run else ""
|
||||||
|
print(f"{mode_str}Starting backup process for service: {self.service_name}")
|
||||||
|
|
||||||
|
# Load and parse compose file
|
||||||
|
self.load_compose_file()
|
||||||
|
|
||||||
|
# Parse configuration
|
||||||
|
self.volumes = self.parse_volumes()
|
||||||
|
self.networks = self.parse_networks()
|
||||||
|
|
||||||
|
print(f"Found {len(self.volumes)} volumes and {len(self.networks)} networks")
|
||||||
|
|
||||||
|
if self.dry_run:
|
||||||
|
self.show_dry_run_summary()
|
||||||
|
print("\n=== ARCHIVE PREVIEW ===")
|
||||||
|
volume_backups = self.prepare_volume_backups()
|
||||||
|
for vb in volume_backups:
|
||||||
|
print(f" {vb['archive_name']}: {vb['source_path']} ({vb['volume_type']})")
|
||||||
|
print("=== END PREVIEW ===")
|
||||||
|
|
||||||
|
# Stop service
|
||||||
|
self.stop_service()
|
||||||
|
|
||||||
|
# Create backup
|
||||||
|
self.create_pbs_backup()
|
||||||
|
|
||||||
|
mode_str = "[DRY-RUN] " if self.dry_run else ""
|
||||||
|
print(f"{mode_str}Backup process completed successfully")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
mode_str = "[DRY-RUN] " if self.dry_run else ""
|
||||||
|
print(f"{mode_str}Backup process failed: {e}")
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
# Always try to restart the service
|
||||||
|
try:
|
||||||
|
self.start_service()
|
||||||
|
except Exception as e:
|
||||||
|
mode_str = "[DRY-RUN] " if self.dry_run else ""
|
||||||
|
print(f"{mode_str}Warning: Failed to restart service: {e}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Backup Docker service to Proxmox Backup Server')
|
parser = argparse.ArgumentParser(description='Backup Docker service to Proxmox Backup Server')
|
||||||
@@ -308,8 +377,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
backup_tool = Docker2PBS(args.compose_file, args.service_name, pbs_config, args.dry_run)
|
backup_tool = Docker2PBS(args.compose_file, args.service_name, pbs_config, args.dry_run)
|
||||||
backup_tool.load_compose_file()
|
backup_tool.run_backup()
|
||||||
print(f"Successfully loaded compose file and found service: {args.service_name}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user