macos: add a script to exclude folders from Backblaze
- ID
a233bac- date
2026-11-18 19:52:28+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
1cdc6db- message
macos: add a script to exclude folders from Backblaze- changed files
3 files, 77 additions, 5 deletions
Changed files
fish_functions/venv.fish (2439 → 2569)
diff --git a/fish_functions/venv.fish b/fish_functions/venv.fish
index 4555655..415e040 100644
--- a/fish_functions/venv.fish
+++ b/fish_functions/venv.fish
@@ -46,15 +46,18 @@ function venv --description "Create and activate a new virtual environment"
append_to_file_if_not_exists ".git/info/exclude" "__pycache__"
end
- # Tell Time Machine that it doesn't need to both backing up the
- # virtualenv directory.
+ # Tell Time Machine not to back up the .venv directory.
#
# Note: this is quite slow, so we only run it if we're in my home
- # directory -- it won't get backed up otherwise.
+ # directory -- Time Machine only looks in here, so other locations
+ # are already excluded.
if string match -q "$HOME/*" "$PWD"; and [ $(uname) = "Darwin" ]
tmutil addexclusion .venv
end
-
+
+ # Tell Backblaze not to back up the .venv directory.
+ ~/repos/scripts/macos/exclude_from_backblaze .venv >/dev/null
+
# Record the path to this venv in ~/.venv_registry.
#
# This is a text file with one directory per line, which records
macos/README.md (7750 → 8132)
diff --git a/macos/README.md b/macos/README.md
index 8603394..f124c61 100644
--- a/macos/README.md
+++ b/macos/README.md
@@ -33,6 +33,10 @@ scripts = [
"description": "count the number of tabs I have open in Safari."
},
{
+ "name": "exclude_from_backblaze DIRNAME",
+ "description": "exclude a directory from being backed up by Backblaze"
+ },
+ {
"name": "ffile",
"description": "print the path to the frontmost selected item in Finder"
},
@@ -136,6 +140,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</dd>
<dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/macos/exclude_from_backblaze">
+ <code>exclude_from_backblaze DIRNAME</code>
+ </a>
+ </dt>
+ <dd>
+ exclude a directory from being backed up by Backblaze
+ </dd>
+
+ <dt>
<a href="https://github.com/alexwlchan/scripts/blob/main/macos/ffile">
<code>ffile</code>
</a>
@@ -264,4 +277,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</p>
</dd>
</dl>
-<!-- [[[end]]] (sum: HJjXQ1mrjm) -->
+<!-- [[[end]]] (sum: ajarIMC+sR) -->
macos/exclude_from_backblaze (0 → 1231)
diff --git a/macos/exclude_from_backblaze b/macos/exclude_from_backblaze
new file mode 100755
index 0000000..37ba7ef
--- /dev/null
+++ b/macos/exclude_from_backblaze
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+if (( $# != 1 )); then
+ echo "Usage: $0 <path_to_directory>" >&2
+ exit 1
+fi
+
+INPUT_PATH="$1"
+BZCLI_PATH="/Applications/Backblaze.app/Contents/MacOS/bzcli"
+
+# If Backblaze isn't installed, we can assume this device isn't backed
+# up with Backblaze and no-op this operation.
+if [ ! -x "$BZCLI_PATH" ]; then
+ exit 0
+fi
+
+# Resolve relative paths to absolute paths.
+if [[ "$INPUT_PATH" = /* ]]; then
+ TARGET_DIR="$INPUT_PATH"
+else
+ TARGET_DIR="$PWD/$INPUT_PATH"
+fi
+
+# Create a temporary JSON file with the following structure:
+#
+# {
+# "settings": {
+# "bzdirfilter_add": [
+# {
+# "dir": "/Users/alexwlchan/repos/chives/.venv/",
+# "whichfiles": "none"
+# }
+# ]
+# }
+# }
+#
+TEMP_JSON=$(mktemp)
+trap 'rm -f "$TEMP_JSON"' EXIT
+
+if ! jq -n \
+ --arg dir "$TARGET_DIR" \
+ '{settings: {bzdirfilter_add: [{dir: $dir, whichfiles: "none"}]}}' \
+ > "$TEMP_JSON"; then
+ echo "Error: Failed to generate temporary JSON configuration." >&2
+ exit 1
+fi
+
+echo "Applying Backblaze exclusion for: $TARGET_DIR"
+
+if ! "$BZCLI_PATH" configure -j "$TEMP_JSON"; then
+ echo "Error: bzcli configuration failed." >&2
+ exit 1
+fi