Skip to content

Instantly share code, notes, and snippets.

@varqox
Last active October 12, 2021 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varqox/4b2e43aaa8c7714d563049271f96b0da to your computer and use it in GitHub Desktop.
Save varqox/4b2e43aaa8c7714d563049271f96b0da to your computer and use it in GitHub Desktop.
Backup script (copy it to root directory of your project and run it every time you want to make a backup)
#!/bin/sh
set -e
cd -P -- "$(dirname -- "$0")" # chdir to script directory
out_file="$HOME/backup/$(echo ${PWD#$HOME/} | sed 's@/@,@g').tar.zst"
((git ls-files -z --cached --recurse-submodules 2> /dev/null &&
git ls-files -z --others --exclude-standard &&
PROJECT_DIR=$PWD git submodule foreach --quiet 'git ls-files -z -o --exclude-standard | while read -d "" x; do echo -n "${PWD#$PROJECT_DIR/}/$x"; echo -ne "\0"; done' &&
echo -ne '.git\0'
) || ls --zero -A) | \
xargs --null tar --create --zst --file "$out_file"
du -sh "$out_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment