Created
June 5, 2025 13:03
-
-
Save thebiss/bf376d756abbc54261f78d990744a73d to your computer and use it in GitHub Desktop.
Backup a development tree to a compressed tar, ignoring cache dirs.
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
#!/bin/bash | |
_backupdir='./dev' | |
_now=`date -Isec | tr -d "\:"` | |
_archive="./dev.${_now}.tgz" | |
# WSL2-ism to free disk cache | |
echo 1 | sudo tee /proc/sys/vm/drop_caches > /dev/null | |
t=$(mktemp -t ) || exit | |
trap "rm -f -- '$t'" EXIT | |
# https://bford.info/cachedir/ | |
cat << EOF >> "${t}" | |
Signature: 8a477f597d28d172789f06886806bc55 | |
EOF | |
# tag any cache dirs | |
find "${_backupdir}" \( -name 'node_modules' -o -name '.venv' \) -type d -readable -executable -exec cp "${t}" "{}/CACHEDIR.TAG" \; -print | sed 's/^\(.*\)/Marking as cache: \1/' | |
tar --exclude-caches-under --ignore-failed-read --exclude="*.qcow*" --exclude "*.vhdx*" --exclude "*.gguf" -cvzf "${_archive}" "${_backupdir}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment