SOLVED Create Snapshot on every Boot

elektropepi

Cadet
Joined
Feb 12, 2021
Messages
6
Hello everyone,

my TrueNAS system is not running all of the time, it's rather booted on-demand. Therefore I can't use the periodic snapshot feature, since I can't make sure that the NAS is running at the defined snapshot time . I still want to have some kind of regular snapshot process.

Is there a built-in way in TrueNAS to create a snapshot everytime the system boots up?

If no, I'd imagine I can add a post-init script that calls something like zfs snapshot -r pool_name@snapshot_name but I still want the snapshots to show up in the Snapshot section in the UI. Is any ZFS snapshot shown in that section or do I have to follow a certain naming convention?

Any help is greatly appreciated.
Cheers,
Elektropepi
 
Joined
Oct 22, 2019
Messages
3,641
I still want the snapshots to show up in the Snapshot section in the UI. Is any ZFS snapshot shown in that section or do I have to follow a certain naming convention?
Any snapshot you create, whether through the GUI, API, or command-line, will show up in the Snapshots page in the GUI.


You can create a task to run at every system bootup.

Go to Tasks -> Init/Shutdown Scripts

Create a new entry and give it a Description like: Recursive auto snapshot for entire pool at bootup

Type: Command

Command: zfs snap -r poolname@auto-`date +%Y-%m-%d_%H-%M`

When: Post-Init

Enabled: Yes

Timeout: You can leave it at the default or bump it to something 30 seconds. (Taking a snapshot should only take mere seconds at most, anyways.)

Replace poolname with your actual pool's name.

The recursive snapshots (which will be created for all datasets in the pool) will be named something like "auto-2023-07-15_1345" depending on the system time.
 
Last edited:

elektropepi

Cadet
Joined
Feb 12, 2021
Messages
6
Hi winnielinnie, thanks for your response. Works like a charm.

Just two follow-up questions, maybe you can help me there too:
  1. Do you think I actually need the recursive flag? Because in the end, I only want to snapshot where most of my files are stored, so I don't really need to snapshot stuff like iocage, iocage/download, iocage/images, etc. right?
  2. I want to clean up those bootup snapshots too (like the periodic snapshot task does) if they reach a certain age. Do you know whether I can reuse this script so it's run on bootup too?
 
Joined
Oct 22, 2019
Messages
3,641
Do you think I actually need the recursive flag? Because in the end, I only want to snapshot where most of my files are stored, so I don't really need to snapshot stuff like iocage, iocage/download, iocage/images, etc. right?
That's up to you. The iocage datasets can be considered important as well. Either way, a snapshot will only consume space when it "holds onto" data that has been deleted.


I want to clean up those bootup snapshots too (like the periodic snapshot task does) if they reach a certain age. Do you know whether I can reuse this script so it's run on bootup too?
TrueNAS is meant to run 24/7, and you're supposed to use the GUI and middleware for automation.

If you want...
  • Automatic snapshots
  • Exclude certain children of a recursive snapshot
  • Automatic pruning
...then it's not as practical nor feasible to rely on your own scripts to do this every time you boot up.

You'd need to use more fancy scripting, and essentially recreate what the appliance already does for you with Automatic Snapshot Tasks.
 
Last edited:
Top