~rycwo/workspace

167a47b26a9b3375657eb1c825be90cef229d6b3 — Ryan Chan 7 months ago a255d55
Update backup-host script to include system files
1 files changed, 32 insertions(+), 38 deletions(-)

M bin/backup-host
M bin/backup-host => bin/backup-host +32 -38
@@ 19,50 19,44 @@ fi

export BORG_REMOTE_PATH="borg1"
export BORG_REPO="zh1117@zh1117.rsync.net:""$(hostname)"
export BORG_PASSCOMMAND="cat ""$HOME""/.borg-passphrase"

readonly paths=(
    "/home/rycwo"
)
readonly exclude_paths=(
    "/home/rycwo/.borg-passphrase"
    "/home/rycwo/.cache"
    "/home/rycwo/.mozilla"
    "/home/rycwo/.secret"
    "/home/rycwo/.vagrant.d"
    "/home/rycwo/.virtualbox"
    "/home/rycwo/go")
exclude_file="$(mktemp)"
export BORG_PASSCOMMAND="cat ""$HOME""/.borg_passphrase"

exit_() {
    status="$?"

    # Reset the trap for EXIT so that we don't enter an exit loop
    trap - EXIT

    rm -f "$exclude_file"
    exit "$status"
    echo "$(date)"" Backup interrupted" >&2
    exit 2
}

trap exit_ EXIT INT TERM QUIT
trap exit_ INT TERM

# Run borg init if the repo doesn't exist yet
borg list > /dev/null 2>&1 || {
    borg init --encryption "repokey"
}

for path in "${exclude_paths[@]}"; do
    echo "$path" >> "$exclude_file"
done

# --stats is a nice option if just running as a script
borg create \
    --verbose \
    --filter AME \
    --list \
    --progress \
    --compression "lzma" \
    --exclude-caches \
    --exclude-from "$exclude_file" \
    "::{hostname}-{now}" \
    "${paths[@]}"
borg create                     \
    --verbose                   \
    --filter AME                \
    --list                      \
    --show-rc                   \
    --stats                     \
    --progress                  \
    --compression "lzma"        \
    --exclude-caches            \
    --exclude "home/*/.cache/*" \
    --exclude "var/tmp/*"       \
    "::{hostname}-{now}"        \
    /etc                        \
    /home                       \
    /root                       \
    /var

# Keep 7 end of day, 4 additional end of week archives,
# and an end of month archive for every month
borg prune                      \
    --list                      \
    --prefix "{hostname}-"      \
    --show-rc                   \
    --keep-daily 7              \
    --keep-weekly 4             \
    --keep-monthly -1

borg compact