-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_create_new_bacula_client_windows--server_side_template.sh
executable file
·181 lines (169 loc) · 4.4 KB
/
3_create_new_bacula_client_windows--server_side_template.sh
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# set -x
#
### === Create Config for new client for bacula - server side ===
#
# Set variables
SCRIPT_VERSION=0.2
PASSWORD="$(pwgen 32 1)"
MD5_PASSWORD=$(echo -n "$PASSWORD"|md5sum| sed -r 's/\s+.*$//;s/^/[md5]/')
CLIENT_NAME=
IP_ADDRESS=
# Function
show_help() {
echo ""
echo "Usage: $0 -n pc-01 -ip 10.0.2.5"
echo "Or"
echo "Usage: $0 --name pc-02 --ipaddress 10.0.2.5"
echo ""
echo "Create bacula client config files."
echo ""
echo "-h, --help Show help and exit."
echo "-v, --version Show script version and exit."
echo "-ip, --ipaddress IP address of bacula client - example: \"192.168.20.45\""
echo "-n, --name Name of bacula client - example: \"oracle8\""
echo ""
}
# Menu
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-ip|--ipaddress)
shift
BACULA_CLIENT_IP_ADDRESS=$1
shift
;;
-h|--help)
show_help
exit 0
;;
-v|--version)
echo "Script: Will show script version."
echo "Script: Version is: ${SCRIPT_VERSION}"
exit 0
;;
-n|--name)
shift
BACULA_CLIENT_NAME=$1
shift
;;
-*|--*)
echo "Script: Unrecognized option: '$key'"
echo "Script: See 'Script -h|--help' for supported options."
exit 0
;;
*) # unknown option
echo "Script: Unrecognized option: '$key'"
echo "Script: See 'Script -h|--help' for supported options."
exit 0
;;
esac
done
# Pass variables
CLIENT_NAME=${BACULA_CLIENT_NAME}
IP_ADDRESS=${BACULA_CLIENT_IP_ADDRESS}
BACULA_DIR_CONFIG_FILE_TEMPLATE=bacula-dir_template_windows.conf
BACULA_DIR_CONFIG_FILE=bacula-dir_${CLIENT_NAME}.conf
CONFIG_FOLDER=config_files
# create config folder
if [[ ! -d ${CONFIG_FOLDER} ]]; then
echo -n "Creating folder \"${CONFIG_FOLDER}\"... "
mkdir ${CONFIG_FOLDER}
echo [DONE]
fi
# create config files
if [[ -f ${BACULA_DIR_CONFIG_FILE_TEMPLATE} ]]; then
# Create config file
echo -n "Creating file: \"bacula-dir.conf\"... "
cp ${BACULA_DIR_CONFIG_FILE_TEMPLATE} ${CONFIG_FOLDER}/${BACULA_DIR_CONFIG_FILE}
echo [DONE]
# Create template
if [[ ! -z ${MD5_PASSWORD} ]] && [[ ! -z ${CLIENT_NAME} ]] && [[ ! -z ${IP_ADDRESS} ]]; then
echo "Password: ${PASSWORD}"
echo "MD5 Password: ${MD5_PASSWORD}"
echo "Client name: ${CLIENT_NAME}"
echo "IP Address: ${IP_ADDRESS}"
echo -n "Inserting variables into config file... "
sed -i -e "s/###CLIENT_NAME###/${CLIENT_NAME}/" \
-e "s/###IP_ADDRESS###/${IP_ADDRESS}/" \
-e "s/###MD5_PASSWORD###/${MD5_PASSWORD}/" ${CONFIG_FOLDER}/${BACULA_DIR_CONFIG_FILE}
echo [DONE]
fi
fi
exit 0
# Template
cat > bacula-dir_template.conf << 'EOL'
Client {
Name = "###CLIENT_NAME###-fd"
Address = "###IP_ADDRESS###"
FdPort = 9102
Password = "###MD5_PASSWORD###"
Description = "Backup Host - ###CLIENT_NAME###"
Catalog = "MyCatalog"
FileRetention = 5184000
JobRetention = 15552000
AutoPrune = yes
}
Job {
Name = "backup-###CLIENT_NAME###"
JobDefs = "###CLIENT_NAME###-job"
Description = "Backup Host - ###CLIENT_NAME###"
}
JobDefs {
Name = "###CLIENT_NAME###-job"
Type = "Backup"
Level = "Incremental"
Messages = "Standard"
Storage = "File1"
Pool = "Incremental"
FullBackupPool = "Full"
IncrementalBackupPool = "Incremental"
DifferentialBackupPool = "Differential"
Client = "###CLIENT_NAME###-fd"
Fileset = "###CLIENT_NAME###-fset"
Schedule = "WeeklyCycle"
WriteBootstrap = "/var/lib/bacula/%c.bsr"
SpoolAttributes = yes
Priority = 10
}
Fileset {
Name = "###CLIENT_NAME###-fd"
Include {
File = "/etc"
File = "/opt/bacula/etc"
Options {
Signature = MD5
Wild = *.jpg
Wild = *.png
Wild = *.gif
Wild = *.zip
Wild = *.rar
Wild = *.7z
Wild = *.r??
Wild = *.mpg
Wild = *.wmv
Wild = *.avi
Wild = *.mov
Wild = *.mkv
Wild = *.mp3
Wild = *.mp4
Wild = *.gz
Wild = *.bz2
}
Options {
Signature = "Md5"
Compression = "LZO"
}
}
Exclude {
File = "/proc"
File = "/tmp"
File = "/sys"
File = "/.journal"
File = "/.fsck"
File = "/etc/selinux"
File = "/etc/udev"
}
}
EOL