summaryrefslogtreecommitdiff
path: root/bin/check_db
blob: 7953653260a0a56291edfe5139cb9df582edcce7 (plain) (blame)
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
#! /usr/bin/env python
#
# Copyright (C) 1998 by the Free Software Foundation, Inc.
#
# 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 2
# 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, write to the Free Software 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""Check the raw config.db for a mailing list.
Also check the config.db.last if the live file is corrupted.

Usage: %(program)s listname
"""

import sys
import os
import marshal
import paths
import Mailman.mm_cfg

program = sys.argv[0]

def testfile(filename):
    try:
        fp = open(filename)
    except IOError, (code, msg):
        print filename, 'cannot be opened:\n\t', msg
        return 1
    else:
        try:
            d = marshal.load(fp)
        except (EOFError, ValueError, TypeError), msg:
            print filename, 'is corrupted:\n\t', msg
            return 1
        else:
            print filename, 'is fine'
            return 0


def main():
    if len(sys.argv) == 2:
        listname = sys.argv[1]
    else:
        print __doc__ % globals()
        sys.exit(1)

    listpath = os.path.join(Mailman.mm_cfg.LIST_DATA_DIR, listname)
    configdb = os.path.join(listpath, 'config.db')
    lastdb = os.path.join(listpath, 'config.db.last')

    origbad = testfile(configdb)
    backupbad = testfile(lastdb)

    if origbad and not backupbad:
        print """
***** ALERT *****
The original database file is corrupt, but the backup seems fine.
Consider copying
    %(lastdb)s
to
    %(configdb)s
however, you may lose some data.""" % locals()
    elif origbad and backupbad:
        print """
***** ALERT *****
Both the original database file and the backup seem
corrupted.  You will probably need to recover both
    %(configdb)s
and
    %(lastdb)s
from a system backup, or remove the list `%(listname)s' and
re-create it from scratch.""" % locals()
        

if __name__ == '__main__':
    main()