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 tempfile
22 from CmdBase import CmdBase
23
24
25 BACKUP_DIR = 'zenbackup'
26 CONFIG_FILE = 'backup.settings'
27 CONFIG_SECTION = 'zenbackup'
28 CONFIG_FIELDS = ( ('dbname', 'events', 'database'),
29 ('dbuser', 'root', 'username'),
30 ('dbpass', '', 'password'))
31
32
34
35
36 doesLogging = False
37
38
41
43 ''' If --verbose then send msg to stdout
44 '''
45 if self.options.verbose:
46 print(msg)
47
48
50 """basic options setup sub classes can add more options here"""
51 CmdBase.buildOptions(self)
52 self.parser.add_option('-v', '--verbose',
53 dest="verbose",
54 default=False,
55 action='store_true',
56 help='Send progress messages to stdout.')
57 self.parser.add_option('--temp-dir',
58 dest="tempDir",
59 default=None,
60 help='Directory to use for temporary storage.')
61
62
64 ''' Return string to be used as the -p (including the "-p")
65 to mysql commands
66 '''
67 if self.options.dbpass == None:
68 return ''
69 return '--password="%s"' % self.options.dbpass
70
71
73 ''' Return directory to be used for temporary storage
74 during backup or restore.
75 '''
76 if self.options.tempDir:
77 dir = tempfile.mkdtemp('', '', self.options.tempDir)
78 else:
79 dir = tempfile.mkdtemp()
80 return dir
81