Skip to content

Instantly share code, notes, and snippets.

@hectorj2f
Created October 29, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hectorj2f/f44f415624b5a7d75432 to your computer and use it in GitHub Desktop.
Save hectorj2f/f44f415624b5a7d75432 to your computer and use it in GitHub Desktop.
Script to cleanup etcd fleet hashes
#!/bin/bash
DIR="/tmp/cleanup_fleet_keys"
mkdir -p ${DIR}
echo "Fetching etcd keys from fleet /_coreos.com/fleet/unit "
cat <(etcdctl ls --recursive /_coreos.com/fleet/unit| awk -F\/ '{print $NF}') <(fleetctl list-unit-files -full -fields=hash -no-legend) | sort | uniq -u > ${DIR}/etcd_fleet_keys_one
echo "Waiting 10 seconds to collect the keys one more time..."
sleep 10
echo "Fetching etcd keys from fleet to be sure deleting the right keys"
cat <(etcdctl ls --recursive /_coreos.com/fleet/unit| awk -F\/ '{print $NF}') <(fleetctl list-unit-files -full -fields=hash -no-legend) | sort | uniq -u > ${DIR}/etcd_fleet_keys_two
echo "Fetched keys twice... merging now (this operation can take quite a lot of time.. be Patience and smile! )"
cat ${DIR}/etcd_fleet_keys_one | grep -f ${DIR}/etcd_fleet_keys_two > ${DIR}/etcd_fleet_keys
echo "Instersecction between the two files is done!!"
NUM_KEYS=$(cat ${DIR}/etcd_fleet_keys | wc -l)
echo "After intersection, we have ${NUM_KEYS} etcd fleet hashes keys to remove"
cat ${DIR}/etcd_fleet_keys | sort | awk '{print "/_coreos.com/fleet/unit/" $1}' | xargs -n1 -P50 etcdctl rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment