1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 __doc__='''zenbackupcommon.py
17
18 Common code for zenbackup.py and zenrestore.py
19 '''
20
21 import os
22 import os.path
23 import tempfile
24 from CmdBase import CmdBase
25
26
27 BACKUP_DIR = 'zenbackup'
28 CONFIG_FILE = 'backup.settings'
29 CONFIG_SECTION = 'zenbackup'
30 CONFIG_FIELDS = ( ('dbname', 'events', 'database'),
31 ('dbuser', 'root', 'username'),
32 ('dbpass', '', 'password'))
33
34
36
37
38 doesLogging = False
39
40
46
47
49 ''' If --verbose then send msg to stdout
50 '''
51 if self.options.verbose:
52 print(msg)
53
54
56 """basic options setup sub classes can add more options here"""
57 CmdBase.buildOptions(self)
58 self.parser.add_option('-v', '--verbose',
59 dest="verbose",
60 default=False,
61 action='store_true',
62 help='Send progress messages to stdout.')
63 self.parser.add_option('--temp-dir',
64 dest="tempDir",
65 default=None,
66 help='Directory to use for temporary storage.')
67
68
70 ''' Return string to be used as the -p (including the "-p")
71 to mysql commands
72 '''
73 if self.options.dbpass == None:
74 return ''
75 return '-p"%s"' % self.options.dbpass
76
77
79 ''' Return directory to be used for temporary storage
80 during backup or restore.
81 '''
82 if self.options.tempDir:
83 dir = tempfile.mkdtemp('', '', self.options.tempDir)
84 else:
85 dir = tempfile.mkdtemp()
86 return dir
87
88
90 ''' Return path to repozo.py
91 This is usually $ZENHOME/bin/repozo.py, but on the appliance it is
92 $ZOPEHOME/bin/repozo.py
93 '''
94 path = os.path.join(self.zenhome, 'bin', 'repozo.py')
95 if not os.path.isfile(path):
96 path = os.path.join(self.zopehome, 'bin', 'repozo.py')
97 return path
98