Skip to main content

macos/exclude_from_backblaze

1#!/usr/bin/env bash
3set -o errexit
4set -o nounset
6if (( $# != 1 )); then
7 echo "Usage: $0 <path_to_directory>" >&2
8 exit 1
9fi
11INPUT_PATH="$1"
12BZCLI_PATH="/Applications/Backblaze.app/Contents/MacOS/bzcli"
14# If Backblaze isn't installed, we can assume this device isn't backed
15# up with Backblaze and no-op this operation.
16if [ ! -x "$BZCLI_PATH" ]; then
17 exit 0
18fi
20# Resolve relative paths to absolute paths.
21if [[ "$INPUT_PATH" = /* ]]; then
22 TARGET_DIR="$INPUT_PATH"
23else
24 TARGET_DIR="$PWD/$INPUT_PATH"
25fi
27# Create a temporary JSON file with the following structure:
29# {
30# "settings": {
31# "bzdirfilter_add": [
32# {
33# "dir": "/Users/alexwlchan/repos/chives/.venv/",
34# "whichfiles": "none"
35# }
36# ]
37# }
38# }
40TEMP_JSON=$(mktemp)
41trap 'rm -f "$TEMP_JSON"' EXIT
43if ! jq -n \
44 --arg dir "$TARGET_DIR" \
45 '{settings: {bzdirfilter_add: [{dir: $dir, whichfiles: "none"}]}}' \
46 > "$TEMP_JSON"; then
47 echo "Error: Failed to generate temporary JSON configuration." >&2
48 exit 1
49fi
51echo "Applying Backblaze exclusion for: $TARGET_DIR"
53if ! "$BZCLI_PATH" configure -j "$TEMP_JSON"; then
54 echo "Error: bzcli configuration failed." >&2
55 exit 1
56fi