Changing ZFS Auto-Snapshot Settings On Oracle Solaris 11

Changing the default Time-Slider settings for Auto-Snapshot

By default when you activate Time-Slider on Solaris, auto-snapshot is enabled with the following names and settings:

  • “Frequent” - snapshots every 15 minutes, retaining 3 snapshots
  • “Hourly” - snapshots every hour, retaining 23 snapshots
  • “Daily” - snapshots every day, retaining 6 snapshots
  • “Weekly” - snapshots once a week, retaining 4 snapshots
  • “Monthly” - snapshots once a month, retaining 12 snapshots

Snapshots are taken on this time schedule until the drive is at 80% of it’s capacity (another default setting) at which point it will start deleting the oldest snapshots to make room for new ones or new data. If you want to alter these settings, there is unfortunately no user interface to do so. The only GUI setting that can be changed is the percent of drive space to use. This means that any further adjustments to the auto-snapshot policy needs to be done at the command line.

Making adjustments isn’t altogether hard. In fact, if you know the correct steps to take, it’s actually rather easy. One prerequisite though, as one would expect, is that you must have admin/root privileges to make the necessary changes.

At the command prompt, the first thing we’ll do is export the current settings with the following command:

svccfg export auto-snapshot > SnapshotSched.xml

This exports the current settings to the xml file so that they are easily viewed and edited. Now, simply open the file in your favorite text or xml editor and you should see sections that look like the following:

<instance name='frequent' enabled='true' complete='true'>
    <property_group name='zfs' type='application'>
        <propval name='interval' type='astring' value='minutes'/>
        <propval name='keep' type='astring' value='3'/>
        <propval name='period' type='astring' value='15'/>
    </property_group>
    <property_group name='general' type='framework'>
        <property name='action_authorization' type='astring'/>
        <property name='value_authorization' type='astring'/>
    </property_group>
</instance>

Here we can see for the instance ‘frequent’ where the two key properties: ‘keep’ and ‘period’ are set. Since I have a considerable amount of available space on my ZFS pool, I’m going to change these settings. I would still like to only have an hours worth of snapshots, but instead, I want them to happen every 10 minutes instead of 15. So, I change the ‘period’ value from 15 to 10, and then change the ‘keep’ value from 3 to 5 which looks like the following:

<instance name='frequent' enabled='true' complete='true'>
    <property_group name='zfs' type='application'>
        <propval name='interval' type='astring' value='minutes'/>
        <propval name='keep' type='astring' value='5'/>
        <propval name='period' type='astring' value='10'/>
    </property_group>
    <property_group name='general' type='framework'>
        <property name='action_authorization' type='astring'/>
        <property name='value_authorization' type='astring'/>
    </property_group>
</instance>

This will take snapshots at 10 minute intervals (as indicated by the ‘interval’ value being set to ‘minutes’) and will keep 5 snapshots for a total of 50 minutes. The next snapshot that would occur will be the hourly snapshot, thus removing the necessity to take a 6th snapshot under the ‘frequent’ interval.

Other settings for the ‘hourly’, ‘daily’, ‘weekly’ and ‘monthly’ instance types are changed in exactly the same manner. In fact, you can easily create a new instance type if you wish by copy and pasting an instance section to create a new retention policy. In my case, I wanted an annual snapshot taken and retained for 5 years. I copied the monthly portion, pasted it as a new section, and made the following modifications:

<instance name='annually' enabled='true' complete='true'>
    <property_group name='zfs' type='application'>
        <propval name='interval' type='astring' value='months'/>
        <propval name='keep' type='astring' value='5'/>
        <propval name='period' type='astring' value='12'/>
    </property_group>
    <property_group name='general' type='framework'>
        <property name='action_authorization' type='astring'/>
        <property name='value_authorization' type='astring'/>
    </property_group>
</instance>

With these settings, every 12 months, a new snapshot will be taken, and a total of 5 of them will be retained. With all the modifications made, it’s now time to save and close the file in preparation of importing it back into the system settings. To conduct the import, execute the following command:

svccfg import SnapshotSched.xml

With the settings loaded, they must now be made active. This could be done through a simple reboot of the server; however, it’s not necessary to do so. To activate the settings, each service must be refreshed and restarted. This could be done one at a time with the following commands:

svccfg -s service-name:instance-name refresh
svcadm restart service-name:instance-name

As there are multiple instances listed in the auto-snapshot service, this means that you’ll need to type in the instance name for each instance type: ‘frequent’, ‘hourly’, ‘daily’, etc. While it would be tempting to try the use of a wildcard to refresh and restart all auto-snapshot instances simultaneously, the svccfg and svcadm commands will not allow for it. Wildcards can in fact be used, but if in using them more than one result is returned, the command line will fail. To get around this, we’ll use the following two commands:

cat <(svcs auto-snapshot |grep svc: |awk '{print $3}')|xargs -n1 -I {} svccfg -s {} refresh
cat <(svcs auto-snapshot |grep svc: |awk '{print $3}')|xargs -n1 -I {} svcadm restart {}

These commands will take each instance and feed it one at a time into the previously listed commands, thus eliminating the need to retype each command over repeatedly. When executed successfully, you don’t get any feedback from the system. It simply pauses for a brief second and shows you a new command prompt. In addition to restarting the auto-snapshot, the Time-Slider should also be restarted by using the following command:

svcadm restart time-slider

This command also just drops you back to a fresh command prompt if execution is successful. To see if your settings took a quick check is to use a portion of the previous command and execute the following:

svcs auto-snapshot

The output will show you what snapshot services are running and when they were started. The start time should all be identical and should also correspond to when the restart command was executed. If you adjusted the period setting for the ‘frequent’ instance, you only need wait a short while and you should start seeing new snapshots at the prescribed interval. The current system snapshots can be viewed using the following command:

zfs list -t snapshot

On my system this generated the following output (truncated for convenience):

NAME USED AVAIL REFER MOUNTPOINT
stack@zfs-auto-snap_hourly-2015-02-06-17h13 8.63M - 1.05T -
stack@zfs-auto-snap_hourly-2015-02-06-18h13 8.73M - 1.05T -
stack@zfs-auto-snap_hourly-2015-02-06-19h13 8.48M - 1.05T -
stack@zfs-auto-snap_hourly-2015-02-06-20h13 6.98M - 1.05T -
stack@zfs-auto-snap_frequent-2015-02-06-20h43 5.84M - 1.05T -
stack@zfs-auto-snap_frequent-2015-02-06-20h58 4.74M - 1.05T -
stack@zfs-auto-snap_annually-2015-02-06-21h00 4.74M - 1.05T -
stack@zfs-auto-snap_frequent-2015-02-06-21h08 5.24M - 1.05T -
stack@zfs-auto-snap_hourly-2015-02-06-21h13 5.49M - 1.05T -
stack@zfs-auto-snap_frequent-2015-02-06-21h23 5.24M - 1.05T -
stack@zfs-auto-snap_frequent-2015-02-06-21h33 4.62M - 1.05T -

Here you can see the timestamps for the ‘hourly’ snapshots were occurring at 13 minutes past the hour. As prescribed, the ‘frequent’ snapshots were happening at 15 minute intervals (only the last 2 are shown with at 2043 and 2058). At 2100 I executed the refresh and the first ‘annual’ snapshot was taken according to the updated settings. Since the period was changed for ‘frequent’ snapshots, the next one took place as prescribed at 10 minutes after the previous snapshot (2058 to 2108). However, since the ‘hourly’ period wasn’t changed, the next ‘hourly’ snapshot still happened at 13 after. You’ll observe, the next ‘frequent’ snapshot took place 10 minutes after the ‘hourly’ snapshot (2113 to 2123) , which is why you see the odd skip in timestamps for the ‘frequent’ snapshots. After that, the ‘frequent’ snapshots fall into place at 10 minute intervals coinciding with the hourly snapshots. Additionally, you can see that the retention setting of 5 ‘frequent’ snapshots was also properly updated as there are now a total of 5 ‘frequent’ snapshots.

Now that you you know how to adjust the snapshot frequency, the next useful thing I would recommend you look into is retaining snapshots so that they are not deleted. Or, in Oracle terms, “hold” the snapshots so that they are not “destroyed.” This is very useful for meeting retention requirements for legal compliance.