Beispiel #1
0
 def __init__(self, configname):
     zfscredfilename = os.path.join(scriptpath(), 'netappcredentials.cfg')
     if not os.path.isfile(zfscredfilename):
         raise Exception(
             self._exceptionbase,
             "Configuration file %s not found" % zfscredfilename)
     # Authentication information
     zfscredconfig = SafeConfigParser()
     zfscredconfig.read(zfscredfilename)
     zfsauth = (zfscredconfig.get('netappcredentials', 'user'),
                zfscredconfig.get('netappcredentials', 'password'))
     #
     self._filer = Configuration.get('filer', 'netapp')
     self._srv = NaServer(self._filer, 1, 1)
     # Check if CA certificate validation is needed
     try:
         self._cacert = os.path.join(scriptpath(), 'certs',
                                     Configuration.get('cacert', 'netapp'))
     except NoOptionError:
         self._cacert = None
     if self._cacert:
         self._srv.set_ca_certs(self._cacert)
         self._srv.set_server_cert_verification(True)
         self._srv.set_hostname_verification(False)
     #
     self._srv.set_admin_user(
         zfscredconfig.get('netappcredentials', 'user'),
         zfscredconfig.get('netappcredentials', 'password'))
     self._volprefix = Configuration.get('volumeprefix', 'netapp')
     self._volname = "%s%s" % (self._volprefix, configname)
     super(Netapp, self).__init__(configname)
Beispiel #2
0
 def pit_restore(self, mountpath, sid):
     self._restoredest = mkdtemp(prefix="restore", dir=mountpath)
     self._mountdest = mountpath
     self._restoresid = sid
     self._set_parameters()
     self._createinitora()
     self._exec = OracleExec(oraclehome=Configuration.get('oraclehome', 'generic'),
         tnspath=os.path.join(scriptpath(), Configuration.get('tnsadmin', 'generic')),
         sid=sid)
     self._run_restore()
Beispiel #3
0
 def __init__(self, configname):
     credfilename = os.path.join(scriptpath(), 'softnascredentials.cfg')
     if not os.path.isfile(credfilename):
       raise Exception(self._exceptionbase, "Configuration file %s not found" % credfilename)
     # Authentication information
     credconfig = SafeConfigParser()
     credconfig.read(credfilename)
     self._username = credconfig.get('credentials','user')
     self._password = credconfig.get('credentials','password')
     #
     self._serveraddress = Configuration.get('serveraddress', 'softnas')
     url = "https://%s/softnas" % self._serveraddress
     self._pool = Configuration.get('pool', 'softnas')
     self._filesystem = configname
     #
     self._http = SoftNASHttp(url)
     super(SoftNAS, self).__init__(configname)
Beispiel #4
0
 def run(self):
     self.starttime = datetime.now()
     info("Starting to restore")
     #
     success = False
     self.clone()
     try:
         self._mount()
     except:
         self.cleanup()
         raise Exception('restore', 'Mount failed')
     self._set_parameters()
     self._createinitora()
     self._exec = OracleExec(oraclehome=Configuration.get('oraclehome', 'generic'),
         tnspath=os.path.join(scriptpath(), Configuration.get('tnsadmin', 'generic')),
         sid=self._dbparams['dbname'])
     #
     self._run_restore()
Beispiel #5
0
 def __init__(self, configname):
     zfscredfilename = os.path.join(scriptpath(), 'zfscredentials.cfg')
     if not os.path.isfile(zfscredfilename):
         raise Exception(
             self._exceptionbase,
             "Configuration file %s not found" % zfscredfilename)
     # Authentication information
     zfscredconfig = SafeConfigParser()
     zfscredconfig.read(zfscredfilename)
     zfsauth = (zfscredconfig.get('zfscredentials', 'zfsuser'),
                zfscredconfig.get('zfscredentials', 'zfspassword'))
     #
     zfssaurl = "%s/api/storage/v1" % Configuration.get('url', 'zfssa')
     self._pool = Configuration.get('pool', 'zfssa')
     self._project = Configuration.get('project', 'zfssa')
     self._filesystem = configname
     #
     self._http = ZFSHttp(zfssaurl, zfsauth)
     super(ZFSSA, self).__init__(configname)
def exec_restore():
    global exitvalue

    restore.clone(False)
    print "Please execute the following command as root to mount the backup volume:"
    print ""
    print "mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600 %s %s" % (restore.mountstring, restoreparams['mountpath'])
    print ""
    while ask_yn("Did you execute it") == "N":
        print "Please execute it then."
    # Verify that clone is mounted
    autorestorefile = os.path.join(restoreparams['mountpath'], 'autorestore.cfg')
    if not os.path.isfile(autorestorefile):
        print "The mounted path does not look correct, file %s not found" % autorestorefile
        exitvalue = 1
        return
    #
    BackupLogger.init('/tmp/restore_%s_%s.log' % (datetime.now().strftime('%Y%m%dT%H%M%S'), configname))
    BackupLogger.clean()
    Configuration.substitutions.update({
        'logdir': '/tmp',
        'logfile': BackupLogger.logfile
    })
    print "Session log file: %s" % BackupLogger.logfile
    info("Starting database restore")
    #
    try:
        restore.pit_restore(restoreparams['mountpath'], restoreparams['sid'])
        restore.verify(False)
        info("Database restore complete")
        info("SID: %s" % restoreparams['sid'])
        info("Requested target time: %s" % restoreparams['timepoint'].astimezone(get_localzone()))
        info("Verified restored database time: %s" % restore.verifytime)
        info("Difference from target: %s" % restore.verifydiff)
    except:
        exception("Database restore failed")
        exitvalue = 1
    print ""
    print "Commands to clean up:"
    print "1. Shut down database instance %s" % restoreparams['sid']
    print "2. Execute as root: umount %s" % restoreparams['mountpath']
    print "3. Drop clone: BACKUPCONFIG=%s %s %s dropclone %s" % (os.path.basename(Configuration.configfilename),
        os.path.join(scriptpath(), 'zsnapper.py'), configname, restore.clonename)
Beispiel #7
0
def exec_restore():
    global exitvalue

    restore.clone(False)
    print "Please execute the following command as root to mount the backup volume:"
    print ""
    print "mount -t nfs -o rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,vers=3,timeo=600 %s %s" % (restore.mountstring, restoreparams['mountpath'])
    print ""
    while ask_yn("Did you execute it") == "N":
        print "Please execute it then."
    # Verify that clone is mounted
    autorestorefile = os.path.join(restoreparams['mountpath'], 'autorestore.cfg')
    if not os.path.isfile(autorestorefile):
        print "The mounted path does not look correct, file %s not found" % autorestorefile
        exitvalue = 1
        return
    #
    debug("Oracle home: %s" % Configuration.get("oraclehome", "generic"))
    debug("Clone mount path: %s" % restoreparams['mountpath'])
    debug("Target instance SID: %s" % restoreparams['sid'])
    debug("Restore target time UTC: %s" % restoreparams['timepoint'].astimezone(pytz.utc))
    debug("Restore target time local: %s" % restoreparams['timepoint'].astimezone(get_localzone()))
    debug("Restored from snapshot: %s" % restore.sourcesnapid)
    info("Starting database restore")
    #
    try:
        restore.pit_restore(restoreparams['mountpath'], restoreparams['sid'])
        restore.verify(False)
        info("Database restore complete")
        info("SID: %s" % restoreparams['sid'])
        info("Requested target time: %s" % restoreparams['timepoint'].astimezone(get_localzone()))
        info("Verified restored database time: %s" % restore.verifytime)
        info("Difference from target: %s" % restore.verifydiff)
    except:
        exception("Database restore failed")
        exitvalue = 1
    print ""
    print "Commands to clean up:"
    print "1. Shut down database instance %s" % restoreparams['sid']
    print "2. Execute as root: umount %s" % restoreparams['mountpath']
    print "3. Drop clone: BACKUPCONFIG=%s %s %s dropclone %s" % (os.path.basename(Configuration.configfilename),
        os.path.join(scriptpath(), 'zsnapper.py'), configname, restore.clonename)
 def __init__(self, configname):
     zfscredfilename = os.path.join(scriptpath(), 'netappcredentials.cfg')
     if not os.path.isfile(zfscredfilename):
         raise Exception(
             self._exceptionbase,
             "Configuration file %s not found" % zfscredfilename)
     # Authentication information
     zfscredconfig = SafeConfigParser()
     zfscredconfig.read(zfscredfilename)
     zfsauth = (zfscredconfig.get('netappcredentials', 'user'),
                zfscredconfig.get('netappcredentials', 'password'))
     #
     self._filer = Configuration.get('filer', 'netapp')
     self._srv = NaServer(self._filer, 1, 1)
     self._srv.set_admin_user(
         zfscredconfig.get('netappcredentials', 'user'),
         zfscredconfig.get('netappcredentials', 'password'))
     self._volprefix = Configuration.get('volumeprefix', 'netapp')
     self._volname = "%s%s" % (self._volprefix, configname)
     super(Netapp, self).__init__(configname)
Configuration.init(configsection)
gimanaged = Configuration.get('gimanaged').upper() == 'TRUE'

if not gimanaged:
    print "gimanaged option is not set to TRUE for this database"
    sys.exit(2)

# Set oracle home, if it is not configured separately, take it from environment
oraclehome = Configuration.get('oraclehome', 'generic')
if os.environ.get('ORACLE_SID'):
    del os.environ['ORACLE_SID']
os.environ['ORACLE_HOME'] = oraclehome
os.environ['NLS_DATE_FORMAT'] = 'yyyy-mm-dd hh24:mi:ss'

# Get software version
p = Popen([os.path.join(scriptpath(), "get_oracle_version.sh"), oraclehome],
          stdout=PIPE,
          stderr=None,
          stdin=None)
oracleversion, dataerr = p.communicate()
if oracleversion < "11.1":
    print "Detected Oracle software version %s is too old" % oracleversion
    sys.exit(1)

# srvctl config database
print "== Database configuration =="
p = Popen([
    os.path.join(oraclehome, 'bin', 'srvctl'), 'config', 'database', '-d',
    configsection
],
          stdout=PIPE,
Beispiel #10
0
Configuration.init('autorestore',
                   configfilename=sys.argv[1],
                   additionaldefaults={
                       'customverifydate':
                       'select max(time_dp) from sys.smon_scn_time',
                       'autorestoreenabled': '1',
                       'autorestoreinstancenumber': '1',
                       'autorestorethread': '1'
                   })
validatechance = int(
    Configuration.get('autorestorevalidatechance', 'autorestore'))
validatemodulus = int(Configuration.get('autorestoremodulus', 'autorestore'))
oexec = OracleExec(oraclehome=Configuration.get('oraclehome', 'generic'),
                   tnspath=os.path.join(
                       scriptpath(), Configuration.get('tnsadmin', 'generic')))
restoretemplate = BackupTemplate('restoretemplate.cfg')

# Does the backup destination exist?
restoredest = Configuration.get('autorestoredestination', 'autorestore')
mountdest = Configuration.get('autorestoremountpoint', 'autorestore')
logdir = Configuration.get('autorestorelogdir', 'autorestore')
Configuration.substitutions.update({
    'logdir':
    logdir,
    'autorestorecatalog':
    Configuration.get('autorestorecatalog', 'autorestore')
})
if restoredest is None or not os.path.exists(restoredest) or not os.path.isdir(
        restoredest):
    print "Restore directory %s not found or is not a proper directory" % restoredest
import os, sys, json
from backupcommon import scriptpath, Configuration, BackupLogger, BackupTemplate, info, error, debug, exception, create_snapshot_class
from tempfile import mkstemp
from oraexec import OracleExec


def printhelp():
    print "Usage: report.py [comma separated list of databases]"
    sys.exit(2)


if len(sys.argv) not in [1, 2]:
    printhelp()

# Directory where the executable script is located
scriptpath = scriptpath()

# Read configuration
logf = mkstemp(prefix='backupreport-', suffix='.log')
os.close(logf[0])
Configuration.init('generic')
BackupLogger.init(logf[1], 'reporting')
Configuration.substitutions.update({
    'logfile':
    BackupLogger.logfile,
    'autorestorecatalog':
    Configuration.get('autorestorecatalog', 'autorestore')
})
reporttemplate = BackupTemplate('reporttemplate.cfg')