Files
duplicati/Duplicati/Library/Snapshots/apfs-scripts/remove-apfs-snapshot.sh
T
Kenneth Skovhede 44bef1e855 Implement support for filesystem snapshots on macOS using APFS (Apple File System). This allows disks-consistent backups and backing up files that are locked by other processes by creating and mounting local snapshots using tmutil.
Key changes:
- Add `MacOSSnapshot` class implementing `SnapshotBase`
- Add helper scripts for creating, finding, and removing APFS snapshots
- Update `SnapshotUtility` to initialize macOS snapshots
- Enable `snapshot-policy` option for macOS in `Options.cs`
- Update build configuration to include APFS scripts
- Update snapshot test utility with macOS support

This fixes #6409
2026-02-04 15:02:31 +01:00

39 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# Input:
# $1 = snapshot name (not used with tmutil, but kept for compatibility)
# $2 = device
# $3 = mount point
NAME=$1
DEVICE=$2
MOUNTPOINT=$3
# Unmount
umount "$MOUNTPOINT"
if [ "$?" -ne 0 ]; then
# Try force unmount
umount -f "$MOUNTPOINT"
fi
# Remove mount point
rmdir "$MOUNTPOINT"
# Delete all local snapshots for the device (tmutil doesn't support deleting specific snapshots easily)
# Get the mount point for the device
MOUNT_POINT=$(mount | grep "^$DEVICE " | sed -E 's/^.* on (.*) \(.*$/\1/')
if [ -n "$MOUNT_POINT" ]; then
# Check if NAME looks like an APFS snapshot (com.apple.TimeMachine...)
if [[ "$NAME" == com.apple.TimeMachine.* ]]; then
# Extract date and delete specific snapshot
SNAPSHOT_DATE=$(echo "$NAME" | sed -E 's/^com\.apple\.TimeMachine\.//; s/\.local$//')
tmutil deletelocalsnapshots "$SNAPSHOT_DATE"
else
# Fallback: Delete all local snapshots for this volume
tmutil deletelocalsnapshots "$MOUNT_POINT"
fi
fi
exit 0