RazBack is a simple Btrfs-based backup system using snapshots. A Btrfs subvolume is shared over the network via Samba, and a script periodically creates new snapshots while keeping a structured retention schedule. Older snapshots are removed at increasing intervals to balance storage efficiency and recovery options.
The Samba share utilizes the vfs_shadow_copy2 module, allowing Windows clients to access previous versions of files directly from the file or folder properties.
The Samba share (e.g., NameOfTheShare) is located on a Btrfs-formatted volume mounted at /path. Snapshots are stored in a dedicated subdirectory: /path/.snapshots. The primary script, razback-snap.sh, periodically creates snapshots, while razback-remove-all.sh (optional) can be used to manually remove all snapshots if needed. Both scripts must be executable and run with sufficient Btrfs privileges (typically as root).
The mountpoint must be on a Btrfs filesystem. The scripts require the btrfs command from btrfs-progs, plus findmnt and flock from util-linux.
Install the required packages for your distribution:
# Debian / Ubuntu
sudo apt update && sudo apt install btrfs-progs util-linux
# Fedora / RHEL-compatible systems
sudo dnf install btrfs-progs util-linux
# Arch Linux
sudo pacman -S btrfs-progs util-linux
# openSUSE
sudo zypper install btrfsprogs util-linuxVerify that the required commands are available:
command -v btrfs findmnt flockTo enable previous versions in Windows, configure the share as follows in /etc/samba/smb.conf:
[NameOfTheShare]
comment = This contains stuff...
path = /path
vfs objects = shadow_copy2
shadow:snapprefix = .*
shadow:delimiter = -20
shadow:format = -%Y-%m-%d-%H-%M-%S
shadow:sort = desc
shadow:snapdir = .snapshots
read only = no
browsable = yesConfigure MOUNTPOINT in razback-snap.sh, install the executable script outside the snapshot directory (for example at /usr/local/sbin/razback-snap.sh), and execute it periodically via cron. For example, to create a snapshot every hour:
sudo crontab -e
0 * * * * /usr/local/sbin/razback-snap.shSnapshots follow the naming pattern: XXXXXX-YYYY-MM-DD-HH-MM-SS, where XXXXXX is a sequential counter, and the rest is a timestamp.
The counter has six digits. At an hourly schedule it wraps after roughly 114 years; the script intentionally retains this naming format and only discovers existing six-digit snapshots for retention.
The script implements a retention policy that maintains:
- last three hourly snapshots (all intervals depend on interval the script is being executed via cron)
- next three 2-hourly snapshots
- next three 4-hourly snapshots
- ... up to three snapshots spaced every 512 hours (~21 days)
Total number od snapshots is 30, with increassing time intervals. When using suggested 1-hour interval, maximum age of the last snapshot is around four months.
All other snapshots outside this pattern are removed automatically.
The razback-remove-all.sh script removes all snapshots. It is only meant for emergency cleanups when disk space is critically low and is not meant for regular use.
Individual snapshots can be removed by executing:
sudo btrfs subvolume delete "/path/.snapshots/XXXXXX-YYYY-MM-DD-HH-MM-SS"This system provides a simple and efficient way to manage backups using Btrfs snapshots while making them accessible to Windows clients through Samba’s Previous Versions feature.
Run the retention-policy regression tests with:
./tests/test-retention.sh