Caring for and protecting NetBSD data: keeping filesystems healthy with fsck, creating FFS snapshots, and building a backup strategy with dump, restore, tar, cpio, and rsync.

In episode 10 we built the entire NetBSD from source — an impressive achievement, but meaningless if the data inside it is lost. In this episode we'll protect the most valuable asset: data management and backup — caring for filesystems with fsck, creating FFS snapshots for consistent backups, and building a backup strategy with dump/restore, tar, cpio, and rsync.
fsck is the main tool for keeping a filesystem consistent. Regular checks on inactive filesystems are highly recommended — for example the /var partition when the system is booted from other media, or when checking a data disk:
fsck -f /dev/rwd0e** /dev/rwd0e
** Last Mounted on /usr
** Phase 1 - Check Blocks and Sizes
...
** Phase 6 - Salvage Cylinder Groups
** 512 files, 1024 used, 419328 freeA "clean" output means the filesystem is consistent. If there are errors, fsck asks whether to repair them.
An FFS snapshot gives a consistent picture of the filesystem at a single point in time — without stopping services. Here's how to create one:
fsck -t /dev/rwd0eSnapshot of /dev/rwd0e created at /var/snapshot/rwd0e.0The snapshot can be mounted read-only and then backed up, while the original filesystem keeps serving users. This is the standard technique for consistent "live" backups.
dump and restore are the classic BSD backup pair that use the filesystem interface directly — well suited for backing up an entire filesystem. The basic flow:
dump -0au -f /backup/wd0e.dump /dev/rwd0e DUMP: Date of this level 0 dump: Mon Aug 3 12:00:00 2026
DUMP: Dumping /dev/rwd0e to /backup/wd0e.dump
DUMP: Writing 10 Kilobyte records
DUMP: finished in 42 secondsOption explanation: -0 level 0 (full dump), -a auto-size (automatic record size), -u updates the /etc/dumpdates record, -f destination. Levels 1-9 are incremental — level 1 only backs up changes since level 0.
Restoring a dump's contents:
restore -rf /backup/wd0e.dump Verify tape and initialize maps
Request next file-r for a full restore, -f to read from a file. To view the contents without restoring:
restore -tf /backup/wd0e.dumpFor backing up specific directories (not entire filesystems), tar is more practical:
tar -czf /backup/etc.tar.gz /etctar -tzf /backup/etc.tar.gz | headExtracting on another machine:
tar -xzf /backup/etc.tar.gz -C /mnt/restorecpio is a powerful alternative for pipeline workflows — for example, backing up a file list from find:
find /var/log -type f | cpio -o -H newc | gzip > /backup/logs.cpio.gzgzip -dc /backup/logs.cpio.gz | cpio -t | head| Tool | Level | Strengths | When to Use |
|---|---|---|---|
dump/restore | Filesystem | Consistent, incremental, easy restore | Backing up entire partitions |
tar | File | Simple, portable | Specific directories/contents |
cpio | File | Pipeline-friendly | Flexibly architected backups |
rsync | File | Incremental sync, remote | Mirroring between machines |
rsync is the king of synchronization — it compares and copies only what changed. Install from pkgsrc:
cd /usr/pkgsrc/net/rsync
make install cleanLocal synchronization (mirroring one directory to another):
rsync -av --delete /etc/ /backup/etc-mirror/sending incremental file list
passwd
rc.conf
rsyncd.conf
...Remote synchronization to a backup server:
rsync -avz --delete /var/www/ backup@server:/backups/www/Key options: -a archive (recursive + attributes), -v verbose, -z compression, --delete removes files that are gone from the source. --delete is very useful for precise mirrors — but make sure the direction is right!
Warning
Test rsync with the --dry-run option first to see what would be copied without actually copying. A single wrong-direction --delete can wipe the target data.
| Component | Meaning |
|---|---|
| 3 copies of data | 1 production + 2 backups |
| 2 different media | E.g. local disk + external/remote disk |
| 1 off-site | A copy in a different location from the production machine |
# Level 0 (full) backup every Sunday at 02:00
0 2 * * 0 root dump -0au -f /backup/full.dump /dev/rwd0e
# Level 5 (incremental) backup every day at 02:00
0 2 * * 1-6 root dump -5au -f /backup/inc.dump /dev/rwd0eRegister the schedule in the root crontab with crontab -e. Combining full + incremental gives a balance between speed and recovery coverage.
A backup that is never restored is a guess, not a backup. Schedule periodic restore tests — for example in a VM — to make sure the recovery process actually works when you need it.
In this episode 11, you've protected NetBSD data: caring for filesystems with fsck, creating FFS snapshots for consistent backups, and building a backup strategy with dump/restore, tar, cpio, and rsync — plus an automated schedule via crontab.
Key takeaways:
fsck; snapshots with fsck -t for consistent backups on a live system.dump/restore for filesystem-level backups; tar/cpio for file-level.rsync for incremental synchronization — test with --dry-run first.In the next episode, episode 12, we'll build the defensive wall: firewalls with npf and ipfilter — writing the npf.conf ruleset, enabling NAT, managing with npfctl, and comparing npf with ipfilter and pf. See you in episode 12!