Skip to content

Instantly share code, notes, and snippets.

@criess
Created October 20, 2021 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criess/99221224583af8176c3f50b6fdb01d7f to your computer and use it in GitHub Desktop.
Save criess/99221224583af8176c3f50b6fdb01d7f to your computer and use it in GitHub Desktop.
#!/bin/bash
##
# uses this env:
# REMOTE_BUCKET: gcs bucket adress prefix (can include foldername)
# FILENAME_PREFIX: Filename prefix (prefix on basename)
LOCAL_LS="$(tempfile)"
REMOTE_LS="$(tempfile)"
gsutil ls "$REMOTE_BUCKET$FILENAME_PREFIX*" | cut -d "/" -f5 > "$REMOTE_LS"
ls | grep "$FILENAME_PREFIX" > "$LOCAL_LS"
for FILE in $(diff -u "$REMOTE_LS" "$LOCAL_LS" | grep -E "^\+[^\+]" | cut -c 2-); do
echo "upload $FILE"
gsutil cp "$FILE" "$REMOTE_BUCKET"
done
for FILE in $(diff -u "$REMOTE_LS" "$LOCAL_LS" | grep -E "^-[^-]" | cut -c 2-); do
echo "remove $FILE"
gsutil rm "$REMOTE_BUCKET$FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment