Last active
October 12, 2021 15:26
-
-
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)
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/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