Hi,
I want to write a script which manages automatically my zfs snapshots. The script itself will get started from cron.
I thought it would be the best if there would be a structure like this:
Daily snapshot from each day of the actual month
30-09-2011
...
03-09-2011
02-09-2011
01-09-2011
Weekly snapshot of the month before
29-08-2011
22-08-2011
15-08-2011
08-08-2011
01-08-2011
One snapshot of the two months before before
01-07-2011
01-06-2011
That was the idea.
Now I have some problems with writting this to code:
I would need something which erases every day except monday from the month before and something which erases every day except the first of the months before before.
The second would be easier
=> I need to "minus" the "%m" of the date command 2 (date +%d-(%m-2)-%Y) and with this variable I could set up a for loop which starts with 2 and end at 31 or the days which the month has.
For the first I need to get the dates of the mondays before the actual month.
Than a for loop has to remove all days except these mondays.
My question is now how I will get this to detail. So how I have to form the date command to use the month before and how to filter the mondays
Hope for help
Regards
I want to write a script which manages automatically my zfs snapshots. The script itself will get started from cron.
I thought it would be the best if there would be a structure like this:
Daily snapshot from each day of the actual month
30-09-2011
...
03-09-2011
02-09-2011
01-09-2011
Weekly snapshot of the month before
29-08-2011
22-08-2011
15-08-2011
08-08-2011
01-08-2011
One snapshot of the two months before before
01-07-2011
01-06-2011
That was the idea.
Now I have some problems with writting this to code:
Code:
#! /usr/local/bin/bash
# Settings
DATASET="storage/home"
DATE="$(date +%d-%m-%Y)"
zfs snapshot "$DATASET"@"$DATE"
I would need something which erases every day except monday from the month before and something which erases every day except the first of the months before before.
The second would be easier
=> I need to "minus" the "%m" of the date command 2 (date +%d-(%m-2)-%Y) and with this variable I could set up a for loop which starts with 2 and end at 31 or the days which the month has.
For the first I need to get the dates of the mondays before the actual month.
Than a for loop has to remove all days except these mondays.
My question is now how I will get this to detail. So how I have to form the date command to use the month before and how to filter the mondays
Hope for help
Regards