Skip to main content

Snapshot Style Backup Folder

A snapshot layout makes backups easier to browse, verify, and restore. Instead of overwriting latest.zip forever, you keep timestamped snapshots and optionally maintain a latest pointer.

Quick Summary
  • Use timestamped directories or files.
  • Keep a latest symlink for automation.
  • Write a small manifest per snapshot (sizes, checksums, metadata).
  • Design the layout to support restore drills.

A simple folder layout

One practical layout:

snapshot-folder-layout.txt
/backups/
snapshots/
2026-03-01/
wp-files.tar.zst
wp-db.sql.zst
manifest.txt
2026-03-02/
...
latest -> /backups/snapshots/2026-03-02/

Create a new snapshot directory

create-snapshot-directory.sh
set -euo pipefail

STAMP="$(date +%F)"
SNAP_DIR="/backups/snapshots/$STAMP"

sudo mkdir -p "$SNAP_DIR"
sudo rm -f /backups/latest
sudo ln -s "$SNAP_DIR" /backups/latest

echo "snapshot dir: $SNAP_DIR"
ls -la /backups/latest

If you want snapshot directories without storing full copies each time, use --link-dest.

rsync-snapshot-with-link-dest.sh
set -euo pipefail

TODAY="$(date +%F)"
BASE="/backups/snapshots"

DEST="$BASE/$TODAY/files"
PREV="$BASE/latest/files"

sudo mkdir -p "$DEST"

sudo rsync -a \
--delete \
--link-dest="$PREV" \
--exclude 'wp-content/cache/' \
--exclude 'wp-content/*/cache/' \
/var/www/html/ \
"$DEST/"

Notes:

  • Unchanged files are hard-linked to the previous snapshot (saves space).
  • Changed files are stored as new copies.

Write a manifest

write-snapshot-manifest.sh
SNAP_DIR="/backups/latest"

{
echo "created_at=$(date -Is)"
echo "hostname=$(hostname)"
echo "files_archive=$(ls -1 "$SNAP_DIR" | rg -n 'wp-files')"
echo "db_dump=$(ls -1 "$SNAP_DIR" | rg -n 'wp-db')"
echo "sizes:";
ls -lh "$SNAP_DIR" | sed -n '1,60p'
} | sudo tee "$SNAP_DIR/manifest.txt" >/dev/null

Restore drills

Your folder layout should support staging restores.

restore-drill-from-snapshot.sh
set -e

SNAP_DIR="/backups/latest"
sudo rm -rf /tmp/restore-test
sudo mkdir -p /tmp/restore-test

sudo tar --use-compress-program=zstd -xf "$SNAP_DIR/wp-files.tar.zst" -C /tmp/restore-test
sudo find /tmp/restore-test -maxdepth 3 -type f -name wp-config.php -print

Next steps

  • Retention and pruning: opt/docker-data/apps/docusaurus/site/docs/server/linux-server/10-backup-disaster-recovery/rotation--retention-policies.mdx.
  • Verification and logging: opt/docker-data/apps/docusaurus/site/docs/server/linux-server/10-backup-disaster-recovery/backup-logging-and-verification.mdx.