Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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"
echo "⚠️ ⚠️ ⚠️ $filepath is not valid ⚠️ ⚠️ ⚠️ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment