Package ZenUtils :: Module ZenBackupBase
[hide private]
[frames] | no frames]

Source Code for Module ZenUtils.ZenBackupBase

 1  #! /usr/bin/env python 
 2  ########################################################################### 
 3  # 
 4  # This program is part of Zenoss Core, an open source monitoring platform. 
 5  # Copyright (C) 2007, 2009 Zenoss Inc. 
 6  # 
 7  # This program is free software; you can redistribute it and/or modify it 
 8  # under the terms of the GNU General Public License version 2 as published by 
 9  # the Free Software Foundation. 
10  # 
11  # For complete information please visit: http://www.zenoss.com/oss/ 
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   
33 -class ZenBackupBase(CmdBase):
34 doesLogging = False 35 36
37 - def __init__(self, noopts=0):
38 CmdBase.__init__(self, noopts)
39
40 - def msg(self, msg):
41 ''' 42 If --verbose then send msg to stdout 43 ''' 44 if self.options.verbose: 45 print(msg)
46 47
48 - def buildOptions(self):
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
64 - def getPassArg(self):
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
77 - def getTempDir(self):
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