Skip to content
Edit this page

SSD and SD card wear

HomeVault is often deployed on a Raspberry Pi with an SD card or a USB-attached SSD. Both have a finite write budget, so HomeVault is built to stay off the disk. This page explains what the app does for you and what you can tune on the host.

What HomeVault does

Backups are split, and only rewritten when they change

File Contents Size Written when
homevault-data-<timestamp>.zip homevault.db + data.json kilobytes the database changed
homevault-images-<timestamp>.zip the image tree potentially GB an image was added, removed or modified

Photos change far less often than inventory data, so the large archive is usually skipped. In On change mode, a scheduled run with no changes writes no backup at all. Retention applies to each kind separately, so small data backups never push out the image backup they depend on. See Backups & restore.

Change detection only reads: a hash over the database table contents, and a hash over each image's path, size and modification time.

SQLite runs in WAL mode

Write-ahead logging needs far fewer writes per change than a rollback journal. Temporary tables are kept in RAM, with an 8 MB page cache and a 64 MB memory-mapped window.

To confirm on a running install:

xxd -s 18 -l 2 -p data/db/homevault.db     # expect: 0202

Logs are bounded

The app logs to standard output. Successful requests are logged only at debug, so run with LOG_LEVEL=warn, and cap Docker's log size as shown in Installation.


Tune the host

The OS underneath contributes more writes than the application does. Run:

./scripts/pi-ssd-optimize.sh          # dry run — shows what it would change
sudo ./scripts/pi-ssd-optimize.sh --apply

It covers three things:

journald writes system logs to /var/log/journal forever. Storage=volatile moves them to a tmpfs, bounded at 32 MB of RAM so this does not trade disk wear for memory pressure. Logs are lost across reboots — that is the trade.

Swap. dphys-swapfile puts swap on the SSD, and swapping there is heavy sustained write traffic exactly when the machine is already under pressure. The script disables it and installs zram, which provides the same safety margin as compressed RAM (typically 2–3× compression) with no disk writes at all.

noatime. relatime, the default, still writes an access timestamp once a day per file read. noatime eliminates that class of write entirely. The script does not edit /etc/fstab automatically — a malformed entry can make the Pi unbootable — it prints the line to add:

defaults,noatime,commit=60

commit=60 is ext4-specific and batches journal flushes, trading up to 60 seconds of writes on power loss for far fewer journal commits. This is consistent with the database's synchronous=NORMAL.

Verify without rebooting:

sudo mount -o remount /            # or your data mount
findmnt -no OPTIONS /

Measuring the result

# Total bytes written per device, since boot
awk '{printf "%-12s %10.1f MB\n", $3, $10*512/1024/1024}' /proc/diskstats

# NVMe wear indicators
sudo smartctl -A /dev/nvme0 | grep -iE 'Percentage Used|Data Units Written'

Percentage Used is the drive's own estimate of consumed write endurance. Data Units Written is in 512 KB units. Record both, then compare after a week.