Skip to content

Patrick010/Proxmox-DR-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Proxmox VE Disaster Recovery Scripts

(Highly experimental. Be sure to test thoroughly!)

This repository contains a two-part script set designed to simplify Proxmox VE Disaster Recovery:

  1. pve-backup.sh — Creates comprehensive backups of your Proxmox configuration and essential system files.
  2. pve-restore.sh — Recovers your Proxmox system configuration from backups created by the backup script, with integrated VM and container restore options.

Key points:

  • The recovery script strictly depends on backups generated with the matching pve-backup.sh script to ensure consistency and reliability.
  • Backup includes critical configuration files, network settings, user credentials, cron jobs, SSH keys, Proxmox cluster configs, logs, and more.
  • Before any recovery, the script automatically creates a rollback snapshot to safeguard the current state, enabling easy rollback if needed.
  • User confirmation is required before recovery to prevent accidental overwrites.
  • The restore script supports restoring VMs and containers separately using Proxmox native tools (qmrestore and pct restore), with interactive selection and multiple restores.
  • Designed for Proxmox VE environments with a focus on preserving cluster and VM container configurations.

Why use these scripts?

Managing Proxmox configuration backups manually or through partial methods is error-prone and time-consuming. This script set automates the process end-to-end, providing:

  • Reliable full config backups including cluster configuration, network settings, user credentials, cron jobs, SSH keys, logs, and more.
  • Safe restoration Recovery script supports rollback snapshots to safely revert changes.
  • Interactive VM/CT restore User selects backup location and restores VMs/containers separately with prompts, reducing risk of errors.
  • Checksum verification Verifies SHA256 hash with user override option if missing.
  • Clear logging All backup and recovery steps are logged for audit and troubleshooting.
  • Selectable backups and source location Shows available backup archives on a configurable location.

Contributions welcome

Feel free to:

  • Improve error handling
  • Extend backup scope for additional Proxmox features and files
  • Optimize restore processes for faster recovery
  • Add integration with Proxmox or automation tools

Make sure to use the backup script first to generate your backups before relying on the recovery script.


Features

  • Full snapshot of critical configuration files, networking, cron, SSH, firewall, apt state, logs, and other key system areas
  • SHA256 hash file is generated with each backup for optional integrity verification on restore
  • Recovery script verifies backup hashes and prompts user to continue or abort if checksum file is missing
  • Rollback snapshots created before applying changes
  • Dry-run mode shows exactly what would happen without modifying the system
  • Selectable archives, custom backup directory support
  • Optional email alerts on scheduled backup failure via --email-to (requires working mail setup)
  • Interactive VM and container restore using qmrestore and pct restore
  • Lists backups in user-provided directory for selection and multiple restores
  • Reminds user that reboot is required to finalize restoration

Usage

1. Backup Proxmox Configuration

Run the backup script to create a compressed archive of your system configuration.

sudo ./pve-backup.sh [--dry-run] [--backup-dir /path/to/backups] [--keep-days N] [--email-to [email protected]] [--ignore-hash]

Scheduled backup via crontab:

To automate backups, add a cron job like the following (adjust options and timing as needed):

0 3 * * * root /path/to/pve-backup.sh --backup-dir /path/to/backups --keep-days 7 --email-to your@email

Flags:

  • --dry-run : Show the steps that would be performed without making any changes. (should not be used in crontab)
  • --backup-dir : (Optional) Specify the target directory where the backup archive will be stored. Defaults to /mnt/pve/pvebackup/dump.
  • --keep-days : (Optional) Set the number of days to retain old backups. Defaults to 7.
  • --email-to : (Optional) Address to send alerts to if backup fails. (Requires working mail client on host).

Backups include essential system and Proxmox configuration files, VM and container configs, storage definitions, cron jobs, ssh keys, apt state, and more. The script also creates a SHA256 checksum for verification and cleans up old backups based on the retention period.

A detailed log of the backup process is saved to /var/log/pve-backup.log.

2. Restore Proxmox Configuration

Run the recovery script to restore a previous backup.

sudo ./pve-restore.sh [--recover | --rollback] [--dry-run] [--backup-dir /path/to/backups] [--ignore-hash] [--overwrite-snapshot] [--ignore-snapshot]

Flags:

  • --recover : Restore from a selectable backup archive. Creates a rollback snapshot before proceeding.
  • --rollback : Restore the rollback snapshot created during the last recovery attempt.
  • --dry-run : Show the steps that would be performed without making any changes.
  • --backup-dir : (Optional) Specify the directory containing backup archives. Defaults to /mnt/pve/pvebackup/dump.
  • --ignore-hash : (Optional) Skip SHA256 verification of backup archive, even if a .sha256 file exists.
  • --ignore-snapshot : (Optional) Skip creating a rollback snapshot before restoration.
  • --overwrite-snapshot : (Optional) Automatically overwrite existing rollback snapshot without prompting.

The script will prompt you to select which backup archive to restore if multiple exist.

After restoring system files, you will be asked if you want to restore VMs or containers now. You can provide the directory containing VM/CT backups, choose backups to restore, and perform multiple restores interactively.

You will be asked to confirm all critical operations before proceeding.


How It Works

  • Backup Script

    • Archives all relevant Proxmox and system configuration files into a timestamped tarball.
    • VM or containers disks are NOT included!
  • Restore Script

    • Before restoring, saves the current system configuration as a rollback snapshot in your home directory (~/recover-rollback.tar.gz).
    • Allows restoring from that rollback snapshot if needed.
    • Stops and restarts relevant services during restoration to ensure consistency.
    • Prompts user for VM/container backup location and restores selected backups using Proxmox-native tools (qmrestore and pct restore).
    • Supports multiple restores and flexible input for confirmation prompts.
    • Reminds user a system reboot is mandatory after restoration to apply changes.

Notes

  • These scripts are designed for disaster recovery of Proxmox VE configuration only — they do not back up or restore any VM or container disk data.
  • After restoring the PVE configuration, you must manually restore your VM or CT disk images separately, either by using your existing backup solution (PBS, external storage, ZFS, etc.), or by using the integrated restore option in this script.
  • The script set is focused solely on backup and recovery of the Proxmox platform and its configuration, not the guest virtual machines themselves.
  • Always verify backups and test the full DR workflow in a non-production environment before relying on these scripts in critical setups.

Contributing

Contributions, improvements, and suggestions are welcome to improve the scripts. Suggestions and fixes are welcome to make this toolkit more reliable and user-friendly.


License

This project is licensed under the GNU GPLv3 license, so all modifications and derivatives remain open source and freely available.


Disclaimer

Use these scripts at your own risk. Always verify backups and test recovery procedures in a safe environment before relying on them in production.

About

Proxmox PVE Disaster Recovery scripts (Backup and Restore of critical system files)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages