Files
borg_mount/README.md
2025-10-07 10:41:37 +02:00

4.1 KiB

Borg Vault & QCOW2 Mount Scripts

Interactive shell scripts for mounting Borg backup vaults and QCOW2 disk images with LVM support.

Overview

This repository contains scripts to easily mount and unmount Borg backup archives and the QCOW2 virtual disk images contained within them. The mount script provides an interactive menu to select from available backup snapshots.

Files

  • mount_backup.sh - Interactive script to mount Borg vault and QCOW2 disk image
  • umount_backup.sh - Script to safely unmount all mounted filesystems

Features

  • 🔍 Auto-discovery: Automatically scans for available backups in the Borg vault
  • 📅 German date formatting: Displays backup dates in German format (e.g., "6. Oktober 2025 - 02:00 Uhr")
  • 🎯 Interactive selection: Choose which backup snapshot to mount
  • 🔒 Read-only mounting: All filesystems are mounted read-only for safety
  • 🔄 LVM support: Handles LVM logical volumes within QCOW2 images
  • 🧹 Clean unmount: Proper cleanup of NBD devices, LVM, and FUSE mounts

Requirements

  • BorgBackup (borgbackup package)
  • QEMU tools (qemu-utils package for qemu-nbd)
  • LVM2 tools (lvm2 package)
  • NBD kernel module
  • Root/sudo access

Usage

Mounting

Run the mount script and follow the interactive prompts:

./mount_backup.sh

The script will:

  1. Mount the Borg vault to /mnt/restore
  2. Display available backup snapshots with dates
  3. Prompt you to select a backup (press Enter for latest)
  4. Automatically find and mount the QCOW2 disk image to /mnt/qcow2

Unmounting

When finished, unmount everything properly:

./umount_backup.sh

This will safely unmount all filesystems and disconnect devices in the correct order.

Configuration

The following paths are configured in mount_backup.sh:

  • Borg Repository: /data_storage/Backup/borg/srvfs01
  • Borg Mount Point: /mnt/restore
  • QCOW2 Mount Point: /mnt/qcow2
  • QCOW2 Filename: vm-105-disk-3.qcow2

Edit these variables at the top of the script if your setup differs.

Technical Details

Mount Process

  1. Borg vault is mounted via FUSE at /mnt/restore
  2. NBD (Network Block Device) module is loaded
  3. QCOW2 image is connected to /dev/nbd0 in read-only mode
  4. LVM physical volumes are scanned
  5. LVM volume group vgdata is activated
  6. Logical volume lvshare is mounted to /mnt/qcow2 with noload option (skips journal recovery)

Unmount Process

  1. Unmount /mnt/qcow2 filesystem
  2. Deactivate LVM volume group vgdata
  3. Disconnect NBD device /dev/nbd0
  4. Unmount Borg vault from /mnt/restore

Example Output

=== Mounting Borg Backup Vault ===
✓ Borg vault mounted to /mnt/restore

=== Scanning for available backups ===
Available backups:

 1) 7. Oktober 2025 - 02:00 Uhr
 2) 6. Oktober 2025 - 02:00 Uhr
 3) 5. Oktober 2025 - 02:00 Uhr
 4) 4. Oktober 2025 - 02:00 Uhr
 ...

Select backup number (1-13) or [Enter] for latest: 2

✓ Selected backup: 6. Oktober 2025 - 02:00 Uhr

=== Searching for QCOW2 file ===
✓ Found: /mnt/restore/vm105-20251006-020001/mnt/my_storage_box/images/105/vm-105-disk-3.qcow2

=== Mounting QCOW2 Disk Image ===
✓ NBD module loaded
✓ QCOW2 connected to /dev/nbd0
✓ LVM volumes scanned
✓ Filesystem mounted to /mnt/qcow2

=== Mount Summary ===
Borg vault:    /mnt/restore
Selected:      6. Oktober 2025 - 02:00 Uhr
QCOW2 disk:    /mnt/qcow2

Done! To unmount, run: /data_storage/Backup/borg/umount_backup.sh

Troubleshooting

"Read-only file system" error

This is expected - the Borg vault is mounted read-only. The scripts handle this by using --read-only flag with qemu-nbd and ro,noload mount options.

"Journal recovery failed" error

The noload mount option skips journal recovery, which is necessary for read-only mounting of ext4 filesystems with dirty journals.

NBD device busy

If unmounting fails, manually disconnect: qemu-nbd --disconnect /dev/nbd0

LVM conflicts

If volume group names conflict with existing systems, the script may need modification to handle renamed volume groups.

License

Created: 2025-10-07

Author

System Administrator - Egonetix