Skip to content

Instantly share code, notes, and snippets.

@Praveenrajmani
Last active November 9, 2023 07:06
Show Gist options
  • Save Praveenrajmani/f5e65f04fcb5b6d5a5cb8eb5bd078047 to your computer and use it in GitHub Desktop.
Save Praveenrajmani/f5e65f04fcb5b6d5a5cb8eb5bd078047 to your computer and use it in GitHub Desktop.
Backup and restoring MinIO resources

STEP 1: Take backups

export NAMESPACE=<your-tenant-namespace>
kubectl get directpvvolumes -o yaml > directpvvolumes.yaml
kubectl get directpvdrives -o yaml > directpvdrives.yaml
kubectl get ns $NAMESPACE -o yaml > tenantns.yaml
kubectl get pv -o yaml > pvs.yaml           	 
kubectl get pvc -n $NAMESPACE -o yaml > pvcs.yaml
kubectl get tenants -n $NAMESPACE -o yaml > tenant.yaml
kubectl get sts -n $NAMESPACE -o yaml > tenantsts.yaml
kubectl get secrets -n $NAMESPACE -o yaml > tenantsecrets.yaml

STEP 2: Delete and recreate the cluster

STEP 3: Install DirectPV and operator

STEP 4: Restore the backup

# applying directpv backups
kubectl apply -f directpvdrives.yaml
kubectl apply -f directpvvolumes.yaml

# restarting directpv after backing up directpv objects
kubectl delete pods -n directpv --all

# applying tenant backups and resources
kubectl apply -f tenantns.yaml
kubectl apply -f pvs.yaml
kubectl apply -f pvcs.yaml
kubectl apply -f tenantsts.yaml
kubectl apply -f tenant.yaml
kubectl apply -f tenantsecrets.yaml

STEP 5: Patch the PVs

(NOTE: Before patching, the PVs will be in "Released" state and PVCs will be in "Lost" state)

kubectl get pv -o custom-columns=NAME:.metadata.name --no-headers | while read -r resource_name; do
        kubectl patch pv "${resource_name}" -p '{"spec":{"claimRef": null}}' --type=merge
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment