Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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