-
szilard
Hi. I am trying to create and delete ZFS snapshots using the crontab, creation works ok, but I am facing issues with the deleting part.
-
szilard
The crontab entry looks like this:
-
szilard
SHELL=/usr/bin/zsh
-
szilard
10 21 * * * /usr/sbin/zfs destroy -r tank@`TZ=$TZ+167 date +'%Y-%m-%d'` 2>> /var/log/zfs.destroy
-
szilard
However I am getting the following error:
-
szilard
zsh:1: unmatched `
-
szilard
If you are wondering the +167 is the maximum offset value TZ accepts, with this I attempt to delete snapshots older than 7 days, or so.
-
szilard
the command works just fine in root ZSH shell, but it fails in crontab, so there must be some differences, but I don't know, how to find it.
-
szilard
I have already tried to change the command to : tank@$(TZ=$TZ+167 date +'%Y-%m-%d') but it didn't help
-
szilard
Please let me know if oyu have any better solution for this.
-
tomww
your could move the code into a shell script file with #!/usr/bin/zsh on the first line and led crontab call that file
-
tomww
my apporach to deleting autmatic snapshots is having a dedidacted constant part in the name like "autobackup_" and the date in seconds. Then a zfs list -r -t snapshot -o name | grep autobackup_ and then not delete the last n-number snapshots
-
tomww
(or egrep "@autobackup_1[0-9]*$" )
-
szilard
tomww: Thanks for the hint, I'll test it and will also think about your approach.
-
szilard
Thanks again.
-
tomww
you’re welcome
-
szilard
I'd liek to use a USB drive for cold backup. I'd liek to have a ZFS pool on it, so i can send snapshots there. Am I supposed to create a partition and create Zpool on that partition, or should I use the raw device itself for the pool?
-
szilard
tomww: what do you think about this aproach:
-
szilard
/usr/sbin/zfs list -d 1 -H -o name -t snapshot | grep "tank@" | tail -n +7 | xargs /usr/sbin/zfs destroy -r
-
szilard
-d 1 means it lists non-recursively (so it emmits only the top level dataset names
-
szilard
-H means it ommits the output header (this is not really needed)
-
szilard
-o will instruct zfs to list only the name property
-
szilard
tail -n +7 means it ommits the first 7 items
-
szilard
So it deletes all snapshots except the 7 most recent ones
-
tomww
I try to never stript a "destroy -r". instead I try to identify every single zfs filesystem and loop over that one to find all snapshots in there.
-
tomww
and for the first run I prefix the destroy command with "echo" to only see the command it _would_ run.
-
szilard
tomw, I agree.
-
szilard
I have modified my script like this:
-
szilard
/usr/sbin/zfs list -d 1 -o name -t snapshot | grep "tank@autobackup" | tail -n +7 | xargs /usr/sbin/zfs destroy -r
-
tomww
note: I'm only reading occationally here, so scripting support is very limited on my side
-
szilard
included autobackup in the grep, so it will list only applicable snapshots from tank and will keep the 7 most recent version
-
tomww
I still do not use a "-r" in destroy. think of a clone dependent on a snapshot. I might be killed the clone.
-
szilard
I haven't tried zfs cloning feature yet.
-
szilard
I haven't used many of the zfs features yet.
-
szilard
But thanks for the hint.
-
oninoshiko
if a clone is dependent on a snapshot -r is not enough to delete it. You need -R in that case.
-
szilard
I am wondering, why is there . and .. in my /
-
tux0r
. is everywhere
-
jayjwa
. and .. show up in my omnios and linux systems in /