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, 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__='''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   
33 -class ZenBackupBase(CmdBase):
34 35 36 doesLogging = False 37 38
39 - def __init__(self, noopts=0):
40 CmdBase.__init__(self, noopts)
41
42 - def msg(self, msg):
43 ''' If --verbose then send msg to stdout 44 ''' 45 if self.options.verbose: 46 print(msg)
47 48
49 - def buildOptions(self):
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
63 - def getPassArg(self):
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
72 - def getTempDir(self):
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