2 ################################################
3 ### Managed by someone's ansible provisioner ###
4 ################################################
5 # Part of: https://git.somenet.org/root/pub/somesible.git
6 # 2017-2024 by someone <someone@somenet.org>
13 export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="yes"
14 export BORG_RELOCATED_REPO_ACCESS_IS_OK="yes"
17 export BKPREPO=${1} # backup repo (should be: "/bkp/storage-local/$host/$path" or for ssh: "user@server:$path")
18 export BKPHOST=${2} # src-host
19 export BKPPATH=${3} # abs-path on src-host
20 export BKPKEEP=${4} # pruning-settings
21 export BORG_PASSPHRASE=${5} # borg key passphrase
23 BKPPATH_ESCAPED=$(echo -n "$BKPPATH"|sed -e 's#/#-#g') # contains first "/"
25 if [[ -z "$BORG_PASSPHRASE" ]]; then
26 borg info "$BKPREPO" >/dev/null 2>&1 || borg init --umask 0077 -e none --make-parent-dirs "$BKPREPO"
28 borg info "$BKPREPO" >/dev/null 2>&1 || borg init --umask 0077 -e repokey-blake2 --make-parent-dirs "$BKPREPO"
31 echo "# Merged on: $(date -Isec)" > "/bkp/local/exclude.conf.d/.merged.$BKPHOST-$BKPPATH_ESCAPED"
32 for file in /bkp/local/exclude.conf.d/$BKPHOST-$BKPPATH_ESCAPED*; do
33 echo -e "\n\n# $file" >> "/bkp/local/exclude.conf.d/.merged.$BKPHOST-$BKPPATH_ESCAPED"
34 cat "$file" >> "/bkp/local/exclude.conf.d/.merged.$BKPHOST-$BKPPATH_ESCAPED"
37 borg create --umask 0077 --info --list --stats --noctime --nobirthtime --exclude-caches --exclude-from "/bkp/local/exclude.conf.d/.merged.$BKPHOST-$BKPPATH_ESCAPED" "$BKPREPO::$BKPHOST-$BKPPATH_ESCAPED--{now}" "$BKPPATH"
39 if [ $exit_status -ne 0 ]; then
40 export ERRCODE="$exit_status";
41 echo "** backup.sh (backup:create): non-zero exitcode: $exit_status"
44 backup_prune "$BKPREPO" "$BKPKEEP" "$BORG_PASSPHRASE"
48 export BKPREPO=${1} # backup repo (should be: "/bkp/storage-local/$host/$path" or for ssh: "user@server:$path")
49 export BKPNAME=${2} # backup name
50 export BKPCMD=${3} # command to run
51 export BKPKEEP=${4} # pruning-settings
52 export BORG_PASSPHRASE=${5} # borg key passphrase
54 if [[ -z "$BORG_PASSPHRASE" ]]; then
55 borg info "$BKPREPO" >/dev/null 2>&1 || borg init --umask 0077 -e none --make-parent-dirs "$BKPREPO"
57 borg info "$BKPREPO" >/dev/null 2>&1 || borg init --umask 0077 -e repokey-blake2 --make-parent-dirs "$BKPREPO"
60 borg create --umask 0077 --info --stats --noctime --nobirthtime --compression zstd --files-cache disabled --content-from-command -- "$BKPREPO::$BKPNAME--{now}" $BKPCMD
62 if [ $exit_status -ne 0 ]; then
63 export ERRCODE="$exit_status";
64 echo "** backup.sh (backup_cmd:create): non-zero exitcode: $exit_status"
67 backup_prune "$BKPREPO" "$BKPKEEP" "$BORG_PASSPHRASE"
70 function backup_prune {
71 export BKPREPO=${1} # backup repo (should be: "/bkp/storage-local/$host/$path" or for ssh: "user@server:$path")
72 export BKPKEEP=${2} # pruning-settings
73 export BORG_PASSPHRASE=${3} # borg key passphrase
75 if [[ -z "$BKPKEEP" ]]; then
76 echo "** backup.sh(backup_prune): No prune settings, skipping"
78 borg prune --umask 0077 --list --stats --save-space --keep-last 1 $BKPKEEP "$BKPREPO"
80 if [ $exit_status -ne 0 ]; then
81 export ERRCODE="$exit_status";
82 echo "** backup.sh (backup_prune:prune): non-zero exitcode: $exit_status"
84 borg compact -v --cleanup-commits "$BKPREPO"
86 if [ $exit_status -ne 0 ]; then
87 export ERRCODE="$exit_status";
88 echo "** backup.sh (backup_prune:compact): non-zero exitcode: $exit_status"
94 echo "** backup.sh: running /bkp/local/backup.conf.managed"
95 source /bkp/local/backup.conf.managed
98 if [ -e "/bkp/local/backup.conf.local" ]; then
99 echo "** backup.sh: running /bkp/local/backup.conf.local"
100 source /bkp/local/backup.conf.local
103 echo "** backup.sh: DONE"
105 unset BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK
106 unset BORG_RELOCATED_REPO_ACCESS_IS_OK