fix: Dynamic snapshot sizing to prevent I/O errors

Problem: Fixed 500MB snapshot size was too small for large/active LVs,
causing I/O errors when snapshot space was exhausted during backup.

Solution: Calculate appropriate snapshot size based on LV size:
- Use 10% of LV size for snapshot space
- Minimum 1GB to handle reasonable activity
- Shows snapshot size in logs for transparency

Example:
- 20GB LV → 2GB snapshot
- 100GB LV → 10GB snapshot
- 500MB LV → 1GB snapshot (minimum)

This prevents snapshot overflow and resulting I/O errors during backup.

Changes:
- GUI: Calculate snapshot size before creating
- CLI: Same dynamic sizing logic
- Both show calculated snapshot size in output
- Handles both single LV and VG backup modes
This commit is contained in:
root
2025-10-09 01:06:12 +02:00
parent c86fee78cb
commit f12d07be7f
2 changed files with 50 additions and 7 deletions

View File

@@ -298,10 +298,21 @@ case "$MODE" in
SNAPSHOT_NAME="${LV_NAME}_borg_snap"
SNAPSHOT_PATH="/dev/$VG_NAME/$SNAPSHOT_NAME"
# Get LV size to determine appropriate snapshot size
LV_SIZE_BYTES=$(lvs --noheadings -o lv_size --units b "$SOURCE" | tr -d ' ' | sed 's/B$//')
# Use 10% of LV size or minimum 1GB for snapshot
SNAPSHOT_SIZE_BYTES=$((LV_SIZE_BYTES / 10))
if [ $SNAPSHOT_SIZE_BYTES -lt 1073741824 ]; then
SNAPSHOT_SIZE_BYTES=1073741824 # 1GB minimum
fi
SNAPSHOT_SIZE_GB=$((SNAPSHOT_SIZE_BYTES / 1073741824))
SNAPSHOT_SIZE="${SNAPSHOT_SIZE_GB}G"
info "This will backup LV to Borg repository"
echo ""
echo -e "${YELLOW}Source LV: $SOURCE${NC}"
echo -e "${YELLOW}Repository: $TARGET${NC}"
echo -e "${BLUE}Snapshot size: $SNAPSHOT_SIZE${NC}"
if [ "$NEW_REPO" = true ]; then
echo -e "${BLUE}Will create new repository${NC}"
else
@@ -328,7 +339,7 @@ case "$MODE" in
fi
log "Creating snapshot of source LV"
lvcreate -L1G -s -n "$SNAPSHOT_NAME" "$SOURCE" || error "Failed to create snapshot"
lvcreate -L"$SNAPSHOT_SIZE" -s -n "$SNAPSHOT_NAME" "$SOURCE" || error "Failed to create snapshot"
# Create Borg archive
ARCHIVE_NAME="lv_${LV_NAME}_$(date +%Y%m%d_%H%M%S)"
@@ -398,9 +409,19 @@ case "$MODE" in
SNAPSHOT_PATH="/dev/$SOURCE/$SNAPSHOT_NAME"
LV_PATH="/dev/$SOURCE/$LV_NAME"
# Get LV size to determine appropriate snapshot size
LV_SIZE_BYTES=$(lvs --noheadings -o lv_size --units b "$LV_PATH" | tr -d ' ' | sed 's/B$//')
# Use 10% of LV size or minimum 1GB for snapshot
SNAPSHOT_SIZE_BYTES=$((LV_SIZE_BYTES / 10))
if [ $SNAPSHOT_SIZE_BYTES -lt 1073741824 ]; then
SNAPSHOT_SIZE_BYTES=1073741824 # 1GB minimum
fi
SNAPSHOT_SIZE_GB=$((SNAPSHOT_SIZE_BYTES / 1073741824))
SNAPSHOT_SIZE="${SNAPSHOT_SIZE_GB}G"
log "Processing LV: $LV_NAME"
log "Creating snapshot: $SNAPSHOT_NAME"
lvcreate -L500M -s -n "$SNAPSHOT_NAME" "$LV_PATH" || {
log "Creating snapshot: $SNAPSHOT_NAME (size: $SNAPSHOT_SIZE)"
lvcreate -L"$SNAPSHOT_SIZE" -s -n "$SNAPSHOT_NAME" "$LV_PATH" || {
warn "Failed to create snapshot for $LV_NAME"
continue
}