-
Notifications
You must be signed in to change notification settings - Fork 256
/
create_autochanger_configs.sh.in
executable file
·110 lines (90 loc) · 3.09 KB
/
create_autochanger_configs.sh.in
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
#!/bin/bash
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2021-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# 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
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
set -e
set -u
. ./environment
. ./tape-config
. ./redirect_output
echo "=== $0 Running ==="
autochanger_conf_file="${conf}/bareos-sd.d/autochanger/autochanger.conf"
tape_device_conf_file="${conf}/bareos-sd.d/device/tape_devices.conf"
dir_storage_conf_file="${conf}/bareos-dir.d/storage/Tape.conf"
[[ -d "${conf}/bareos-sd.d/autochanger" ]] || mkdir "${conf}/bareos-sd.d/autochanger"
rm -f "${autochanger_conf_file}"
rm -f "${tape_device_conf_file}"
rm -f "${dir_storage_conf_file}"
# loop over all changer devices
for changer_index in {0..9}; do
ch="CHANGER_DEVICE${changer_index}"
changer_device="${!ch:-}"
[[ -z "${changer_device}" ]] && break
echo "Creating devices for autochanger ${changer_device}"
####
cat << EOF >> "${autochanger_conf_file}"
Autochanger {
Name = "autochanger-${changer_index}"
Changer Device = ${changer_device}
Changer Command = "${rscripts}/mtx-changer %c %o %S %a %d"
EOF
####
cat << EOF >> "${dir_storage_conf_file}"
Storage {
Name = Tape-${changer_index}
Address = @hostname@
Password = "sd_password"
Device = autochanger-${changer_index}
SD Port = @sd_port@
Media Type = LTO
Auto Changer = yes
MaximumConcurrentJobs=2000
}
EOF
# loop over all tape devices attached to that changer
drive_index=0
tape_devices="TAPE_DEVICES${changer_index}[@]"
for tape_device in ${!tape_devices}; do
bareos_tape_device_name="tapedrive${changer_index}-${drive_index}"
echo " Attaching ${tape_device} to autochanger"
#### add the type device
cat << EOF >> ${conf}/bareos-sd.d/autochanger/autochanger.conf
Device=${bareos_tape_device_name}
EOF
####
echo " Creating Device ${bareos_tape_device_name}"
cat << EOF >> "${tape_device_conf_file}"
Device {
Name = "${bareos_tape_device_name}"
DeviceType = Tape
DriveIndex = ${drive_index}
ArchiveDevice = ${tape_device}
MediaType = LTO
AutoChanger = yes
AutomaticMount = yes
MaximumFileSize = 10GB
AlwaysOpen = Yes
MaximumBlockSize = 1M # must be larger than real block size, otherwise bls crashes.
}
EOF
(( drive_index=drive_index+1 ))
done # for tape_device in ${!tape_devices}; do
echo "" >> "${autochanger_conf_file}"
echo "}" >> "${autochanger_conf_file}"
done # for changer_index in {0..9}; do
echo "=== $0 Ready ==="