cloudstack-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dag Sonstebo <Dag.Sonst...@shapeblue.com>
Subject Re: Manual Volume Snapshot retention
Date Thu, 17 Nov 2016 16:14:01 GMT
Hi Alessandro,

Sorry forgot to say this requires you to set CloudMonkey to display json. If CloudMonkey display
is set to “default” you will get parse error.

Either: In your /<username>/.cloudmonkey/config file set the following:
----
 [ui]
display = json
----

Or do this from command line:
# cloudmonkey list snapshots display=json | jq -r '.snapshot[] | .created + "|" + .id' | sort
-r
parse error: Invalid numeric literal at line 1, column 6
# cloudmonkey set display json
# cloudmonkey list snapshots volumeid=21f830d8-b182-41dc-8a10-48ff0a07f299 | jq -r '.snapshot[]
| .created + "|" + .id + "|" + .state' | sort -r
2016-11-11T14:41:59+0000|418075c1-bcfc-4b9f-b2f2-4e11fb3e111c|BackedUp
2016-11-11T14:41:29+0000|363129bd-ee9b-4301-b46b-a09291f05b98|BackedUp
2016-11-11T14:39:52+0000|fd51897e-725f-40b0-a07d-7bad6cbd7c89|BackedUp
2016-11-11T14:32:57+0000|7f2a7b7d-789d-4056-b287-9b8f8e113e76|BackedUp

One more thing about your script – make sure you also capture the state like the above example
– if your snapshots aren’t all in state “BackedUp” you should probably consider them
as not valid for the purpose of maintaining healthy snapshots.

Regards,
Dag Sonstebo

On 17/11/2016, 13:40, "Alessandro Caviglione" <c.alessandro@gmail.com> wrote:

    Hi Dag,
    thank you very much, I didn't know jq!
    But with your command I get this error:
    
    parse error: Invalid numeric literal at line 1, column 6
    
    I search on Google and I see that it could be a problem of missing double
    quote in the json array... but it's strange because it's not a file but an
    API query results...
    
    On Mon, Nov 14, 2016 at 11:33 AM, Özhan Rüzgar Karaman <
    oruzgarkaraman@gmail.com> wrote:
    
    > 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.Sonstebo@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.alessandro@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.Sonstebo@shapeblue.com
    > > www.shapeblue.com
    > > 53 Chandos Place, Covent Garden, London  WC2N 4HSUK
    > > @shapeblue
    > >
    > >
    > >
    > >
    >
    


Dag.Sonstebo@shapeblue.com 
www.shapeblue.com
53 Chandos Place, Covent Garden, London  WC2N 4HSUK
@shapeblue
  
 

Mime
View raw message