-
Notifications
You must be signed in to change notification settings - Fork 0
/
tapebackup
executable file
·68 lines (58 loc) · 1.28 KB
/
tapebackup
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
#!/bin/sh -eu
#dump -h 0 -u -a -b 256 -f /dev/nst0 -j9 -Q /tmp/root.qfa -0 /dev/mapper/box-root_ubuntu
DUMPOPTS=""
TAPE="/dev/nst0"
usage() {
echo "Usage: $(basename "${0}") [-t ${TAPE}] -[0-9] TARGET [...]"
}
while getopts ":h0123456789t:" opt; do
case ${opt} in
[0-9] ) LEVEL="$opt" ;;
t ) TAPE="$OPTARG" ;;
h ) usage ; exit 0; ;;
? ) echo "Invalid Option: -$OPTARG" 1>&2; usage 1>&2; exit 1; ;;
esac
done
shift $((OPTIND -1))
if [ -z "${TAPE:-}" ]
then
echo "Tape is required" 1>&2; usage 1>&2;
exit 1
fi
if [ -z "${*:-}" ]
then
echo "Target is required\n" 1>&2
dump -w 1>&2
echo 1>&2
usage 1>&2
exit 1
fi
if [ -z "${LEVEL:-}" ]
then
echo "Level is required\n" 1>&2
dump -w 1>&2
echo 1>&2
usage 1>&2
exit 1
fi
tell() {
mt -f "${TAPE}" tell | grep -o '[0-9]*'
}
for target
do
pos="$( (grep EOT tape || echo "0 EOT") | cut -d " " -f1 )"
mt -f "${TAPE}" seek "${pos}"
target_name="$(basename "${target}")"
slug="${target_name##*-}"
pos="$(tell)"
qfa="${slug}-${pos}.qfa"
dump -h 0 -u -a -b 256 ${DUMPOPTS:-} -f "${TAPE}" -Q "${qfa}" "-${LEVEL}" "${target}"
tmptape="$(mktemp tape.XXXXXXXXXX)"
(
grep -v -e "^${pos}\s" tape
echo "${pos} dump ${slug} ${LEVEL:-} ${DUMPOPTS:-}"
echo "$(tell) EOT"
) > "${tmptape}"
shtool rotate tape
mv "${tmptape}" tape
done