Created
May 11, 2024 12:34
-
-
Save shikharbhardwaj/c7361f7a0015255388148b8f5ef6204b to your computer and use it in GitHub Desktop.
democratic-csi PV parent dataset migration
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 | |
storageclass_name="..." | |
kubectl get pvc -A --output=json | jq -r '.items[] | select(.spec.storageClassName == "${storageclass_name}") | [.metadata.namespace, .metadata.name, .spec.volumeName] | @tsv' > pvc-list.txt |
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 | |
# Set the source and destination ZFS datasets | |
source_dataset="..." | |
destination_dataset="..." | |
# Source snapshot name, created with a command like | |
# zfs snap -r <source_pool>@<snapshot_name> | |
snapshot_name="..." | |
# Read each line from the input file | |
while IFS=$'\t' read -r namespace pv pvc; do | |
# Extract relevant parts from the input line | |
namespace="${namespace// /}" # Trim any extra spaces | |
pvc="${pvc// /}" # Trim any extra spaces | |
pv="${pv// /}" # Trim any extra spaces | |
# Formulate the ZFS send and receive command | |
send_command="zfs send ${source_dataset}/${pvc}@${snapshot_name}" | |
recv_command="zfs recv ${destination_dataset}/${namespace}-${pv}" | |
# Execute the ZFS send | ZFS recv command | |
echo "Executing: $send_command | $recv_command" | |
# Uncomment to run the migration | |
# $send_command | $recv_command | |
# Check the exit status of the previous command | |
if [ $? -ne 0 ]; then | |
echo "Error executing ZFS send | recv for ${pvc}" | |
fi | |
done < pvc-list.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment