blob: 74553e33b837a0912c389a16eca255bacdd55413 (
plain)
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
|
#! /bin/sh
# This file is part of BEAM
# Copyright (C) 2012 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# BEAM 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BEAM. If not, see <http://www.gnu.org/licenses/>.
# initdb item
# Initializes snapshot for the given basename.
initdb() {
local filename
if [ -n "$dry_run" ]; then
logit "initializing snapshot for $1"
return
fi
if [ $level -eq 0 ]; then
filename=$backup_snapshot_dir/$1-$week-$round-$level.db
test -r $filename && rm $filename
else
if [ $level -eq 1 ]; then
filename=$backup_snapshot_dir/$1-$week-0-0.db
else
filename=$backup_snapshot_dir/$1-$week-$round-$((level - 1)).db
fi
if [ -r $filename ]; then
cp $filename $backup_snapshot_dir/$1-$week-$round-$level.db
else
abend 1 "previous snapshot file $filename not found; cannot backup at level $level"
exit 1
fi
fi
}
# fs_check item
fs_check() {
local rc=0
eval root=\$${1}_dir
eval files=\$${1}_files
test -z "$root" && rc=1 && error "${1}_dir not set"
test -z "$files" && rc=1 && error "${1}_files not set"
return $rc
}
# fs_backup item
fs_backup() {
local basename text root files exclude addopts s e
basename=$1-$week-$round-$level
eval text=\$${1}_text
eval root=\$${1}_dir
eval files=\$${1}_files
eval addopts=\$${1}_tar_options
eval exclude=\$${1}_exclude
for e in $exclude
do
eval s="$e"
addopts="$addopts --exclude=$s"
done
eval exclude=\$${1}_exclude_from
for e in $exclude
do
addopts="$addopts --exclude-from=$e"
done
test -z "$root" && abend 1 "${1}_dir not set"
test -z "$files" && abend 1 "${1}_files not set"
test -z "$text" && text="$1"
initdb $1
logit "backing up $text ($basename.$tar_suffix)"
$dry_run tar $verbose $taroptions $addopts \
-f $backup_archive_dir/$basename.$tar_suffix \
--listed=$backup_snapshot_dir/$basename.db \
-C $root $files
tarcode $?
}
# fs_restore item
fs_restore() {
local i text root files tarcommand
eval text=\$${1}_text
eval root=\$${1}_dir
eval files=\$${1}_files
test -z "$root" && abend 1 "${1}_dir not set"
test -z "$files" && abend 1 "${1}_files not set"
test -z "$text" && text="$1"
tarcommand="tar $verbose $taroptions -C $root --listed-incremental=/dev/null -f"
logit "restoring $text"
logit "restoring from level 0 backup"
$dry_run $tarcommand $backup_archive_dir/$1-$week-0-0.$tar_suffix
tarcode $?
for i in $(seq 1 $level)
do
logit "restoring from the $round/$i backup"
$dry_run $tarcommand $backup_archive_dir/$1-$week-$round-$i.tar.bz2
tarcode $?
done
logit "finished restoring $text"
}
|