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 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   
35 -class ZenBackupBase(CmdBase):
36 37 38 doesLogging = False 39 40
41 - def __init__(self, noopts=0):
42 CmdBase.__init__(self, noopts) 43 from Utils import zenPath 44 self.zenhome = zenPath() 45 self.zopehome = os.getenv('ZOPEHOME')
46 47
48 - def msg(self, msg):
49 ''' If --verbose then send msg to stdout 50 ''' 51 if self.options.verbose: 52 print(msg)
53 54
55 - def buildOptions(self):
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
69 - def getPassArg(self):
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
78 - def getTempDir(self):
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
89 - def getRepozoPath(self):
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