Script to cleanup etcd fleet hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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