Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
197 lines
5.2 KiB
Bash
Executable File
197 lines
5.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Load IP configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
|
|
# Setup automated backups for Proxmox containers/VMs
|
|
# Creates backup jobs and schedules them
|
|
|
|
set -u
|
|
|
|
NODE="r630-01"
|
|
NODE_IP="${PROXMOX_HOST_R630_01}"
|
|
NODE_PASS="password"
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[✗]${NC} $1"; }
|
|
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
|
|
|
|
ssh_node() {
|
|
sshpass -p "$NODE_PASS" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@"$NODE_IP" "$@" 2>&1
|
|
}
|
|
|
|
# Check if backup storage exists
|
|
check_backup_storage() {
|
|
log_info "Checking backup storage..."
|
|
|
|
if ssh_node "pvesm status | grep -q 'local.*active'"; then
|
|
log_success "Local storage available for backups"
|
|
return 0
|
|
else
|
|
log_error "No local storage available for backups"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Create backup job configuration
|
|
create_backup_job() {
|
|
local job_id="$1"
|
|
local schedule="$2"
|
|
local vmid_list="$3"
|
|
local storage="$4"
|
|
local retention="$5"
|
|
|
|
log_info "Creating backup job: $job_id"
|
|
|
|
# Create backup job using pvesh API
|
|
local job_config="{
|
|
\"enabled\": 1,
|
|
\"schedule\": \"$schedule\",
|
|
\"storage\": \"$storage\",
|
|
\"vmid\": \"$vmid_list\",
|
|
\"mode\": \"snapshot\",
|
|
\"compress\": \"gzip\",
|
|
\"prune-backups\": \"keep-all=1\",
|
|
\"retention\": \"keep-daily=$retention\"
|
|
}"
|
|
|
|
# Note: This requires Proxmox API access
|
|
# For now, we'll create a cron-based solution
|
|
log_warn "Using cron-based backup solution (API method requires additional setup)"
|
|
}
|
|
|
|
# Create cron-based backup script
|
|
create_backup_cron_script() {
|
|
log_info "Creating backup cron script..."
|
|
|
|
local script_content='#!/usr/bin/env bash
|
|
# Automated backup script for Proxmox containers
|
|
# Run daily at 2 AM
|
|
|
|
BACKUP_STORAGE="local"
|
|
BACKUP_DIR="/var/lib/vz/dump"
|
|
LOG_DIR="/var/log/proxmox-backups"
|
|
LOG_FILE="$LOG_DIR/backup_$(date +%Y%m%d).log"
|
|
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
log_info() { echo "[$(date +%Y-%m-%d\ %H:%M:%S)] [INFO] $1" | tee -a "$LOG_FILE"; }
|
|
log_error() { echo "[$(date +%Y-%m-%d\ %H:%M:%S)] [ERROR] $1" | tee -a "$LOG_FILE"; }
|
|
log_success() { echo "[$(date +%Y-%m-%d\ %H:%M:%S)] [SUCCESS] $1" | tee -a "$LOG_FILE"; }
|
|
|
|
# Get list of containers to backup
|
|
CONTAINERS=$(pct list | awk "NR>1 && \$2==\"running\" {print \$1}")
|
|
|
|
log_info "Starting backup job..."
|
|
log_info "Containers to backup: $CONTAINERS"
|
|
|
|
for vmid in $CONTAINERS; do
|
|
log_info "Backing up container $vmid..."
|
|
if vzdump $vmid --storage $BACKUP_STORAGE --compress gzip --mode snapshot --quiet; then
|
|
log_success "Container $vmid backed up successfully"
|
|
else
|
|
log_error "Failed to backup container $vmid"
|
|
fi
|
|
done
|
|
|
|
# Cleanup old backups (keep last 7 days)
|
|
log_info "Cleaning up old backups..."
|
|
find "$BACKUP_DIR" -name "vzdump-lxc-*.tar.gz" -mtime +7 -delete
|
|
find "$BACKUP_DIR" -name "vzdump-qemu-*.vma.gz" -mtime +7 -delete
|
|
|
|
log_info "Backup job completed"
|
|
'
|
|
|
|
ssh_node "cat > /usr/local/bin/proxmox-backup.sh << 'EOFSCRIPT'
|
|
$script_content
|
|
EOFSCRIPT
|
|
chmod +x /usr/local/bin/proxmox-backup.sh" || {
|
|
log_error "Failed to create backup script"
|
|
return 1
|
|
}
|
|
|
|
log_success "Backup script created"
|
|
}
|
|
|
|
# Setup cron job
|
|
setup_cron_job() {
|
|
log_info "Setting up cron job..."
|
|
|
|
# Add cron job to run daily at 2 AM
|
|
ssh_node "echo '0 2 * * * /usr/local/bin/proxmox-backup.sh' | crontab -" || {
|
|
log_error "Failed to setup cron job"
|
|
return 1
|
|
}
|
|
|
|
log_success "Cron job configured (daily at 2 AM)"
|
|
}
|
|
|
|
# Create manual backup script
|
|
create_manual_backup_script() {
|
|
log_info "Creating manual backup script..."
|
|
|
|
local script_content='#!/usr/bin/env bash
|
|
# Manual backup script for specific containers
|
|
|
|
BACKUP_STORAGE="${BACKUP_STORAGE:-local}"
|
|
VMID_LIST="$@"
|
|
|
|
if [ -z "$VMID_LIST" ]; then
|
|
echo "Usage: $0 <vmid1> [vmid2] [vmid3] ..."
|
|
echo "Example: $0 106 107 108"
|
|
exit 1
|
|
fi
|
|
|
|
for vmid in $VMID_LIST; do
|
|
echo "Backing up container $vmid..."
|
|
vzdump $vmid --storage $BACKUP_STORAGE --compress gzip --mode snapshot
|
|
done
|
|
'
|
|
|
|
ssh_node "cat > /usr/local/bin/manual-backup.sh << 'EOFSCRIPT'
|
|
$script_content
|
|
EOFSCRIPT
|
|
chmod +x /usr/local/bin/manual-backup.sh" || {
|
|
log_error "Failed to create manual backup script"
|
|
return 1
|
|
}
|
|
|
|
log_success "Manual backup script created"
|
|
}
|
|
|
|
main() {
|
|
log_info "=== Setting up Automated Backups ==="
|
|
echo ""
|
|
|
|
if ! check_backup_storage; then
|
|
log_error "Backup storage check failed"
|
|
exit 1
|
|
fi
|
|
|
|
create_backup_cron_script
|
|
setup_cron_job
|
|
create_manual_backup_script
|
|
|
|
echo ""
|
|
log_success "Backup system configured!"
|
|
log_info ""
|
|
log_info "Automated backups will run daily at 2 AM"
|
|
log_info "Manual backups: /usr/local/bin/manual-backup.sh <vmid1> [vmid2] ..."
|
|
log_info "Backup location: /var/lib/vz/dump/"
|
|
log_info "Logs: /var/log/proxmox-backups/"
|
|
}
|
|
|
|
main "$@"
|