1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 __doc__='''ZenBackupBase
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 doesLogging = False
35
36
39
41 '''
42 If --verbose then send msg to stdout
43 '''
44 if self.options.verbose:
45 print(msg)
46
47
49 """
50 Command-line options setup
51 """
52 CmdBase.buildOptions(self)
53 self.parser.add_option('-v', '--verbose',
54 dest="verbose",
55 default=False,
56 action='store_true',
57 help='Send progress messages to stdout.')
58 self.parser.add_option('--temp-dir',
59 dest="tempDir",
60 default=None,
61 help='Directory to use for temporary storage.')
62
63
65 '''
66 Return string to be used as the -p (including the "-p")
67 to MySQL commands.
68
69 @return: password and flag
70 @rtype: string
71 '''
72 if self.options.dbpass == None:
73 return ''
74 return '--password="%s"' % self.options.dbpass
75
76
78 '''
79 Return directory to be used for temporary storage
80 during backup or restore.
81
82 @return: directory name
83 @rtype: string
84 '''
85 if self.options.tempDir:
86 dir = tempfile.mkdtemp('', '', self.options.tempDir)
87 else:
88 dir = tempfile.mkdtemp()
89 return dir
90