Created
October 20, 2021 13:06
-
-
Save criess/99221224583af8176c3f50b6fdb01d7f to your computer and use it in GitHub Desktop.
This file contains 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 | |
## | |
# 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