JozefJarosciak / Lightsail-Backup-and-Clean-Up-Shell-Script

Shell script to automatically remove old AWS Lightsail snapshots (and retain only a specific number of snapshot backups)
The Unlicense
23 stars 17 forks source link

Updated script to make it more useful #1

Open harrystaley opened 7 years ago

harrystaley commented 7 years ago

I have updated your Lightsail Script to make it more flexible.

Feel free to pull in my fork if you like.

JozefJarosciak commented 7 years ago

Fantastic work. I will merge it soon.

vw1234 commented 6 years ago

I am testing this script with a few instances and found it does not work well. the jq select part does not do the work.

maherber commented 6 years ago

I'd the same issue. The following jq part doesn't work SnapshotNames=$(aws lightsail get-instance-snapshots | jq '.[] | sort_by(.createdAt) | select(.[0].fromInstanceName == "'${NameOfYourInstance}'") | .[].name') I'm not an expert in jq, hope for a quick correction

seagullnz commented 6 years ago

I also have the same issue as @vw1234 , SnapshotNames returns blank. I have tried several variations but I cannot targert the snapshots I need.

vw1234 commented 6 years ago

Please change the line to :

get the names of all snapshots sorted from old to new

SnapshotNames=$(aws lightsail get-instance-snapshots | jq '.instanceSnapshots | sort_by(.createdAt) | .[] | select(.fromInstanceName == "'${NameOfYourInstance}'") | . name') It works well for me.

maherber commented 6 years ago

didn't work for me but after checking with jqplay.org the following version works for me: SnapshotNames=$(aws lightsail get-instance-snapshots | jq '.instanceSnapshots | sort_by(.createdAt) | .[] | select (.fromInstanceName == "'${NameOfYourInstance}'")| .name')

the difference is no blank between "." and 'name'