Any way to automate updates with Snapshots?

Started by BrokenOnion, November 20, 2026, 11:37:25 PM

Previous topic - Next topic
Hi,

Are there any ways to automate creating snapshots by date as a title, activating it then doing a reboot to use the new snapshot then start any available updates, all of this done on a specific day of the week at a specific time?

I know there is Cron for scheduling and perhaps using Bash for the rest? Would this be feasible to script and implement into OPNsense? I would like to automate the update process so it's self maintained and I don't need to login into the firewall to kick off the update process.

Thanks,
BrokenOnion

Likely yes but if you look at the code behind a tool like sanoid, you'll realise that managing the snapshot is not trivial.
That's not even discussing the idea of auto updating without an admin eyes on the process.

Quote from: cookiemonster on November 21, 2026, 12:15:45 AMLikely yes but if you look at the code behind a tool like sanoid, you'll realise that managing the snapshot is not trivial.
That's not even discussing the idea of auto updating without an admin eyes on the process.

Are there any scripts that you would recommend? I took a look online what Sanoid is but I could barely find anything, there were a few mentions about Zabix, ESXi but nothing for bare metal installation of OPNsense.

No I would not recommend "automated" updates, full stop.
Automating snapshots is not new and can be done with your own scripting or leveraging something like sanoid because once you start auto sanpshotting, you need to manage them or you run out of storage, and removing the snapshots once you have hundreds is not fun.
I use sanoid on my OPN as it happens. I have a freeBSD-based NAS that receives the snapshots. syncoid then pushes them out for backup. This is only one of the parts of my backups regime.
My config is:

######################################
# This is a sample sanoid.conf file. #
# It should go in /etc/sanoid.       #
######################################

## name your backup modules with the path to their ZFS dataset - no leading slash.
#[zpoolname/datasetname]
#       # pick one or more templates - they're defined (and editable) below. Comma separated, processed in order.
#       # in this example, template_demo's daily value overrides template_production's daily value.
#       use_template = production,demo
#
#       # if you want to, you can override settings in the template directly inside module definitions like this.
#       # in this example, we override the template to only keep 12 hourly and 1 monthly snapshot for this dataset.
#       hourly = 12
#       monthly = 1
#
## you can also handle datasets recursively.
#[zpoolname/parent]
#       use_template = production
#       recursive = yes
#       # if you want sanoid to manage the child datasets but leave this one alone, set process_children_only.
#       process_children_only = yes
#
## you can selectively override settings for child datasets which already fall under a recursive definition.
#[zpoolname/parent/child]
#       # child datasets already initialized won't be wiped out, so if you use a new template, it will
#       # only override the values already set by the parent template, not replace it completely.
#       use_template = demo


# you can also handle datasets recursively in an atomic way without the possibility to override settings for child datasets.
#[zpoolname/parent2]
#       use_template = production
        # there are two options for recursive: zfs or yes
        # * zfs - taken a zfs snapshot with the '-r' flag; zfs will recursively take a snapshot of the whole
        #         dataset tree which is consistent. Newly-added child datasets will not immediately get snapshots,
        #         and must instead slowly catch up to policy over time. Slightly lower storage load.
        #
        # * yes - the snapshots will be taken one-at-time through the sanoid code; not necessarily consistent.
        #         newly added child datasets will be immediately brought into policy. Slightly higher storage load.
#       recursive = zfs

[zroot/ROOT]
     use_template = production
     recursive = zfs

[zroot/tmp]
     use_template = production
     recursive = zfs

[zroot/usr]
     use_template = production
     recursive = zfs

[zroot/var]
     use_template = production
     recursive = zfs


#############################
# templates below this line #
#############################

# name your templates template_templatename. you can create your own, and use them in your module definitions above.

[template_demo]
        daily = 60

[template_production]
        frequently = 0
        hourly = 3
        daily = 2
        monthly = 3
        yearly = 0
        autosnap = yes
        autoprune = yes

[template_backup]
        autoprune = yes
        frequently = 0
        hourly = 30
        daily = 90
        monthly = 12
        yearly = 0

        ### don't take new snapshots - snapshots on backup
        ### datasets are replicated in from source, not
        ### generated locally
        autosnap = no

        ### monitor hourlies and dailies, but don't warn or
        ### crit until they're over 48h old, since replication
        ### is typically daily only
        hourly_warn = 2880
        hourly_crit = 3600
        daily_warn = 48
        daily_crit = 60

[template_hotspare]
        autoprune = yes
        frequently = 0
        hourly = 30
        daily = 90
        monthly = 3
        yearly = 0

        ### don't take new snapshots - snapshots on backup
        ### datasets are replicated in from source, not
        ### generated locally
        autosnap = no

        ### monitor hourlies and dailies, but don't warn or
        ### crit until they're over 4h old, since replication
        ### is typically hourly only
        hourly_warn = 4h
        hourly_crit = 6h
        daily_warn = 2d
        daily_crit = 4d

[template_scripts]
        ### information about the snapshot will be supplied as environment variables,
        ### see the README.md file for details about what is passed when.
        ### run script before snapshot
        pre_snapshot_script = /path/to/script.sh
        ### run script after snapshot
        post_snapshot_script = /path/to/script.sh
        ### run script before pruning snapshot
        pre_pruning_script = /path/to/script.sh
        ### run script after pruning snapshot
        pruning_script = /path/to/script.sh
        ### don't take an inconsistent snapshot (skip if pre script fails)
        #no_inconsistent_snapshot = yes
        ### run post_snapshot_script when pre_snapshot_script is failing
        #force_post_snapshot_script = yes
        ### limit allowed execution time of scripts before continuing (<= 0: infinite)
        script_timeout = 5

[template_ignore]
        autoprune = no
        autosnap = no
        monitor = no

So I am keeping a snapshot of ROOT, tmp, usr and var all recursive.
With that I have some monthly, dailies and hourlies.

$ zfs list
NAME                  USED  AVAIL  REFER  MOUNTPOINT
zroot                14.9G  31.2G    96K  /zroot
zroot/ROOT           13.6G  31.2G    96K  none
zroot/ROOT/26.7.4_1     8K  31.2G  4.72G  /
zroot/ROOT/26.7.5    72.3M  31.2G  4.70G  /
zroot/ROOT/26.7.7    75.9M  31.2G  4.03G  /
zroot/ROOT/26.7.8       8K  31.2G  4.05G  /
zroot/ROOT/26.7.9    13.4G  31.2G  4.04G  /
zroot/tmp             612M  31.2G   201M  /tmp
zroot/usr             552K  31.2G    96K  /usr
zroot/usr/home         96K  31.2G    96K  /usr/home
zroot/usr/ports        96K  31.2G    96K  /usr/ports
zroot/usr/src         264K  31.2G    96K  /usr/src
zroot/var             616M  31.2G    96K  /var
zroot/var/audit       288K  31.2G    96K  /var/audit
zroot/var/crash       356K  31.2G   164K  /var/crash
zroot/var/log         614M  31.2G   256M  /var/log
zroot/var/mail        288K  31.2G   120K  /var/mail
zroot/var/tmp         712K  31.2G   132K  /var/tmp
penguin@OPNsense:~ $ zfs list -t snap
NAME                                                       USED  AVAIL  REFER  MOUNTPOINT
zroot/ROOT@autosnap_2026-09-01_01:07:01_monthly              0B      -    96K  -
zroot/ROOT@autosnap_2026-10-01_01:07:00_monthly              0B      -    96K  -
zroot/ROOT@autosnap_2026-11-01_02:07:00_monthly              0B      -    96K  -
zroot/ROOT@autosnap_2026-11-20_02:07:00_daily                0B      -    96K  -
zroot/ROOT@autosnap_2026-11-21_02:07:00_daily                0B      -    96K  -
zroot/ROOT@autosnap_2026-11-21_02:07:00_hourly               0B      -    96K  -
zroot/ROOT@autosnap_2026-11-21_08:07:01_hourly               0B      -    96K  -
zroot/ROOT@autosnap_2026-11-21_12:07:00_hourly               0B      -    96K  -
zroot/ROOT@autosnap_2026-11-21_18:07:00_hourly               0B      -    96K  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-01_02:07:00_monthly     0B      -  4.72G  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-20_02:07:00_daily       0B      -  4.72G  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-21_02:07:00_daily       0B      -  4.72G  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-21_02:07:00_hourly      0B      -  4.72G  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-21_08:07:01_hourly      0B      -  4.72G  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-21_12:07:00_hourly      0B      -  4.72G  -
zroot/ROOT/26.7.4_1@autosnap_2026-11-21_18:07:00_hourly      0B      -  4.72G  -
zroot/ROOT/26.7.5@autosnap_2026-11-01_02:07:00_monthly       0B      -  4.70G  -
zroot/ROOT/26.7.5@autosnap_2026-11-20_02:07:00_daily         0B      -  4.70G  -
zroot/ROOT/26.7.5@autosnap_2026-11-21_02:07:00_daily         0B      -  4.70G  -
zroot/ROOT/26.7.5@autosnap_2026-11-21_02:07:00_hourly        0B      -  4.70G  -
zroot/ROOT/26.7.5@autosnap_2026-11-21_08:07:01_hourly        0B      -  4.70G  -
zroot/ROOT/26.7.5@autosnap_2026-11-21_12:07:00_hourly        0B      -  4.70G  -
zroot/ROOT/26.7.5@autosnap_2026-11-21_18:07:00_hourly        0B      -  4.70G  -
zroot/ROOT/26.7.7@autosnap_2026-11-20_02:07:00_daily         0B      -  4.03G  -
zroot/ROOT/26.7.7@autosnap_2026-11-21_02:07:00_daily         0B      -  4.03G  -
zroot/ROOT/26.7.7@autosnap_2026-11-21_02:07:00_hourly        0B      -  4.03G  -
zroot/ROOT/26.7.7@autosnap_2026-11-21_08:07:01_hourly        0B      -  4.03G  -
zroot/ROOT/26.7.7@autosnap_2026-11-21_12:07:00_hourly        0B      -  4.03G  -
zroot/ROOT/26.7.7@autosnap_2026-11-21_18:07:00_hourly        0B      -  4.03G  -
zroot/ROOT/26.7.8@autosnap_2026-11-20_02:07:00_daily         0B      -  4.05G  -
zroot/ROOT/26.7.8@autosnap_2026-11-21_02:07:00_daily         0B      -  4.05G  -
zroot/ROOT/26.7.8@autosnap_2026-11-21_02:07:00_hourly        0B      -  4.05G  -
zroot/ROOT/26.7.8@autosnap_2026-11-21_08:07:01_hourly        0B      -  4.05G  -
zroot/ROOT/26.7.8@autosnap_2026-11-21_12:07:00_hourly        0B      -  4.05G  -
zroot/ROOT/26.7.8@autosnap_2026-11-21_18:07:00_hourly        0B      -  4.05G  -
zroot/ROOT/26.7.9@autosnap_2026-09-01_01:07:01_monthly    2.14G      -  4.72G  -
zroot/ROOT/26.7.9@autosnap_2026-10-01_01:07:00_monthly     539M      -  4.56G  -
zroot/ROOT/26.7.9@2026-10-07-21:01:58-0                    334M      -  4.72G  -
zroot/ROOT/26.7.9@2026-10-13-20:53:47-0                    400M      -  4.71G  -
zroot/ROOT/26.7.9@autosnap_2026-11-01_02:07:00_monthly     176M      -  4.03G  -
zroot/ROOT/26.7.9@2026-11-01-21:14:09-0                    166M      -  4.03G  -
zroot/ROOT/26.7.9@2026-11-15-20:51:03-0                    922M      -  4.05G  -
zroot/ROOT/26.7.9@autosnap_2026-11-20_02:07:00_daily       167M      -  3.99G  -
zroot/ROOT/26.7.9@autosnap_2026-11-21_02:07:00_daily         0B      -  4.04G  -
zroot/ROOT/26.7.9@autosnap_2026-11-21_02:07:00_hourly        0B      -  4.04G  -
zroot/ROOT/26.7.9@autosnap_2026-11-21_08:07:01_hourly      102M      -  4.04G  -
zroot/ROOT/26.7.9@autosnap_2026-11-21_12:07:00_hourly      107M      -  4.04G  -
zroot/ROOT/26.7.9@autosnap_2026-11-21_18:07:00_hourly      109M      -  4.04G  -
zroot/tmp@autosnap_2026-09-01_01:07:00_monthly            2.71M      -  2.74M  -
zroot/tmp@autosnap_2026-10-01_01:07:00_monthly             202M      -   202M  -
zroot/tmp@autosnap_2026-11-01_02:07:01_monthly             205M      -   205M  -
zroot/tmp@autosnap_2026-11-20_02:07:00_daily               252K      -  1.68M  -
zroot/tmp@autosnap_2026-11-21_02:07:00_daily               140K      -   201M  -
zroot/tmp@autosnap_2026-11-21_02:07:00_hourly              128K      -   201M  -
zroot/tmp@autosnap_2026-11-21_08:07:00_hourly              232K      -   201M  -
zroot/tmp@autosnap_2026-11-21_12:07:00_hourly              228K      -   201M  -
zroot/tmp@autosnap_2026-11-21_18:07:00_hourly              232K      -   201M  -
zroot/usr@autosnap_2026-09-01_01:07:01_monthly               0B      -    96K  -
zroot/usr@autosnap_2026-10-01_01:07:01_monthly               0B      -    96K  -
zroot/usr@autosnap_2026-11-01_02:07:00_monthly               0B      -    96K  -
zroot/usr@autosnap_2026-11-20_02:07:00_daily                 0B      -    96K  -
zroot/usr@autosnap_2026-11-21_02:07:00_daily                 0B      -    96K  -
zroot/usr@autosnap_2026-11-21_02:07:00_hourly                0B      -    96K  -
zroot/usr@autosnap_2026-11-21_08:07:00_hourly                0B      -    96K  -
zroot/usr@autosnap_2026-11-21_12:07:00_hourly                0B      -    96K  -
zroot/usr@autosnap_2026-11-21_18:07:00_hourly                0B      -    96K  -
zroot/usr/home@autosnap_2026-09-01_01:07:01_monthly          0B      -    96K  -
zroot/usr/home@autosnap_2026-10-01_01:07:01_monthly          0B      -    96K  -
zroot/usr/home@autosnap_2026-11-01_02:07:00_monthly          0B      -    96K  -
zroot/usr/home@autosnap_2026-11-20_02:07:00_daily            0B      -    96K  -
zroot/usr/home@autosnap_2026-11-21_02:07:00_daily            0B      -    96K  -
zroot/usr/home@autosnap_2026-11-21_02:07:00_hourly           0B      -    96K  -
zroot/usr/home@autosnap_2026-11-21_08:07:00_hourly           0B      -    96K  -
zroot/usr/home@autosnap_2026-11-21_12:07:00_hourly           0B      -    96K  -
zroot/usr/home@autosnap_2026-11-21_18:07:00_hourly           0B      -    96K  -
zroot/usr/ports@autosnap_2026-09-01_01:07:01_monthly         0B      -    96K  -
zroot/usr/ports@autosnap_2026-10-01_01:07:01_monthly         0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-01_02:07:00_monthly         0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-20_02:07:00_daily           0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-21_02:07:00_daily           0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-21_02:07:00_hourly          0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-21_08:07:00_hourly          0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-21_12:07:00_hourly          0B      -    96K  -
zroot/usr/ports@autosnap_2026-11-21_18:07:00_hourly          0B      -    96K  -
zroot/usr/src@autosnap_2026-09-01_01:07:01_monthly          56K      -    96K  -
zroot/usr/src@autosnap_2026-10-01_01:07:01_monthly          56K      -    96K  -
zroot/usr/src@autosnap_2026-11-01_02:07:00_monthly          56K      -    96K  -
zroot/usr/src@autosnap_2026-11-20_02:07:00_daily             0B      -    96K  -
zroot/usr/src@autosnap_2026-11-21_02:07:00_daily             0B      -    96K  -
zroot/usr/src@autosnap_2026-11-21_02:07:00_hourly            0B      -    96K  -
zroot/usr/src@autosnap_2026-11-21_08:07:00_hourly            0B      -    96K  -
zroot/usr/src@autosnap_2026-11-21_12:07:00_hourly            0B      -    96K  -
zroot/usr/src@autosnap_2026-11-21_18:07:00_hourly            0B      -    96K  -
zroot/var@autosnap_2026-09-01_01:07:00_monthly               0B      -    96K  -
zroot/var@autosnap_2026-10-01_01:07:01_monthly               0B      -    96K  -
zroot/var@autosnap_2026-11-01_02:07:01_monthly               0B      -    96K  -
zroot/var@autosnap_2026-11-20_02:07:00_daily                 0B      -    96K  -
zroot/var@autosnap_2026-11-21_02:07:00_daily                 0B      -    96K  -
zroot/var@autosnap_2026-11-21_02:07:00_hourly                0B      -    96K  -
zroot/var@autosnap_2026-11-21_08:07:00_hourly                0B      -    96K  -
zroot/var@autosnap_2026-11-21_12:07:00_hourly                0B      -    96K  -
zroot/var@autosnap_2026-11-21_18:07:00_hourly                0B      -    96K  -
zroot/var/audit@autosnap_2026-09-01_01:07:00_monthly        64K      -    96K  -
zroot/var/audit@autosnap_2026-10-01_01:07:01_monthly        64K      -    96K  -
zroot/var/audit@autosnap_2026-11-01_02:07:01_monthly        64K      -    96K  -
zroot/var/audit@autosnap_2026-11-20_02:07:00_daily           0B      -    96K  -
zroot/var/audit@autosnap_2026-11-21_02:07:00_daily           0B      -    96K  -
zroot/var/audit@autosnap_2026-11-21_02:07:00_hourly          0B      -    96K  -
zroot/var/audit@autosnap_2026-11-21_08:07:00_hourly          0B      -    96K  -
zroot/var/audit@autosnap_2026-11-21_12:07:00_hourly          0B      -    96K  -
zroot/var/audit@autosnap_2026-11-21_18:07:00_hourly          0B      -    96K  -
zroot/var/crash@autosnap_2026-09-01_01:07:00_monthly        64K      -    96K  -
zroot/var/crash@autosnap_2026-10-01_01:07:01_monthly        64K      -    96K  -
zroot/var/crash@autosnap_2026-11-01_02:07:01_monthly        64K      -    96K  -
zroot/var/crash@autosnap_2026-11-20_02:07:00_daily           0B      -   164K  -
zroot/var/crash@autosnap_2026-11-21_02:07:00_daily           0B      -   164K  -
zroot/var/crash@autosnap_2026-11-21_02:07:00_hourly          0B      -   164K  -
zroot/var/crash@autosnap_2026-11-21_08:07:00_hourly          0B      -   164K  -
zroot/var/crash@autosnap_2026-11-21_12:07:00_hourly          0B      -   164K  -
zroot/var/crash@autosnap_2026-11-21_18:07:00_hourly          0B      -   164K  -
zroot/var/log@autosnap_2026-09-01_01:07:00_monthly         105M      -   222M  -
zroot/var/log@autosnap_2026-10-01_01:07:01_monthly         127M      -   250M  -
zroot/var/log@autosnap_2026-11-01_02:07:01_monthly         120M      -   285M  -
zroot/var/log@autosnap_2026-11-20_02:07:00_daily           704K      -   251M  -
zroot/var/log@autosnap_2026-11-21_02:07:00_daily             0B      -   252M  -
zroot/var/log@autosnap_2026-11-21_02:07:00_hourly            0B      -   252M  -
zroot/var/log@autosnap_2026-11-21_08:07:00_hourly          416K      -   253M  -
zroot/var/log@autosnap_2026-11-21_12:07:00_hourly          408K      -   254M  -
zroot/var/log@autosnap_2026-11-21_18:07:00_hourly          468K      -   255M  -
zroot/var/mail@autosnap_2026-09-01_01:07:00_monthly         56K      -   120K  -
zroot/var/mail@autosnap_2026-10-01_01:07:01_monthly         56K      -   120K  -
zroot/var/mail@autosnap_2026-11-01_02:07:01_monthly         56K      -   120K  -
zroot/var/mail@autosnap_2026-11-20_02:07:00_daily            0B      -   120K  -
zroot/var/mail@autosnap_2026-11-21_02:07:00_daily            0B      -   120K  -
zroot/var/mail@autosnap_2026-11-21_02:07:00_hourly           0B      -   120K  -
zroot/var/mail@autosnap_2026-11-21_08:07:00_hourly           0B      -   120K  -
zroot/var/mail@autosnap_2026-11-21_12:07:00_hourly           0B      -   120K  -
zroot/var/mail@autosnap_2026-11-21_18:07:00_hourly           0B      -   120K  -
zroot/var/tmp@autosnap_2026-09-01_01:07:00_monthly          80K      -   132K  -
zroot/var/tmp@autosnap_2026-10-01_01:07:01_monthly          80K      -   132K  -
zroot/var/tmp@autosnap_2026-11-01_02:07:01_monthly          88K      -   132K  -
zroot/var/tmp@autosnap_2026-11-20_02:07:00_daily            64K      -   132K  -
zroot/var/tmp@autosnap_2026-11-21_02:07:00_daily             0B      -   132K  -
zroot/var/tmp@autosnap_2026-11-21_02:07:00_hourly            0B      -   132K  -
zroot/var/tmp@autosnap_2026-11-21_08:07:00_hourly           64K      -   132K  -
zroot/var/tmp@autosnap_2026-11-21_12:07:00_hourly           64K      -   132K  -
zroot/var/tmp@autosnap_2026-11-21_18:07:00_hourly           64K      -   132K  -

When my NAS is off like it is now, I will have gaps but that's OK for me. syncoid on there will manage them.
What you can see is:
-snapshots need managing
-they take space
-keeping in the same storage is of limited use
-I think you can use a tool like sanoid to do the heavy parts but you need to combine the snapshotting with the rest of what you want to do.
Personally as I keep saying, don't think is a good idea.

Why so complicated? Just use bectl - these snapshots will contain everything important.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

Today at 09:01:49 AM #5 Last Edit: Today at 09:38:43 AM by BrokenOnion
Does anyone know how to import the scripts into the Firewall itself? There is no option in GUI to upload files. I would like to avoid using additional \ 3rd party tools for the script \ updating.

Quote from: Patrick M. Hausen on November 21, 2026, 11:21:47 PMWhy so complicated? Just use bectl - these snapshots will contain everything important.

What's the native way to trigger updates via Bash? I'm thinking, I can place the script into the Firewall then set a Cron job in the GUI.

At the moment, I'm looking to automating updating itself, I found that you can trigger the updates via the following:

  • /usr/local/opnsense/scripts/firmware/check.sh
  • /usr/local/opnsense/scripts/firmware/update.sh

So, do I just set two Cron jobs pointing to the above locations and schedule the updates then test it out if it works?