summaryrefslogtreecommitdiff
path: root/borg-family-0.2/src/sbin/bfrun
blob: b0f80dd0e14034179214a88636575313aa40dff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
for e in bfenv bfenv2
do
	source $e
	bfwhat | while IFS=' ' read -r mpe dev; do
		mp=$(echo -e "$mpe")              # mp: interpret escapings that may be present in /proc/mounts (\040 for space...)
		name=${mp// /_};                  # name: replace space by underscore
		name=${mp//\//-}; name=${name/-/} # name: replace slash by dash, remove the leading one
		if [[ "$mp $name $dev" =~ "--" || "$mp $name $dev" =~ ".." || "$mp $name $dev" =~ "[|&;()<>]" ]]; then
			echo "Skipping $mpe because of shell unsafe characters" >&2
			continue
		fi

		comment=$(blkid -- "$dev")
		if [ -r "/etc/borg-family/excludes.d/$name" ]; then
			runtime_args=( --comment="$comment" --exclude-from="/etc/borg-family/excludes.d/$name" )
		else	
			runtime_args=( --comment="$comment" )
		fi

		bfhooks before "$name" && \
		borg create "${runtime_args[@]}" "${borg_create_opts[@]}" "::{hostname}-$name-{now:%Y-%m-%d}" "$mp"
		rc1=$?
		bfhooks after "$name"
		rc2=$?
		if [ "$rc1" -ne 0 -o "$rc2" -ne 0 ]; then
			echo "Errors during $name backup, return codes $rc1 (bfhook before && borg create) and $rc2 (bfhook after)" >&2
		else
			[ "x$quiet" == "x1" ] || echo "Success for $name backup"
		fi
	done
done