Last active
February 14, 2026 13:32
-
-
Save Terrance/d4bdf7435d0c78f5b687daec32abd77f to your computer and use it in GitHub Desktop.
Script to detect additive-only backup files and remove redundant copies.
This file contains hidden or 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
| #!/usr/bin/env sh | |
| trap 'rm -f "$TMPDIR"/*.addonly' INT EXIT | |
| last= | |
| lastf= | |
| for curr; do | |
| prev="$last" | |
| last="$curr" | |
| >&2 echo -n "$curr " | |
| if [ "$FILTER" = "" ]; then | |
| currf="$curr" | |
| else | |
| currf="$(mktemp --suffix=.addonly)" | |
| <"$curr" $FILTER >"$currf" | |
| echo -n "[$(wc -l "$currf")] " | |
| fi | |
| prevf="$lastf" | |
| lastf="$currf" | |
| if [ "$prev" = "" ]; then | |
| >&2 echo "(initial)" | |
| continue | |
| fi | |
| line=$("${GIT:=git}" diff --no-index --numstat "$prevf" "$currf" 2>/dev/null) | |
| adds=$(echo $line | awk '{ print $1 }') | |
| dels=$(echo $line | awk '{ print $2 }') | |
| >&2 echo "(+$adds -$dels)" | |
| if [ $dels -eq 0 ] && [ $adds -gt 0 ]; then | |
| echo "rm '$prev'" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment