def post_restore(self): """ Restore from the directory that we untarred into """ out, err = utils.execute_with_timeout(system.GET_DB_NAMES, shell=True) dbNames = out.split() for dbName in dbNames: service.run_command(system.RESTORE_DB % {'dbname': dbName, 'dir': DB2_BACKUP_DIR}) LOG.info(_("Cleaning out restore location post: %s."), DB2_BACKUP_DIR) operating_system.remove(DB2_BACKUP_DIR, force=True, as_root=True)
def _run_pre_backup(self): """Create archival contents in dump dir""" try: est_dump_size = self.estimate_dump_size() avail = operating_system.get_bytes_free_on_fs(DB2_DBPATH) if est_dump_size > avail: self.cleanup() raise OSError( _("Need more free space to backup db2 database," " estimated %(est_dump_size)s" " and found %(avail)s bytes free ") % { 'est_dump_size': est_dump_size, 'avail': avail }) operating_system.create_directory(DB2_BACKUP_DIR, system.DB2_INSTANCE_OWNER, system.DB2_INSTANCE_OWNER, as_root=True) service.run_command(system.QUIESCE_DB2) dbNames = self.list_dbnames() for dbName in dbNames: service.run_command(system.BACKUP_DB % { 'dbname': dbName, 'dir': DB2_BACKUP_DIR }) service.run_command(system.UNQUIESCE_DB2) except exception.ProcessExecutionError as e: LOG.debug("Caught exception when preparing the directory") self.cleanup() raise e
def _run_pre_backup(self): """Create archival contents in dump dir""" try: est_dump_size = self.estimate_dump_size() avail = operating_system.get_bytes_free_on_fs(DB2_DBPATH) if est_dump_size > avail: self.cleanup() raise OSError(_("Need more free space to backup db2 database," " estimated %(est_dump_size)s" " and found %(avail)s bytes free ") % {'est_dump_size': est_dump_size, 'avail': avail}) operating_system.create_directory(DB2_BACKUP_DIR, system.DB2_INSTANCE_OWNER, system.DB2_INSTANCE_OWNER, as_root=True) service.run_command(system.QUIESCE_DB2) dbNames = self.list_dbnames() for dbName in dbNames: service.run_command(system.BACKUP_DB % { 'dbname': dbName, 'dir': DB2_BACKUP_DIR}) service.run_command(system.UNQUIESCE_DB2) except exception.ProcessExecutionError as e: LOG.debug("Caught exception when preparing the directory") self.cleanup() raise e
def estimate_dump_size(self): """ Estimating the size of the backup based on the size of the data returned from the get_db_size procedure. The size of the backup is always going to be smaller than the size of the data. """ try: dbs = self.list_dbnames() size = 0 for dbname in dbs: out = service.run_command(system.GET_DB_SIZE % {'dbname': dbname}) size = size + out except exception.ProcessExecutionError: LOG.debug("Error while trying to get db size info") LOG.debug("Estimated size for databases: " + str(size)) return size