Last active
June 15, 2021 21:25
-
-
Save rattrayalex/9ff731a9322c0614d48a6a6b1d913bd3 to your computer and use it in GitHub Desktop.
Upload a list of files and directories to b2 backblaze, and then delete them, with a single bash command
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
# usage: | |
# | |
# export BUCKET='my-bucket-name' | |
# b2-archive-files myfile mydirectory myotherfile | |
# | |
# You can find large files in a directory with "du -ahx . | sort -h". | |
archive() ( | |
set -eo pipefail | |
if [ -z "$BUCKET" ]; then | |
echo "missing BUCKET env var" | |
exit 1 | |
fi | |
for filepath in "$@"; do | |
if [[ -d $filepath ]]; then | |
b2 sync "$filepath" "b2://$BUCKET/$filepath" | |
rm -rf "$filepath" | |
elif [[ -f $filepath ]]; then | |
b2 upload-file "$BUCKET" "$filepath" "$filepath" | |
rm "$filepath" | |
else | |
echo "⚠️ ⚠️ ⚠️ $filepath is not valid ⚠️ ⚠️ ⚠️ " | |
fi | |
done | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment