From 9f3db5fe030d4042093d6ad74c544f18000f6b11 Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Mon, 10 Aug 2020 12:13:31 +0200 Subject: [PATCH] added the borg.sh shell script --- salt/states/files/borg.sh | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 salt/states/files/borg.sh diff --git a/salt/states/files/borg.sh b/salt/states/files/borg.sh new file mode 100755 index 0000000..89d3619 --- /dev/null +++ b/salt/states/files/borg.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +[[ ! -f "$HOME/.borgbackup.env" ]] && printf "\$HOME/.borgbackup.env doesn't exist!\n" && exit 1 + +if [[ "$(stat -c %A $HOME/.borgbackup.env)" != "-rw-------" ]]; then + printf "WARNING!!!! \$HOME/.borgbackup.env has the wrong permissions!\n" + printf "\nrun : chmod 0600 \$HOME/.borgbackup.env\n" + exit 1 +fi + +source "$HOME/.borgbackup.env" + +info "Starting backup" + +# Backup the most important directories into an archive named after +# the machine this script is currently running on: + +borg create \ + --verbose \ + --filter AME \ + --list \ + --stats \ + --show-rc \ + --compression lz4 \ + --exclude-caches \ +--exclude '/var/cache/*' \ +--exclude '/var/tmp/*' \ +--exclude '/*/lost\+found/*' \ +--exclude '/home/*/.cache/*' \ +--exclude '/home/*/go/*' \ +--exclude '/home/*/.wine/*' \ +--exclude '/home/*/snap/*' \ +--exclude '/home/*/Downloads/*' \ +--exclude '/home/*/Nextcloud/*' \ +--exclude '/home/*/.config/Rocket.Chat/Cache//*' \ +--exclude '/home/*/.config/discord/Cache/*' \ +--exclude '/home/*/.mozilla/firefox/*/Cache/*' \ +--exclude '/home/*/.mozilla/firefox/*/minidumps/*' \ +--exclude '/home/*/.mozilla/firefox/*/extensions.sqlite' \ +--exclude '/home/*/.mozilla/firefox/*/urlclassifier3.sqlite' \ +--exclude '/home/*/.config/google-chrome/Default/Local Storage/*' \ +--exclude '/home/*/.config/google-chrome/Default/Session Storage/*' \ +--exclude '/home/*/.config/google-chrome/Default/Application Cache/*' \ +--exclude '/home/*/.config/google-chrome/Default/History/*' \ +--exclude '/home/*/.config/google-chrome/Default/History-journal/*' \ +--exclude '/home/*/.config/google-chrome/Default/History Provider Cache/*' \ +--exclude '/home/*/.local/share/flatpak/*' \ +--exclude '/home/*/.local/share/virtualenv/*' \ +--exclude '/home/*/.local/share/virtualenvs/*' \ +::'{hostname}-{now}' \ +/home \ + + +backup_exit=$? + +info "Pruning repository" + +# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly +# archives of THIS machine. The '{hostname}-' prefix is very important to +# limit prune's operation to this machine's archives and not apply to +# other machines' archives also: + +borg prune \ + --list \ + --prefix '{hostname}-' \ + --show-rc \ + --keep-daily 14 \ + --keep-weekly 8 \ + --keep-monthly 6 \ + +prune_exit=$?