A simple yet powerful shell script to back up physical servers or clients to a Proxmox Backup Server (PBS).
- Shell 100%
| backup.sh | ||
| README.md | ||
Proxmox Backup Client Script
A simple yet powerful shell script to back up physical servers or clients to a Proxmox Backup Server (PBS).
It supports:
- Dynamic folder backups
- Environment configuration via
.env - Daily cron execution
- Automatic updates
- Logging with rotation
Features
- Backup multiple directories defined in
.env - Secure API-based connection to Proxmox Backup Server
- Automatically installed as a daily cron job
- Optional auto-update from the repository
- Log rotation to avoid filling up disk space
- Exit codes ready for monitoring integration (Nagios/Icinga/Prometheus)
Installation
1. Install directly via curl
Run this command on your server:
curl -fsSL https://git.onesystems.ch/System-Tools/Proxmox-Backup-Client/raw/branch/main/backup.sh | bash -s install
This will:
- Download the latest version of the script
- Place it in
/opt/pbs-backup/ - Create a default
.envfile (you must edit it before first run) - Install a daily cron job at
/etc/cron.daily/pbs-backup
2. Configure the .env file
After installation, edit the configuration file:
nano /opt/pbs-backup/.env
Example configuration:
# Proxmox Backup Server settings
PBS_HOST="pbs-ch-01.onesystems.ch"
PBS_PORT="8007"
PBS_USERNAME="pbs-user@pbs!api"
PBS_PASSWORD="your-api-password"
PBS_DATASTORE="DS01"
PBS_NAMESPACE="Clients/Servers"
PBS_FINGERPRINT="your-pbs-fingerprint"
# Backup repository (auto-generated from above variables)
PBS_REPOSITORY="${PBS_USERNAME}@${PBS_HOST}:${PBS_PORT}:${PBS_DATASTORE}"
# Directories to back up
PBS_BACKUP_DIRS=(
"/etc"
"/home"
"/opt"
"/srv"
)
# Enable auto-update (true/false)
ONLINE_UPDATE=true
Manual Run
To run the backup manually:
/opt/pbs-backup/backup.sh
Cron Job
The script creates a symlink in /etc/cron.daily/:
/etc/cron.daily/pbs-backup
This runs automatically once a day.
How It Works
- Loads configuration from
.env - Checks for updates if
ONLINE_UPDATE=true - Validates all required environment variables
- Backs up each directory in
PBS_BACKUP_DIRSas individualpxararchives - Stores logs in
/opt/pbs-backup/logs/ - Deletes logs older than 7 days (configurable via
LOG_RETENTION_DAYS)
Log Files
Logs are stored at:
/opt/pbs-backup/logs/
File naming format:
backup-YYYYMMDD-HHMMSS.log
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Backup successful |
| 1 | Backup failed |
| 2 | Configuration error |
These exit codes are suitable for integration with monitoring systems.
Uninstall
To completely remove the script and cron job:
rm -f /etc/cron.daily/pbs-backup
rm -rf /opt/pbs-backup/
Requirements
- Proxmox Backup Client (v2.4+)
- Bash 4+
- curl
License
MIT License – free for commercial and private use.