Initial commit
Benjamin Renard

Benjamin Renard commited on 2012-03-22 16:44:14
Showing 2 changed files, with 104 additions and 0 deletions.

... ...
@@ -0,0 +1,54 @@
1
+#!/bin/bash
2
+
3
+BCKP_BIN=/usr/local/sbin/run-backup
4
+BCKP_DIR=/var/lib/backuppc/pc
5
+
6
+TYPE=$1
7
+DEBUG=0
8
+[ "$2" == "-d" ] && DEBUG=1
9
+
10
+function usage() {
11
+	[ -n "$1" ] && echo "[ERROR] $1" > /dev/stderr && echo
12
+	echo "usage : $0 [incr|FULL] [-d]"
13
+	[ -n "$1" ] && exit 1 || exit 0
14
+}
15
+
16
+[ ! -n "$TYPE" ] && TYPE=full
17
+
18
+if [ "$TYPE" == "incr" -o "$TYPE" == "INCR" ]
19
+then
20
+	ttype="incr"
21
+elif [ "$TYPE" == "full" -o "$TYPE" == "FULL" ]
22
+then
23
+	ttype="full"
24
+else
25
+	usage "backup type not recognized (valid value : incr or full)"
26
+fi
27
+
28
+verb=""
29
+[ $DEBUG -eq 1 ] && verb="-d" && echo "$( date ) - [DEBUG] Run $ttype backup of all machines" 
30
+
31
+ERROR=no
32
+
33
+for path in /var/lib/backuppc/pc/*
34
+do
35
+	[ ! -d "$path" ] && continue
36
+	machine=$( basename $path )
37
+	[ $DEBUG -eq 1 ] && echo "$( date ) - [DEBUG] Run $ttype backup of $machine"
38
+	$BCKP_BIN $machine $ttype $verb
39
+	res=$?
40
+	[ $DEBUG -eq 1 ] && echo "$( date ) - [DEBUG] End of $ttype backup of $machine. Return code : $res"
41
+	if [ $res -ne 0 ]
42
+	then
43
+		echo "[ERROR] Error during $ttype backup of $machine (Return code : $res)" > /dev/stderr
44
+		ERROR=YES
45
+	fi
46
+done
47
+
48
+[ $DEBUG -eq 1 ] && echo "$( date ) - [DEBUG] End of $ttype backup of all machines. Error : $ERROR" 
49
+
50
+if [ "$ERROR" != "no" ]
51
+then
52
+	echo "[ERROR] Error during $ttype backup of all machines"
53
+	exit 2
54
+fi
... ...
@@ -0,0 +1,50 @@
1
+#!/bin/bash
2
+
3
+BCKP_DUMP_BIN=/usr/share/backuppc/bin/BackupPC_dump
4
+BCKP_DIR=/var/lib/backuppc/pc
5
+
6
+MACHINE="$1"
7
+TYPE=$2
8
+DEBUG=0
9
+[ "$3" == "-d" ] && DEBUG=1
10
+
11
+function usage() {
12
+	[ -n "$1" ] && echo "[ERROR] $1" > /dev/stderr && echo
13
+	echo "usage : $0 [MACHINE] [incr|FULL] [-d]"
14
+	[ -n "$1" ] && exit 1 || exit 0
15
+}
16
+
17
+[ ! -n "$MACHINE" ] && usage
18
+
19
+[ ! -n "$TYPE" ] && TYPE=full
20
+
21
+if [ "$TYPE" == "incr" -o "$TYPE" == "INCR" ]
22
+then
23
+	ttype="incremental"
24
+	atype="-i"
25
+elif [ "$TYPE" == "full" -o "$TYPE" == "FULL" ]
26
+then
27
+	ttype="full"
28
+	atype="-f"
29
+else
30
+	usage "backup type not recognized (valid value : incr or full)"
31
+fi
32
+
33
+if [ ! -d "$BCKP_DIR/$MACHINE" ]
34
+then
35
+	usage "Machine name $MACHINE incorrect"
36
+fi
37
+
38
+verb=""
39
+[ $DEBUG -eq 1 ] && verb="-v" && echo "$( date ) - [DEBUG] Run $ttype backup of $MACHINE" 
40
+
41
+su - backuppc -c "$BCKP_DUMP_BIN $verb $atype $MACHINE"
42
+res=$?
43
+
44
+[ $DEBUG -eq 1 ] && echo "$( date ) - [DEBUG] End of $ttype backup of $MACHINE. Return code : $res" 
45
+
46
+if [ $res -ne 0 ]
47
+then
48
+	echo "[ERROR] Error during $ttype backup of $MACHINE (Return code : $res)" > /dev/stderr
49
+	exit $res
50
+fi
0 51