Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
Last active June 15, 2021 21:25
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 rattrayalex/9ff731a9322c0614d48a6a6b1d913bd3 to your computer and use it in GitHub Desktop.
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
# 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