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
Hi, I’m Michael Altfield. I write articles about opsec, privacy, and devops âž¡
Are you accidentally recording the month in your filename twice? I think the %m for minute should be uppercase “%M”?
Good catch, thanks!