File: crash-test

package info (click to toggle)
obnam 1.21-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 2,032 kB
  • ctags: 2,505
  • sloc: python: 14,404; sh: 410; ansic: 252; makefile: 66; awk: 5
file content (80 lines) | stat: -rwxr-xr-x 2,095 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
# Copyright 2012-2014  Lars Wirzenius
#
# This program 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 of the License, or
# (at your option) any later version.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


set -eu

if [ "$#" != 1 ]
then
    echo "usage: see source" 1>&2
    exit 1
fi

N="$1"

tempdir="$(mktemp -d)"
echo "Temporary directory: $tempdir"

cat <<EOF > "$tempdir/conf"
[config]
repository = $tempdir/repo
root = $tempdir/data
log = $tempdir/obnam.log
trace = larch
checkpoint = 1m
lock-timeout = 1
log-keep = 16
# log-level = debug
trace = larch, obnamlib
EOF

# Do a minimal backup to make sure the repository works at least once,
# without the crash-limit option
mkdir "$tempdir/data"
./obnam backup --no-default-config --config "$tempdir/conf"

genbackupdata --create=100m "$tempdir/data"

echo "crash-limit = $N" >> "$tempdir/conf"

while true
do
    # There's no need to delete this file because the first Exception message
    # that appears in the file will terminate the test.
    # rm -f "$tempdir/obnam.log"

    echo "Trying backup with at most $N writes to repository"
    ./obnam force-lock --no-default-config --config "$tempdir/conf" \
        2>/dev/null
    if ./obnam backup --no-default-config --config "$tempdir/conf" 2>/dev/null
    then
        echo "Backup finished ok, done"
        break
    fi

    if ! grep -q '^Exception: Crashing as requested' "$tempdir/obnam.log"
    then
        echo "Backup terminated because of unrequested crash" 1>&2
        exit 1
    fi

#    ./obnam fsck --no-default-config --config "$tempdir/conf" || true
done

rm -rf "$tempdir"

echo "OK"