Skip to content

Instantly share code, notes, and snippets.

@shoesCodeFor
Created March 8, 2024 19:21
Show Gist options
  • Save shoesCodeFor/c01a08d3723442ce0ed0a3976b67288d to your computer and use it in GitHub Desktop.
Save shoesCodeFor/c01a08d3723442ce0ed0a3976b67288d to your computer and use it in GitHub Desktop.
Redis pods backup/killer
#!/bin/bash
# Set the namespace variable
namespace="tools"
# Get the list of pods
pods=$(kubectl get pods -n "${namespace}" -o custom-columns=:metadata.name | grep "redis-cluster")
# Check if we got the pods
if [ -z "$pods" ]; then
echo "Yo, couldn't find any pods. Exiting..."
exit 1
fi
for pod in $pods; do
echo "Located with pod: $pod"
# Execute the command in the pod
if kubectl exec -it -n "${namespace}" "${pod}" -- bash -c "cp -r /data/ /test/"; then
echo "Successfully copied /data to /test/ in $pod"
else
echo "Bummer, dude! Couldn't copy /data to /test/ in $pod"
continue # Move to the next pod without deleting this one
fi
# Delete the pod after the command execution
if kubectl -n "${namespace}" delete pod "${pod}"; then
echo "Pod $pod has been killed with fire!"
else
echo "Yikes, couldn't delete pod $pod. You might wanna check that out."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment