-
Notifications
You must be signed in to change notification settings - Fork 0
/
ib
executable file
·99 lines (92 loc) · 2.4 KB
/
ib
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
# Author: Rémi BARBERO
# Date: 2017-04-14
# Mail: [email protected]
# Incremental backups with rsync and hard links
DIR="$(dirname "$0")"
# include local configuration
while [ $# -gt 0 ]; do
case "$1" in
-c)
shift
if [ $# -gt 0 ]; then
SET_CONFIG=true
CONFIG=$1
fi
shift
;;
--config*)
SET_CONFIG=true
CONFIG=$(echo $1 | sed -e 's/^[^=]*=//g')
shift
;;
*)
break
;;
esac
done
if $SET_CONFIG; then
# test if this is relative or absolute path
if ! echo "$CONFIG" | grep -q "/"; then
CONFIG=./$CONFIG
fi
if [ -f $CONFIG ]; then
. $CONFIG
else
echo "no config file found"
exit 1
fi
else
if [ -f "$DIR/ib.cfg" ]; then
. "$DIR/ib.cfg"
else
echo "no config file found"
exit 1
fi
fi
# test variables in config.cfg
# SOURCE_PATH must be not empty
if [ ${#SOURCE_PATH[*]} -eq 0 ]; then
echo 'error: SOURCE_PATH is not defined.'
exit 1
fi
# DEST_PATH must be defined
if [ -z $DEST_PATH ]; then
echo 'error: DEST_PATH_PATH is no defined.'
exit 1
fi
# START_NUMBER must be defined
if [ -z $START_NUMBER ]; then
echo 'error: START_NUMBER is not defined.'
exit 1
fi
# NUMBER_BACKUP must be not empty
if [ $NUMBER_BACKUP -eq 0 ]; then
echo 'error: NUMBER_BACKUP is not defined.'
exit 1
fi
# TIME_BACKUP must be not empty
if [ $TIME_BACKUP -eq 0 ]; then
echo 'error: TIME_BACKUP is not defined.'
exit 1
fi
DEST_RSYNC_FOLDER="0_`date +%Y%m%d`"
# Manage the stock of backups
# Arguments (four):
# 1) DEST_PATH: where backups are stored
# 2) START_NUMBER is the start number in the first name of the backup
# 3) NUMBER_OF_BACKUP
# 4) INTERVAL_TIME_BETWEEN_TWO_BACKUPS (n * 24h)
# return string of two fields: "DO HARD_LINKS_SOURCE"
# 1) DO: tells if rsync must be executed
# 2) HARD_LINKS_SOURCE: is the folder where rsync make hard links
RES="$(sh -x $DIR/manage_save.sh $DEST_PATH $START_NUMBER $NUMBER_BACKUP $TIME_BACKUP)"
DO=$(echo $RES | cut -f1 -d ',')
HARD_LINKS_SOURCE=$(echo $RES | cut -f2 -d ',')
#rsync
if [ "$DO" -eq "1" ]; then
for i in "${SOURCE_PATH[@]}"
do
rsync -a --delete $(if [ ${#EXCLUDES[@]} -ne 0 ]; then echo "${EXCLUDES[@]/#/--exclude=}"; fi) $(if [ ! -z $HARD_LINKS_SOURCE ]; then echo "--link-dest=$DEST_PATH/$HARD_LINKS_SOURCE"; fi) "$i" $(if [ ! -z $SSH ]; then echo "-e \"ssh -p $SSH_PORT\" ${SSH_USER}@${SSH_HOST}:"; fi)$DEST_PATH/$DEST_RSYNC_FOLDER/
done
fi