Michael Altfield's gravatar

Automatic Timestamped ZFS Snapshots with Cron

A couple of months ago I setup a cron job to automatically create timestamped snapshots of my zfs filesystem. Little did I know, there was a syntax error preventing my job from actually executing. Here's the correct (yet not-so-intuitive) cron job to get a nightly, timestamped snapshot of the ZFS filesystem @tank@:

The following is incorrect:

20 4 * * * zfs snapshot tank@`date "+%Y%m%d%H%m%S"`

Here's what I found in the cron log file:


# tail /var/cron/log
...
> CMD: zfs snapshot tank@`date "+
...

As you can see, the command is being truncated after the plus sign (+), indicating that there is an issue with the following character: the percent sign (%).

The following is correct:

20 4 * * * zfs snapshot tank@`date +%Y%m%d%H%m%S`

Note that I had to escape the percent sign (%) and remove the double quotes.

Now I'm finally getting automatic nightly snapshots. Yay! 🙂

Related Posts

2 comments to Automatic Timestamped ZFS Snapshots with Cron

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>