Skip to content

Instantly share code, notes, and snippets.

@rajannpatel
Last active October 16, 2019 01:20
Show Gist options
  • Save rajannpatel/63bbc6aada41e0534ae5d09a098d0be7 to your computer and use it in GitHub Desktop.
Save rajannpatel/63bbc6aada41e0534ae5d09a098d0be7 to your computer and use it in GitHub Desktop.
rsync to google cloud storage with gsutil in a short and simple bash script, which takes an array of local directories as the source
#!/usr/bin/env bash
bucket=name-of-your-bucket
dirs=(
~/relative/path
../relative/path2
/absolute/path/
/Volumes/Macintosh HD/full/absolute/path
)
for dir in ${dirs[@]}
do
path="$(cd "$(dirname "${dir}")"; pwd)/$(basename "${dir}")"
# absolute path solution: https://stackoverflow.com/a/31605674/3700104
echo ${path} && gsutil -m rsync -e -r -d "${path}" "gs://${bucket}${path}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment