Skip to content

Instantly share code, notes, and snippets.

@varqox
Last active October 12, 2021 15:26
Show Gist options
  • Save varqox/4b2e43aaa8c7714d563049271f96b0da to your computer and use it in GitHub Desktop.
Save varqox/4b2e43aaa8c7714d563049271f96b0da to your computer and use it in GitHub Desktop.

Revisions

  1. varqox revised this gist Oct 12, 2021. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions backup
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,11 @@ cd -P -- "$(dirname -- "$0")" # chdir to script directory

    out_file="$HOME/backup/$(echo ${PWD#$HOME/} | sed 's@/@,@g').tar.zst"

    ((git ls-files --cached --recurse-submodules 2> /dev/null &&
    git ls-files --others --exclude-standard &&
    PROJECT_DIR=$PWD git submodule foreach --quiet 'git ls-files -o --exclude-standard | while read x; do echo "${PWD#$PROJECT_DIR/}/$x"; done' &&
    echo .git
    ) || ls -A) | \
    xargs tar c --zst -f "$out_file"
    ((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"
  2. varqox created this gist Oct 1, 2021.
    15 changes: 15 additions & 0 deletions backup
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/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 --cached --recurse-submodules 2> /dev/null &&
    git ls-files --others --exclude-standard &&
    PROJECT_DIR=$PWD git submodule foreach --quiet 'git ls-files -o --exclude-standard | while read x; do echo "${PWD#$PROJECT_DIR/}/$x"; done' &&
    echo .git
    ) || ls -A) | \
    xargs tar c --zst -f "$out_file"
    du -sh "$out_file"