Skip to content

Commit 585a7e3

Browse files
committed
apply same duplication safegurads during backup creation
1 parent 230f285 commit 585a7e3

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
nuts (2.2.6) nitrux; urgency=medium
2+
3+
* Ensure backup always follows the active root and indicate potentially confusing environments.
4+
5+
-- Uri Herrera <[email protected]> Sub, 29 Dec 2025 11:37:00 -0500
6+
17
nuts (2.2.5) nitrux; urgency=medium
28

39
* Deprecate the restore command and removed related code.

usr/bin/nuts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,28 +259,50 @@ done
259259
# -- This backup is created outside of the chroot because xfsdump relies on /etc/mtab, and that file is unavailable when using overlayroot-chroot.
260260
# -- Since the XFS backup is a "full-backup" (level 0), it won't support incremental updates.
261261

262-
ROOT_PARTITION=$(findfs LABEL=NX_ROOT)
263-
ROOT_PARTITION_LABEL=$(blkid -o value -s LABEL "$ROOT_PARTITION")
264-
ROOT_PARTITION_FS=$(blkid -o value -s TYPE "$ROOT_PARTITION")
265-
XFS_BACKUP_FILE="$NUTS_DIR_XFS/xfs-backup.xfs"
266-
COMPRESSED_XFS_BACKUP="$XFS_BACKUP_FILE.zst"
267-
ZSTD_COMP_THREADS=$(nproc)
262+
ROOT_PARTITION=$(findmnt -n -o SOURCE /media/root-ro 2>/dev/null || true)
263+
264+
if [ -z "$ROOT_PARTITION" ]; then
265+
ROOT_PARTITION=$(findmnt -n -o SOURCE / 2>/dev/null || true)
266+
fi
267+
268+
if [ -z "$ROOT_PARTITION" ]; then
269+
puts_error "Could not resolve the root device from mount points. Quitting."
270+
exit 1
271+
fi
272+
273+
ROOT_PARTITION_LABEL=$(blkid -o value -s LABEL "$ROOT_PARTITION" 2>/dev/null || true)
274+
ROOT_PARTITION_FS=$(blkid -o value -s TYPE "$ROOT_PARTITION" 2>/dev/null || true)
275+
276+
if [ -z "$ROOT_PARTITION_LABEL" ]; then
277+
puts_error "Resolved root device $ROOT_PARTITION has no label, quitting."
278+
exit 1
279+
fi
268280

269281
if [[ "$ROOT_PARTITION_FS" != "xfs" ]]; then
270-
puts_error "The filesystem of $ROOT_PARTITION_LABEL is not XFS, quitting."
282+
puts_error "The filesystem of $ROOT_PARTITION_LABEL ($ROOT_PARTITION) is not XFS, quitting."
271283
exit 1
272284
fi
273285

286+
LABEL_COUNT=$(blkid -o device -t LABEL="$ROOT_PARTITION_LABEL" 2>/dev/null | wc -l)
287+
288+
if [ "$LABEL_COUNT" -gt 1 ]; then
289+
puts_warning "Detected $LABEL_COUNT devices with label $ROOT_PARTITION_LABEL; backing up active root device $ROOT_PARTITION."
290+
fi
291+
292+
XFS_BACKUP_FILE="$NUTS_DIR_XFS/xfs-backup.xfs"
293+
COMPRESSED_XFS_BACKUP="$XFS_BACKUP_FILE.zst"
294+
ZSTD_COMP_THREADS=$(nproc)
295+
274296
if [[ -f "$COMPRESSED_XFS_BACKUP" ]]; then
275297
puts_info "Backup of $ROOT_PARTITION_LABEL found, skipping..."
276298
else
277299
puts_warning "Backup of $ROOT_PARTITION_LABEL not found, creating it..."
278-
300+
279301
xfsdump -l0 -L "Nitrux_Update_Tool_System-XFS_Backup" -M "NX_BAK-Vol-1" -f "$XFS_BACKUP_FILE" "$ROOT_PARTITION" > /dev/null 2>&1 &
280302
spinner "$!"
281-
303+
282304
puts_info "Using $ZSTD_COMP_THREADS threads for backup compression, please wait..."
283-
305+
284306
zstd -T"$ZSTD_COMP_THREADS" -3 "$XFS_BACKUP_FILE" -o "$COMPRESSED_XFS_BACKUP"
285307

286308
rm -f "$XFS_BACKUP_FILE"

0 commit comments

Comments
 (0)