Automated ZFS Boot Environment (snapshot) creation and retention management for OPNsense firewalls with intelligent cleanup policies.
If this helped you, please give it a star! It helps others find this solution.
- Automated Boot Environment Creation: Daily and weekly snapshots visible in OPNsense Web GUI
- Intelligent Retention Policies:
- Daily snapshots kept for 30 days
- Weekly snapshots kept for 52 weeks (1 year)
- Web GUI Integration: All snapshots visible under System > Snapshots
- Automatic Cleanup: Old snapshots automatically removed based on retention policy
- Comprehensive Logging: Detailed logs for monitoring and troubleshooting
- Safety First: Never deletes active boot environments
- Cron Integration: Uses OPNsense's built-in cron system via configd
- Manual snapshot creation before every update
- No automatic cleanup - snapshots accumulate indefinitely
- Risk of running out of disk space
- Inconsistent backup strategy
- Time-consuming maintenance
- Set & Forget: Automatic daily and weekly snapshots
- Smart Cleanup: Old snapshots automatically removed
- Update Safety: Always have recent recovery points before firmware updates
- Disaster Recovery: Quick rollback capability via Web GUI or boot menu
- Space Efficient: ZFS copy-on-write technology minimizes storage usage
- Production Ready: Handles edge cases and prevents accidental deletions
- OPNsense 24.7+ with ZFS root filesystem
- SSH access or Web GUI command prompt access
- ZFS-based installation (UFS not supported)
Note: OPNsense must be installed with ZFS filesystem. You can check with:
zpool status
-
SSH into your OPNsense system or use Diagnostics > Command Prompt in the Web GUI
-
Download and run the installation script:
# Make executable and run
chmod +x zfs_snapshot_setup.sh
./zfs_snapshot_setup.sh-
Configure Cron Jobs in Web GUI:
- Navigate to System > Settings > Cron
- Click "+" to add new jobs
Daily Snapshots:
- Command:
ZFS Daily Boot Environment with 30-day retention - Schedule:
0 23 * * *(11:00 PM daily)
Weekly Snapshots:
- Command:
ZFS Weekly Boot Environment with 52-week retention - Schedule:
0 22 * * 0(10:00 PM Sundays)
-
Click Apply and you're done!
| Disk Size | Recommendation |
|---|---|
| 128GB | |
| 256GB | β Recommended (plenty of space) |
| 512GB | β Excellent (future-proof) |
Estimated Usage:
- Base OPNsense: ~4GB
- 30 daily snapshots: ~750MB
- 52 weekly snapshots: ~10GB
- Total: ~15GB (leaves plenty of room on 256GB)
- Web GUI: System > Snapshots
- Command Line:
bectl list
# Daily snapshot logs
tail -f /var/log/zfs_daily_snapshots.log
# Weekly snapshot logs
tail -f /var/log/zfs_weekly_snapshots.log# Create manual snapshot
bectl create backup-before-config-change
# List all boot environments
bectl list
# Activate a different boot environment
bectl activate daily-20240829
# Delete a boot environment (if not active)
bectl destroy old-snapshot-name- Go to System > Snapshots
- Select desired snapshot
- Click "Activate"
- Reboot system
- Boot system and wait for boot menu
- Press "8" for Boot Options
- Press "2" to cycle through snapshots
- Select desired snapshot and boot
Edit the scripts to modify retention:
Daily retention (default: 30 days):
vi /root/zfs_daily_snapshot.sh
# Change: RETENTION_DAYS=30Weekly retention (default: 52 weeks):
vi /root/zfs_weekly_snapshot.sh
# Change: RETENTION_WEEKS=52Modify the SNAPSHOT_PREFIX variables in the scripts:
SNAPSHOT_PREFIX="daily" # Creates: daily-20240829
SNAPSHOT_PREFIX="weekly" # Creates: weekly-2024W35"Command not found" in Cron
- Ensure
service configd restartwas run after installation - Check that actions file exists:
ls -la /usr/local/opnsense/service/conf/actions.d/actions_zfs_snapshot.conf
Snapshots not visible in Web GUI
- Verify you're creating Boot Environments, not ZFS snapshots
- Check:
bectl listshould show your snapshots
Permission denied
- Ensure scripts are executable:
chmod +x /root/zfs_*.sh
Out of space
- Clean up old snapshots manually:
bectl listthenbectl destroy old-name - Check space usage:
zpool list
- Check the log files first
- Open an issue with log output and system details
- Include output of:
bectl list,zpool status,uname -a
Contributions welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Pre-update snapshot triggers
- Slack/email notifications
- Web GUI configuration panel
- Snapshot size monitoring
- Multiple retention policies
This project is licensed under the MIT License - see the LICENSE file for details.
- OPNsense team for the excellent firewall platform
- FreeBSD ZFS implementation
- Community feedback and testing
Found this useful? Give it a star! β
It helps other OPNsense users discover this automation solution and motivates continued development.
Made with β€οΈ for the OPNsense community