*New 12.1 series Release:
2019-11-08: XigmaNAS 12.1.0.4.7091 - released!

*New 11.3 series Release:
2019-10-19: XigmaNAS 11.3.0.4.7014 - released


We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

Automaticly Delete Snapshots? Cron?

Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
User avatar
juddyjacob
Starter
Starter
Posts: 48
Joined: 07 Sep 2012 03:01
Location: Leonardo New Jersey
Contact:
Status: Offline

Automaticly Delete Snapshots? Cron?

#1

Post by juddyjacob » 22 Jan 2013 07:20

I'm currently trying to figure out how to have my system auto delete snapshots, say that are 30 days old. I'm assuming this has to be done with a cron script? Which is AWSOME! "sarcasim - because I have no experience with scripting! Can someone point me in the right direction? Like where would I put the script? Where would I call on the script? Know a good site / book I might be able to get some basics? I hate that "I'm in over my head feeling" Gotta start somewhere I guess!

I did find this in /etc/crontab

SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute hour mday month wday who command
#
# autosnapshot
0 */1 * * * root /usr/local/sbin/autosnapshot >/dev/null 2>&1

looks like this is where the schedule for the snapshot is, Is there something I can add here to have the oldest delete after 30 days?
x64-full on Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz : Supermicro X10SRL-F : 130926MiB ECC Ram: 8x4TB RZ2 : 19TB Usable

User avatar
raulfg3
Site Admin
Site Admin
Posts: 4968
Joined: 22 Jun 2012 22:13
Location: Madrid (ESPAÑA)
Contact:
Status: Offline

Re: Automaticly Delete Snapshots? Cron?

#2

Post by raulfg3 » 22 Jan 2013 08:35

check script done by fritz: viewtopic.php?f=70&t=2197 and modify as your need if necessary.
12.0.0.4 (revision 6766)+OBI on SUPERMICRO X8SIL-F 8GB of ECC RAM, 12x3TB disk in 3 vdev in RaidZ1 = 32TB Raw size only 22TB usable

Wiki
Last changes

User avatar
juddyjacob
Starter
Starter
Posts: 48
Joined: 07 Sep 2012 03:01
Location: Leonardo New Jersey
Contact:
Status: Offline

Re: Automaticly Delete Snapshots? Cron?

#3

Post by juddyjacob » 23 Jan 2013 03:12

Thanks, I did check it out. And I think I'm getting a closer but I'm confused on the method used to delete a snapshot after a perticular time period.
From what I can gather (remember I am no expert! LOL) I believe this should be in the crontab, please let me know if this is close?

# Auto Delete Snapshot After 60 Days
0 */1 * * * root /usr/local/sbin/zfSnap -d -o

I saw the ( -o ) option is to delete a snapshot with an old timestamp, but I dont know how this is impiled to a particular age. Is there anotherway to state delete after 60 days?
Something tells me an age flag has to be implemented in the autosnapshot cron job? Is this right? Is That what the "Lifetime" option is in the auto snapshot configuration? I assumed it was the time lenght you wanted the autosnapshot to run? In other words if you stated 2 weeks, In 2 weeks the autosnapshot would end? Shed some light please! LOL

Something tells me this is exactly what im looking for - looking forward to feeling stupid...LOL

BTW - Where are the snapshots physically stored?
x64-full on Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz : Supermicro X10SRL-F : 130926MiB ECC Ram: 8x4TB RZ2 : 19TB Usable

fsbruva
Advanced User
Advanced User
Posts: 383
Joined: 21 Sep 2012 14:50
Status: Offline

Re: Automaticly Delete Snapshots? Cron?

#4

Post by fsbruva » 25 Jan 2013 13:39

Since it seems your crontab entry is the same as the howto page on the github site, I suppose that will work. The issue is that the snapshot deletion will ONLY work if the snapshots have been created with the zfSnap script also. This is because when the snapshot is created, it is named in such a way that its expiration is part of its name. In this way, the delete command knows if the snapshot is too old.

The -d -o flag is only necessary if you created some snapshots with an earlier version of zfSnap.

Their storage location within the pool varies, depending on where the changed file resided prior to its modification or deletion. This is because zfs uses something called "copy on write." When you make a change to a file, an entirely new copy of the file is written to disk, elsewhere from the original. Once ZFS has verified that the write operation was carried out successfully, it then moves the file pointer to the new copy of the file, and deletes the old copy. In this way, zfs is able to mitigate the damage of an interrupted write operation. Now, if you take a snapshot today, zfs will keep track of the files you change and delete. Instead of actually deleting the old copy (in the case of a file modification), zfs lets the snapshot take ownership of the old version of the file. The same thing happens when you delete a file. Instead of freeing that disk space and allowing other things to be written there, zfs maintains the deleted file as part of the snapshot.

Because nothing is actually copied, zfs snapshots are instantaneous and take up no space. Snapshots grow in size as you delete/change files within the protected pool or dataset.

User avatar
juddyjacob
Starter
Starter
Posts: 48
Joined: 07 Sep 2012 03:01
Location: Leonardo New Jersey
Contact:
Status: Offline

Re: Automaticly Delete Snapshots? Cron?

#5

Post by juddyjacob » 26 Jan 2013 05:46

Thank You,

I found your information very informative and usefull. I still do not see the symbolism within the cron job that states when to release the snapshot, however I have a feeling its because im looking in the wrong place.

The crontab now sates:
# autosnapshot
0 */1 * * * root /usr/local/sbin/autosnapshot >/dev/null 2>&1
0 0 * * * root /var/run/rsync_client_3690d70c-dad4-425c-a9d9-26d64ceddca3.sh

I think the "3690d70c-dad4-425c-a9d9-26d64ceddca3.sh" is somehow related to the timeline function, but im not sure. I read the script but it appears to be more geared to controlling the action of Rsync and output of log files, or incase it was allready or still running.

This part of it did spark my attention:
"/usr/local/bin/rsync --log-file=/var/log/rsync_client.log --recursive --times --compress --delete "rsync://###.###.###.###/Backup" "/mnt/Backups/Backup/"
/bin/rm -f /var/run/rsync_client_running_3690d70c-dad4-425c-a9d9-26d64ceddca3"

But I still dont see anything where it says "after 60 days delete"
AH- I found it /var/etc/autosnapshot.conf
"daily Backups/Backup auto-%Y%m%d-%H0000 true * * 2000 0000 60d 5270400" - The only part I understand is auto-%Y%m%d-%H and 60d though...LOL

I did however use the lifetime option within the GUI features to specify a 60 lifetime. I'm hoping that within 60 days it will release the snapshot but I guess only 61 days worth of time will tell. But even still, I cant express enough how much I appreciate the responses and hopefully within a couple years or so Ill be able to add some of my own educated posts. :)

My next task is to change the log file destination, which I saw that you could do with the extra options feature, and wish to print the logs to a file and email to myself.....wish me luck! LOL! But is it ok for me to add the code here "/var/run/rsync_client_3690d70c-dad4-425c-a9d9-26d64ceddca3.sh" at the end of coarse. I want it to do it right after rsync finishes. I know the basic commands I need to use "cat" "printf" & "msmtp" I think! I'm sure this will be my next post but im gonna give it a healthy go before I cry for help and post it within the right thread.
x64-full on Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz : Supermicro X10SRL-F : 130926MiB ECC Ram: 8x4TB RZ2 : 19TB Usable

fsbruva
Advanced User
Advanced User
Posts: 383
Joined: 21 Sep 2012 14:50
Status: Offline

Re: Automaticly Delete Snapshots? Cron?

#6

Post by fsbruva » 26 Jan 2013 17:31

juddyjacob wrote: 0 */1 * * * root /usr/local/sbin/autosnapshot >/dev/null 2>&1
So are you using autosnapshot or zfSnap? You make it very difficult to help you if you insist on changing the problem. I am going to proceed with answering your questions about zfSnap, with the undertanding that the basic tactics employed are about the same.

Now, your earlier post instructed zfSnap to delete any old snapshots. But, since you didn't create any snapshots, zfSnap will never delete any. You will need two crontab entries.... one to create snapshots, and another to clean up the old ones. As you can see by reading the zfSnap wiki:
5 * * * * root /usr/local/sbin/zfSnap -a 5d -r zpool
That line instructs zfStune to create hourly snapshots that have an time to live of 5 days. When it runs, it will create snapshots that are named with a combination of the dataset name, the time/date of creation and how long to keep it around. As you can see from the wiki:
zpool/var@2010-08-03_12.06.00--5d

This is the name of a snapshot on pool "zpool," dataset "var", and it was created at 12:06:00 on August 03, 2010. It should remain around for 5 days. When the crontab task to delete old snapshots is run, the following things happen:
1. The time to live is added to creation date/time to create an expiration date/time
2. This expiration date/time is compared to the current date/time
3. If the current date/time is past the expiration date/time, the snapshot is destroyed
These steps are repeated for all snapshots.

In summary - you need at least two crontab entries: 1 to create some snapshots that can have their validity (expiration) determined by what they are named, and 1 to delete the old ones that have expired.

mlbx
NewUser
NewUser
Posts: 1
Joined: 27 Jan 2013 08:17
Status: Offline

Re: Automaticly Delete Snapshots? Cron?

#7

Post by mlbx » 27 Jan 2013 08:21

The interactive cron sandbox at http://www.dataphyx.com will show you a list of future run-times for whatever time/date values you put in.

Post Reply

Return to “ZFS (only!)”