Created
October 12, 2020 04:55
-
-
Save flouthoc/8c1cb98436607d0cfaedebb9476f4e97 to your computer and use it in GitHub Desktop.
velero_az_replace.sh
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
export PROJECT_NAME=yourvalueshere | |
export BACKUP_NAME=yourvalueshere | |
export BUCKET_NAME=yourvalueshere | |
export OLD_REGION=yourvalueshere | |
export OLD_ZONE=yourvalueshere | |
export NEW_REGION=yourvalueshere | |
export NEW_ZONE=yourvalueshere | |
gcloud config set project "$PROJECT_NAME" | |
mkdir fix | |
cd fix | |
# Volume snapshots | |
gsutil cp gs://$BUCKET_NAME/backups/$BACKUP_NAME/$BACKUP_NAME-volumesnapshots.json.gz . | |
gunzip $BACKUP_NAME-volumesnapshots.json.gz | |
sed -i "s/$OLD_ZONE/$NEW_ZONE/g" $BACKUP_NAME-volumesnapshots.json | |
sed -i "s/$OLD_REGION/$NEW_REGION/g" $BACKUP_NAME-volumesnapshots.json | |
gzip $BACKUP_NAME-volumesnapshots.json | |
# Bigger file | |
gsutil cp gs://$BUCKET_NAME/backups/$BACKUP_NAME/$BACKUP_NAME.tar.gz . | |
mkdir $BACKUP_NAME-temp | |
tar xzf $BACKUP_NAME.tar.gz -C $BACKUP_NAME-temp | |
cd $BACKUP_NAME-temp | |
find . -name \*.json -exec sh -c "sed -i 's/$OLD_ZONE/$NEW_ZONE/g' {}" \; | |
find . -name \*.json -exec sh -c "sed -i 's/$OLD_REGION/$NEW_REGION/g' {}" \; | |
tar czf ../$BACKUP_NAME.tar.gz * | |
gsutil cp ../$BACKUP_NAME.tar.gz gs://$BUCKET_NAME/backups/$BACKUP_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment