Created
February 9, 2023 16:37
-
-
Save sumansrivastava/8808652c0fecb96fe84023c138148089 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # Set the name of the namespace | |
| namespace="my-namespace" | |
| # Create a backup directory | |
| backup_dir="pdb-backup-$(date +%s)" | |
| mkdir $backup_dir | |
| # Get the names of all PDBs in the namespace | |
| pdb_list=$(kubectl get pdb -n $namespace -o jsonpath='{.items[*].metadata.name}') | |
| # Loop through the PDBs and backup their deployments and services | |
| for pdb in $pdb_list; do | |
| # Get the name of the deployment associated with the PDB | |
| deployment=$(kubectl get pdb $pdb -n $namespace -o jsonpath='{.spec.selector.matchLabels.app}') | |
| # Backup the deployment and its associated services | |
| kubectl get deployment $deployment -n $namespace -o yaml > $backup_dir/$deployment.yaml | |
| kubectl get service -l app=$deployment -n $namespace -o yaml > $backup_dir/$deployment-services.yaml | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment