Hi Dag;
Jq looks great it really eliminates lots of long lines of codes in my bash
scripts for json parsing. Thanks for sharing this useful tool with us.

Thanks
Özhan

On Fri, Nov 11, 2016 at 5:48 PM, Dag Sonstebo <dag.sonst...@shapeblue.com>
wrote:

> Hi Alessandro,
>
> “Jq” is your friend here. You would start by just listing all the volume
> snapshot ordered by create time – whilst also capturing the snapshot ID:
>
> # cloudmonkey list snapshots volumeid=21f830d8-b182-41dc-8a10-48ff0a07f299
> | jq -r '.snapshot[] | .created + "|" + .id' | sort -r
> 2016-11-11T14:41:59+0000|418075c1-bcfc-4b9f-b2f2-4e11fb3e111c
> 2016-11-11T14:41:29+0000|363129bd-ee9b-4301-b46b-a09291f05b98
> 2016-11-11T14:39:52+0000|fd51897e-725f-40b0-a07d-7bad6cbd7c89
> 2016-11-11T14:32:57+0000|7f2a7b7d-789d-4056-b287-9b8f8e113e76
>
> Now that you have this list all you need to do is parse it, i.e. any id
> entries in line 22 onwards you need to delete, whilst also comparing the
> date stamp with (today – 7days).
>
> Keep in mind your logic though: you should probably retain 21 snapshots no
> matter what the age is – if your snapshot script fails to take snapshots –
> and you delete all snapshots older than 7  days you could end up deleting
> all snapshots… (just my twopence worth).
>
>
> Regards,
> Dag Sonstebo
> Cloud Architect
> ShapeBlue
>
> On 11/11/2016, 14:04, "Alessandro Caviglione" <c.alessan...@gmail.com>
> wrote:
>
>     Hi guys,
>     I've a Cloudmonkey script under cron that create a Volume Snapshot of
> a VPS
>     at certain hours.
>     I had to create this script because client wants to have more than one
>     Snapshotfor each day, so through GUI this is not possible.
>     Now, could someone help me to delete old Snapshot in the scripts?
>     I need to retain 21 Snapshots or delete Snap older than 7 days.
>
>     Thank you!!
>
>
>
> dag.sonst...@shapeblue.com
> www.shapeblue.com
> 53 Chandos Place, Covent Garden, London  WC2N 4HSUK
> @shapeblue
>
>
>
>

Reply via email to