Skip to content

Instantly share code, notes, and snippets.

@shikharbhardwaj
Created May 11, 2024 12:34
Show Gist options
  • Save shikharbhardwaj/c7361f7a0015255388148b8f5ef6204b to your computer and use it in GitHub Desktop.
Save shikharbhardwaj/c7361f7a0015255388148b8f5ef6204b to your computer and use it in GitHub Desktop.
democratic-csi PV parent dataset migration
#!/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
#!/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