Periodic Snapshot Tasks
7 minute read.Last Modified 2021-03-24 14:35 EDT
A periodic snapshot task allows scheduling the creation of read-only versions of pools and datasets at a given point in time.
Snapshots are created quickly and, if little data changes, new snapshots take very little space, since snapshots do not make new copies of the data. It is quite common to take snapshots as frequently as every 15 minutes, even for large and active pools. A snapshot where no files have changed takes no storage space, but as changes are made to files, the snapshot size changes to reflect the size of the changes. Space is recovered in the same way as all pool data, when the last reference to the data is destroyed.
Snapshots keep a history of files, providing a way to recover an older copy or even a deleted file. For this reason, many administrators take snapshots often, store them for a period of time, and store them on another system, typically using Replication Tasks. Such a strategy allows the administrator to roll the system back to a specific point in time. If there is a catastrophic loss, an off-site snapshot can be used to restore data up to the time of the last snapshot.
Any required datasets or zvols must exist before creating a snapshot task.
Go to Tasks > Periodic Snapshot Tasks and click ADD.
Choose the dataset (or zvol) to regularly back up with snapshots and how long to store snapshots. Define the task Schedule. When a specific Schedule is required, choose Custom and use the Advanced Scheduler.
Choosing a preset fills in the rest of the fields.
To customize a schedule, enter crontab values for the
These fields accept standard cron values. The simplest option is to enter a single number in the field. The task runs when the time value matches that number. For example, entering 10 means that the job runs when the time is ten minutes past the hour.
An asterisk (
*) means “match all values”.
Specific time ranges are set by entering hyphenated number values. For example, entering 30-35 in the Minutes field sets the task to run at minutes 30, 31, 32, 33, 34, and 35.
Lists of values can also be entered.
Enter individual values separated by a comma (
For example, entering 1,14 in the Hours field means the task runs at 1:00 AM (0100) and 2:00 PM (1400).
A slash (
/) designates a step value.
For example, while entering
* in Days means the task runs every day of the month,
*/2 means the task runs every other day.
Combining all the above examples together creates a schedule running a task each minute from 1:30-1:35 AM and 2:30-2:35 PM every other day.
There is an option to select which Months the task runs. Leaving each month unset is the same as selecting every month.
The Days of Week schedules the task to run on specific days. This is in addition to any listed Days. For example, entering 1 in Days and setting Wed for Days of Week creates a schedule that starts a task on the first day of the month and every Wednesday of the month.
The Schedule Preview shows when the current settings mean the task runs.
|*||Every item.||* (minutes) = every minute of the hour.|
* (days) = every day.
|*/N||Every Nth item.||*/15 (minutes) = every 15th minute of the hour (every quarter hour).|
*/3 (days) = every 3rd day.
*/3 (months) = every 3rd month.
|Comma and hyphen/dash||Each stated item (comma)|
Each item in a range (hyphen/dash).
|1,31 (minutes) = on the 1st and 31st minute of the hour.|
1-3,31 (minutes) = on the 1st to 3rd minutes inclusive, and the 31st minute, of the hour.
mon-fri (days) = every Monday to Friday inclusive (every weekday).
mar,jun,sep,dec (months) = every March, June, September, December.
Days can be specified as days of month, or days of week.
With these options, flexible schedules can be created similar to these examples:
|Desired schedule||Values to enter|
|3 times a day (at midnight, 08:00 and 16:00)||months=*; days=*; hours=0/8 or 0,8,16; minutes=0|
(Meaning: every day of every month, when hours=0/8/16 and minutes=0)
|Every Monday, Wednesday and Friday, at 8.30 pm||months=*; days=mon,wed,fri; hours=20; minutes=30|
|1st and 15th day of the month, during October to June, at 00:01 am||months=oct-dec,jan-jun; days=1,15; hours=0; minutes=1|
|Every 15 minutes during the working week, which is 8am - 7pm (08:00 - 19:00) Monday to Friday||Note that this requires two tasks to achieve:|
(1) months=*; days=mon-fri; hours=8-18; minutes=*/15
(2) months=*; days=mon-fri; hours=19; minutes=0
We need the second scheduled item, to execute at 19:00, otherwise we would stop at 18:45. Another workaround would be to stop at 18:45 or 19:45 rather than 19:00.
Configure the remaining options to your use case.
|Dataset||Select a pool, dataset, or zvol.|
|Recursive||Set to take separate snapshots of the dataset and each of its child datasets. Leave unset to take a single snapshot only of the specified dataset without child datasets.|
|Exclude||Exclude specific child datasets from the snapshot. Use with recursive snapshots. List paths to any child datasets to exclude. Example: |
|Snapshot Lifetime||Define a length of time to retain the snapshot on this system using a numeric value and a single lowercase letter for units. Examples: 3h is three hours, 1m is one month, and 1y is one year. Does not accept Minute values. After the time expires, the snapshot is removed. Snapshots which have been replicated to other systems are not affected.|
|Naming Schema||Snapshot name format string. The default is |
|Schedule||Choose one of the presets or Custom to use the advanced scheduler.|
|Allow Taking Empty Snapshots||Creates dataset snapshots even when there have been no changes to the dataset from the last snapshot. Recommended for long-term restore points, multiple snapshot tasks pointed at the same datasets, or compatibility with snapshot schedules or replications created in TrueNAS 11.2 and earlier. For example, allowing empty snapshots for a monthly snapshot schedule allows that monthly snapshot to be taken, even when a daily snapshot task has already taken a snapshot of any changes to the dataset.|
|Enabled||To activate this periodic snapshot schedule, set this option. To disable this task without deleting it, unset this option.|
The Naming Schema determines how automated snapshot names are generated. A valid schema requires the %Y (year), %m (month), %d (day), %H (hour), and %M (minute) time strings, but you can add more identifiers to the schema too, using any identifiers from the Python strptime function.
This uses some letters differently from POSIX (Unix) time functions.
For example, including
%z (time zone) ensures that snapshots do not have naming conflicts when daylight time starts and ends, and %S (second) adds finer time granularity.
|Naming Scheme||Snapshot Names Look Like|
When snapshots are to be referenced from a Windows computer, avoid using characters like
:that are invalid in a Windows file path. Some applications filename or path length limits, and there may be limitations related to spaces and other characters. Carefully consider future uses and ensure the names given to periodic snapshots are acceptable.
TrueNAS automatically deletes snapshots when they reach the end of their life and preserves snapshots when at least one periodic task requires it. For example, suppose two schedules are created, one that takes a snapshot every hour and keeps them for a week, and one that takes a snapshot every day and keeps them for 3 years. A snapshot is taken every hour. After a week, snapshots created at 01.00 through 23.00 are deleted, but snapshots timed at 00.00 are kept because they are needed for the second periodic task. These snapshots are destroyed at the end of 3 years.
Click SUBMIT to save this task and add it to the list in Tasks > Periodic Snapshot Tasks. Any snapshots taken using this task are found in Storage > Snapshots.
To check the log for a saved snapshot schedule, go to Tasks > Periodic Snapshot Tasks and click the task State.