Add backup shrinking functionality to eMMC provisioning dashboard: implement API for shrinking raw .img backups using PiShrink, update UI to support shrink option after backup, and enhance documentation for backup image handling and storage options on Proxmox host.
This commit is contained in:
@@ -13,8 +13,8 @@ ExecStart=/opt/cm4-provisioning/flash-emmc-on-connect.sh
|
||||
User=root
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
# Allow long run (rpiboot + device scan + wait for user choice)
|
||||
TimeoutStartSec=900
|
||||
# Allow long run: rpiboot + wait for choice + dd 32GB (~20–35 min) + optional PiShrink (~15–30 min)
|
||||
TimeoutStartSec=7200
|
||||
|
||||
[Install]
|
||||
# Only started by udev trigger, not at boot
|
||||
|
||||
@@ -57,6 +57,10 @@ fi
|
||||
# When a device is detected we ask the user (dashboard): Backup or Deploy?
|
||||
# These files are used to wait for the user's choice (written by dashboard, read by this script).
|
||||
BACKUPS_DIR="${BACKUPS_DIR:-/var/lib/cm4-provisioning/backups}"
|
||||
# Optional: shrink backup with PiShrink (requires pishrink + parted, e2fsprogs). SHRINK_BACKUP=1 to enable.
|
||||
SHRINK_BACKUP="${SHRINK_BACKUP:-0}"
|
||||
# If SHRINK_BACKUP=1, optionally compress: PISHRINK_COMPRESS=gz or xz (uses parallel when available). Uncompressed .img can be dd'd directly for deploy.
|
||||
PISHRINK_COMPRESS="${PISHRINK_COMPRESS:-}"
|
||||
ACTION_REQUEST_FILE="${ACTION_REQUEST_FILE:-/var/lib/cm4-provisioning/action_request}"
|
||||
CURRENT_DEVICE_FILE="${CURRENT_DEVICE_FILE:-/var/lib/cm4-provisioning/current_device}"
|
||||
DEVICE_SOURCE_FILE="${DEVICE_SOURCE_FILE:-/var/lib/cm4-provisioning/device_source}"
|
||||
@@ -163,8 +167,44 @@ for (( i = 0; i < WAIT_TIMEOUT; i += 2 )); do
|
||||
write_status "backup" "Creating backup…" "null"
|
||||
log "Backing up $target_dev to $backup_path..."
|
||||
if dd if="$target_dev" of="$backup_path" bs=4M status=progress conv=fsync; then
|
||||
log "Backup complete: $backup_path"
|
||||
write_status "done" "Backup complete: $backup_name" "100"
|
||||
final_name="$backup_name"
|
||||
shrink_requested=false
|
||||
[[ "$SHRINK_BACKUP" == "1" || "$SHRINK_BACKUP" == "true" ]] && shrink_requested=true
|
||||
[[ -f "$(dirname "$STATUS_FILE")/shrink_next_backup" ]] && shrink_requested=true
|
||||
rm -f "$(dirname "$STATUS_FILE")/shrink_next_backup" 2>/dev/null || true
|
||||
if [[ "$shrink_requested" == "true" ]]; then
|
||||
pishrink_cmd=""
|
||||
for p in /usr/local/bin/pishrink.sh /usr/local/bin/pishrink; do
|
||||
[[ -x "$p" ]] && pishrink_cmd="$p" && break
|
||||
done
|
||||
if [[ -n "$pishrink_cmd" ]]; then
|
||||
write_status "backup" "Shrinking backup image…" "null"
|
||||
log "Shrinking backup with PiShrink (timeout 30 min)..."
|
||||
pishrink_opts="-n"
|
||||
[[ "$PISHRINK_COMPRESS" == "gz" || "$PISHRINK_COMPRESS" == "gzip" ]] && pishrink_opts="$pishrink_opts -z -a"
|
||||
[[ "$PISHRINK_COMPRESS" == "xz" ]] && pishrink_opts="$pishrink_opts -Z -a"
|
||||
PISHRINK_TIMEOUT="${PISHRINK_TIMEOUT:-1800}"
|
||||
if timeout "$PISHRINK_TIMEOUT" $pishrink_cmd $pishrink_opts "$backup_path" 2>&1; then
|
||||
if [[ "$PISHRINK_COMPRESS" == "gz" || "$PISHRINK_COMPRESS" == "gzip" ]]; then
|
||||
final_name="${backup_name}.gz"
|
||||
elif [[ "$PISHRINK_COMPRESS" == "xz" ]]; then
|
||||
final_name="${backup_name}.xz"
|
||||
fi
|
||||
log "Shrunk backup: $BACKUPS_DIR/$final_name"
|
||||
else
|
||||
rc=$?
|
||||
if [[ "$rc" -eq 124 ]]; then
|
||||
log "PiShrink timed out after ${PISHRINK_TIMEOUT}s; keeping full backup $backup_path"
|
||||
else
|
||||
log "PiShrink failed (exit $rc); keeping full backup $backup_path"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log "SHRINK_BACKUP=1 but pishrink not found; keeping full backup. Install with scripts/install-pishrink-on-host.sh"
|
||||
fi
|
||||
fi
|
||||
log "Backup complete: $BACKUPS_DIR/$final_name"
|
||||
write_status "done" "Backup complete: $final_name" "100"
|
||||
else
|
||||
write_status "error" "Backup failed" "null" "dd failed"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user