fix(vaultwarden): make backup script filesystem-agnostic for NTFS/exFAT
- Replace symbolic link handling with a latest.txt file pointer - Trade hard-link deduplication for universal drive compatibility - Guarantee complete standalone backups across all target filesystems
This commit is contained in:
1 parent
d4d709347c
commit
f62d60802f
1 file changed
+13
-11
+13
-11
@@ -3,8 +3,9 @@
|
|||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Script: vaultwarden_backup.sh
|
# Script: vaultwarden_backup.sh
|
||||||
# Description: Backs up Vaultwarden to timestamped directories on a mounted
|
# Description: Backs up Vaultwarden to timestamped directories on a mounted
|
||||||
# drive using Docker exec and rsync. Utilizes hard links for
|
# drive using Docker exec and rsync. Compatible with non-POSIX
|
||||||
# deduplication and automatically prunes backups older than RETENTION_DAYS.
|
# filesystems (exFAT, NTFS, FAT32) and automatically prunes
|
||||||
|
# backups older than RETENTION_DAYS.
|
||||||
# Usage: sudo ./vaultwarden_backup.sh
|
# Usage: sudo ./vaultwarden_backup.sh
|
||||||
# Notes: Must be run with root/sudo privileges.
|
# Notes: Must be run with root/sudo privileges.
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
@@ -22,7 +23,7 @@ RETENTION_DAYS=30
|
|||||||
# Timestamp and Folder Setup
|
# Timestamp and Folder Setup
|
||||||
TIMESTAMP=$(date +"%Y-%m-%d_%H%M%S")
|
TIMESTAMP=$(date +"%Y-%m-%d_%H%M%S")
|
||||||
CURRENT_BACKUP_DIR="$VAULTWARDEN_DESTINATION/backup_$TIMESTAMP"
|
CURRENT_BACKUP_DIR="$VAULTWARDEN_DESTINATION/backup_$TIMESTAMP"
|
||||||
LATEST_LINK="$VAULTWARDEN_DESTINATION/latest"
|
LATEST_TXT_FILE="$VAULTWARDEN_DESTINATION/latest.txt"
|
||||||
|
|
||||||
# ntfy Notification Configuration
|
# ntfy Notification Configuration
|
||||||
NTFY_TOPIC="Server"
|
NTFY_TOPIC="Server"
|
||||||
@@ -54,7 +55,7 @@ if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create target directories if they don't exist
|
# Create target directory for current run
|
||||||
mkdir -p "$CURRENT_BACKUP_DIR"
|
mkdir -p "$CURRENT_BACKUP_DIR"
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
@@ -97,13 +98,15 @@ if [ $RSYNC_DB_STATUS -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 3: Rsync remaining data (using --link-dest for storage efficiency if 'latest' exists)
|
# Step 3: Find previous backup directory for --link-dest (if filesystem supports it)
|
||||||
echo "Rsyncing attachments, RSA keys, and configuration files..."
|
PREVIOUS_BACKUP_DIR=$(ls -td "$VAULTWARDEN_DESTINATION"/backup_* 2>/dev/null | grep -v "$CURRENT_BACKUP_DIR" | head -n 1)
|
||||||
|
|
||||||
LINK_DEST_PARAM=""
|
LINK_DEST_PARAM=""
|
||||||
if [ -d "$LATEST_LINK" ]; then
|
if [ -n "$PREVIOUS_BACKUP_DIR" ] && [ -d "$PREVIOUS_BACKUP_DIR" ]; then
|
||||||
LINK_DEST_PARAM="--link-dest=$LATEST_LINK"
|
LINK_DEST_PARAM="--link-dest=$PREVIOUS_BACKUP_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Rsyncing attachments, RSA keys, and configuration files..."
|
||||||
rsync -av --no-owner --no-group $LINK_DEST_PARAM --exclude='db.sqlite3*' "$VAULTWARDEN_DATA_DIR/" "$CURRENT_BACKUP_DIR/"
|
rsync -av --no-owner --no-group $LINK_DEST_PARAM --exclude='db.sqlite3*' "$VAULTWARDEN_DATA_DIR/" "$CURRENT_BACKUP_DIR/"
|
||||||
RSYNC_DATA_STATUS=$?
|
RSYNC_DATA_STATUS=$?
|
||||||
|
|
||||||
@@ -113,9 +116,8 @@ if [ $RSYNC_DATA_STATUS -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 4: Update 'latest' symlink to point to this new backup folder
|
# Step 4: Record current backup path to latest.txt
|
||||||
rm -f "$LATEST_LINK"
|
echo "$CURRENT_BACKUP_DIR" > "$LATEST_TXT_FILE"
|
||||||
ln -s "$CURRENT_BACKUP_DIR" "$LATEST_LINK"
|
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Retention Cleanup (Prune Backups Older than RETENTION_DAYS)
|
# Retention Cleanup (Prune Backups Older than RETENTION_DAYS)
|
||||||
|
|||||||
Reference in new issue
Block a user