backstep-traceback-auto 2.82 KB
Newer Older
1
#!/bin/bash
Nigel Kukard's avatar
Nigel Kukard committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# backstep-traceback-auto - Automatic backup script using backstep-traceback
# Copyright (c) 2010-2017, AllWorldIT
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 18 19

#set -e -x

Robert Spencer's avatar
Robert Spencer committed
20 21 22 23 24 25 26 27 28 29 30
function show_help {
	cat <<-EOF
	$0 [-hv] [-o lv-name] [daily|weekly]

	-h	Show this help.
	-v	Show verbose debug information & set debug options.
	-o	Only do a backup of the specified lv.

EOF
}

Robert Spencer's avatar
Robert Spencer committed
31 32
export PATH="$PATH:/sbin:/usr/sbin"

Robert Spencer's avatar
Robert Spencer committed
33 34
# Parse options
OPTIND=1
Robert Spencer's avatar
Robert Spencer committed
35
while getopts ":ho:v" OPTION
36 37
do
	case "$OPTION" in
Robert Spencer's avatar
Robert Spencer committed
38 39 40 41
		h)
			show_help
			exit 0
		;;
42 43 44 45 46 47 48 49
		o)
			ONLY="$OPTARG"
		;;
		v)
			VERBOSE="true"
		;;
	esac
done
Robert Spencer's avatar
Robert Spencer committed
50 51 52
# Remove option from parameters
shift $(expr $OPTIND - 1)

53
if [ -n "$1" ]
Robert Spencer's avatar
Robert Spencer committed
54 55
then
	PERIOD="$1"
56 57 58
else
	echo "ERROR: You need to specify a period [daily or weekly]."
	exit 1
Robert Spencer's avatar
Robert Spencer committed
59 60
fi

61 62 63 64 65 66 67 68
if [ -e /etc/backstep-traceback/${PERIOD}.conf ]
then
	source /etc/backstep-traceback/${PERIOD}.conf
else
	echo "ERROR: ${PERIOD^} backup is not configured."
	exit 1
fi

Robert Spencer's avatar
Robert Spencer committed
69
# Change sync options for when we are debugging
70
if [ "$VERBOSE" = "true" ]
71
then
72
	syncopts="--debug --max-load=$DEBUG_MAX_LOAD"
73 74
	set -ex
else
75
	syncopts="--max-load=$MAX_LOAD --quiet --bwlimit=$BWLIMIT"
76 77 78
fi

# Loop with all LVS
79
for LV in "${BACKUP_LVS[@]}"
80
do
81 82 83 84 85
	if [ -n "$ONLY" ] && [ "$ONLY" != "$LV" ]
	then
		continue
	fi

86 87 88
	OLD_IFS="$IFS"
	IFS=','

89
	read -a ITEMS -r <<< "$LV"
90 91 92

	IFS="$OLD_IFS"
	BIND_MOUNT_ARGS=()
93
	LVM_SNAPSHOT_ARGS=()
94 95 96

	for ITEM in "${ITEMS[@]}"
	do
97
		case "$ITEM" in
98 99 100 101 102 103
			/*)
				BIND_MOUNT_ARGS+=("--bind-mount")
				BIND_MOUNT_ARGS+=("$ITEM:$ITEM")
			;;
			*)
				LVM_SNAPSHOT_ARGS+=("--lvm-snapshot")
104
				LVM_SNAPSHOT_ARGS+=("lvm-raid/$ITEM")
105 106
			;;
		esac
107 108
	done

109 110 111
	lv=${LVM_SNAPSHOT_ARGS[1]#*/}
	vg=${LVM_SNAPSHOT_ARGS[1]%/*}

112 113 114 115 116 117
	if [ "${#LVM_SNAPSHOT_ARGS[@]}" -gt "2" ]
	then
		ZABBIX_ITEM="$PERIOD"
	else
		ZABBIX_ITEM="$lv,$PERIOD"
	fi
118

Robert Spencer's avatar
Robert Spencer committed
119
	# Backup to $PERIOD-$vg-$lv ...
120
	backstep-traceback --backup \
121 122 123 124
		--acl \
		--safe \
		--deltas \
		--create-timestamp-file \
125
		--copy-backup-filter \
126
		--prepend-backup-filter \
127
		"${LVM_SNAPSHOT_ARGS[@]}" \
128
		"${BIND_MOUNT_ARGS[@]}" \
129
		--email-subject "${PERIOD^^} $lv" \
130
		--email="$REPORT_EMAIL" \
131 132
		--port "$SERVER_PORT" --pubkey "$SERVER_KEY" \
		$syncopts \
133
		--zabbix "$ZABBIX_ITEM" --zabbix-config "$ZABBIX_CONFIG" \
134
		"$SERVER_USER"@"$SERVER_HOST"::"$SERVER_PATH"/"$PERIOD-$vg-$lv"
135
done