Created
August 2, 2023 19:26
-
-
Save RobinBoers/0f3753d66c41e5a568f2c71480f721ae to your computer and use it in GitHub Desktop.
Simple script to migrate the contents of a Google Cloud Storage bucket to a bunny.net Storage Zone.
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/sh | |
# Script to copy files from GCS bucket to Bunny(.net) Storage. | |
# This script assumes you're logged into the `gcloud` cli, and | |
# that all the files are at the top-level of the bucket and/or zone. | |
# Usage: | |
# ./copy.sh <BUCKET> <ZONE> <PASSWORD> [FLAGS] | |
# Arguments: | |
# $1: GCS bucket ID | |
# The part after `gs://` | |
# Example: qdentity-demo | |
# | |
# $2: Bunny Storage Zone ID | |
# Example: qdentity-demo | |
# | |
# $3: Bunny Storage Zone password | |
# Can be found in Storage -> [Your zone] -> FTP & API Access -> Password -> Password | |
# Flags: | |
# -d: delete temporary directory | |
mkdir temp | |
cd temp | |
gsutil -m cp gs://$1/\* ./ | |
for file in * | |
do | |
if [[ $file != "copy.sh" ]]; then | |
echo "Uploading $file to https://storage.bunnycdn.com/$2/./$file" | |
curl --request PUT \ | |
--url "https://storage.bunnycdn.com/$2/./$file" \ | |
--header "AccessKey: $3" \ | |
--header 'content-type: application/octet-stream' \ | |
--data "@$file" | |
echo "" | |
fi | |
done | |
cd .. | |
while getopts d: flag | |
do | |
case "${flag}" in | |
d) rm -rf temp | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment