Created
March 27, 2023 02:52
-
-
Save jmhublar/01b76b4b51117120ea67cdf9a25fda50 to your computer and use it in GitHub Desktop.
A little script to ease the pain of restoring pulsar pvcs
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 source and destination folders | |
SOURCE_FOLDER="/efs-new/aws-backup-restore_2023-03-27T00-28-30-414788Z/csi/" | |
DESTINATION_FOLDER="/efs-new/csi/" | |
DRY_RUN=false | |
if [ "$1" == "--dry-run" ]; then | |
DRY_RUN=true | |
fi | |
# Broker PVC recovery | |
echo "Starting Bookie PVC recovery..." | |
for restored_pvc in $(find $SOURCE_FOLDER -type d -name "pvc-*" -exec basename {} \;); do | |
if [ -f "${SOURCE_FOLDER}${restored_pvc}/current/VERSION" ]; then | |
bookie_host=$(grep -oP '(?<=bookieHost: ").*(?=")' ${SOURCE_FOLDER}${restored_pvc}/current/VERSION) | |
for dest_pvc in $(find $DESTINATION_FOLDER -type d -name "pvc-*" -exec basename {} \;); do | |
if [ -f "${DESTINATION_FOLDER}${dest_pvc}/current/VERSION" ]; then | |
current_bookie_host=$(grep -oP '(?<=bookieHost: ").*(?=")' ${DESTINATION_FOLDER}${dest_pvc}/current/VERSION) | |
if [ "$bookie_host" == "$current_bookie_host" ]; then | |
echo "Restoring Bookie PVC: $restored_pvc to $dest_pvc" | |
if [ "$DRY_RUN" = false ]; then | |
rsync -a --chown=$(stat -c '%u:%g' ${DESTINATION_FOLDER}${dest_pvc}) ${SOURCE_FOLDER}${restored_pvc}/ ${DESTINATION_FOLDER}${dest_pvc}/ | |
fi | |
fi | |
fi | |
done | |
fi | |
done | |
# Zookeeper PVC recovery | |
echo "Starting Zookeeper PVC recovery..." | |
for restored_pvc in $(find $SOURCE_FOLDER -type d -name "pvc-*" -exec basename {} \;); do | |
if [ -f "${SOURCE_FOLDER}${restored_pvc}/zookeeper/myid" ]; then | |
zookeeper_id=$(cat ${SOURCE_FOLDER}${restored_pvc}/zookeeper/myid) | |
for dest_pvc in $(find $DESTINATION_FOLDER -type d -name "pvc-*" -exec basename {} \;); do | |
if [ -f "${DESTINATION_FOLDER}${dest_pvc}/zookeeper/myid" ]; then | |
current_zookeeper_id=$(cat ${DESTINATION_FOLDER}${dest_pvc}/zookeeper/myid) | |
if [ "$zookeeper_id" == "$current_zookeeper_id" ]; then | |
echo "Restoring Zookeeper PVC: $restored_pvc to $dest_pvc" | |
if [ "$DRY_RUN" = false ]; then | |
rsync -a --chown=$(stat -c '%u:%g' ${DESTINATION_FOLDER}${dest_pvc}) ${SOURCE_FOLDER}${restored_pvc}/ ${DESTINATION_FOLDER}${dest_pvc}/ | |
fi | |
fi | |
fi | |
done | |
fi | |
done | |
if [ "$DRY_RUN" = true ]; then | |
echo "Dry run completed. No files were actually copied." | |
else | |
echo "PVC recovery completed!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment