def run_backup(self): """Create archival contents in dump dir""" try: service.run_command(system.QUIESCE_DB2) self.execute_backup_cmd(system.OFFLINE_BACKUP_DB) service.run_command(system.UNQUIESCE_DB2) except exception.ProcessExecutionError: LOG.exception(_("An exception occurred while doing an offline " "backup.")) self.cleanup() raise
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 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 _post_restore(self, restore_command, rollforward_command=None): """ Restore from the directory that we untarred into """ out = "" try: out, err = utils.execute_with_timeout(system.GET_DB_NAMES, shell=True) except exception.ProcessExecutionError: LOG.exception("Couldn't find any databases.") dbNames = out.split() for dbName in dbNames: service.run_command(restore_command % {'dbname': dbName}) if rollforward_command: service.run_command(system.ROLL_FORWARD_DB % {'dbname': dbName}) LOG.info("Cleaning out restore location: %s.", system.DB2_BACKUP_DIR) service.remove_db2_dir(system.DB2_BACKUP_DIR)
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: LOG.debug("Caught exception when preparing the directory") self.cleanup() raise
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
def estimate_backup_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: size = 0 for dbname in self.databases: out = service.run_command(system.GET_DB_SIZE % {'dbname': dbname}) size = size + int(out[0]) except exception.ProcessExecutionError: LOG.exception(_("An error occurred while trying to " "estimate backup size")) LOG.debug("Estimated size for databases: %d", size) return size
def estimate_backup_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: size = 0 for dbname in self.databases: out = service.run_command(system.GET_DB_SIZE % {'dbname': dbname}) size = size + int(out[0]) except exception.ProcessExecutionError: LOG.exception(_("An error occurred while trying to " "estimate backup size")) LOG.debug("Estimated size for databases: " + str(size)) return size
def estimate_log_size(self): """ Estimate the log utilization for all databases. The LOG_UTILIZATION administrative view returns information about log utilization for the connected database. The TOTAL_LOG_USED_KB returns the log utilization in KB. """ log_size = 0 try: for dbname in self.databases: out = service.run_command( system.LOG_UTILIZATION % {'dbname': dbname}) log_size = log_size + int(out[0]) log_size = log_size * 1024 except exception.ProcessExecutionError: LOG.exception(_("An error occurred while trying to estimate log " "size")) LOG.debug("Estimated log size for all databases: %d", log_size) return log_size
def estimate_log_size(self): """ Estimate the log utilization for all databases. The LOG_UTILIZATION administrative view returns information about log utilization for the connected database. The TOTAL_LOG_USED_KB returns the log utilization in KB. """ log_size = 0 try: for dbname in self.databases: out = service.run_command( system.LOG_UTILIZATION % {'dbname': dbname}) log_size = log_size + int(out[0]) log_size = log_size * 1024 except exception.ProcessExecutionError: LOG.exception(_("An error occurred while trying to estimate log " "size")) LOG.debug("Estimated log size for all databases: " + str(log_size)) return log_size
def execute_backup_cmd(self, backup_command): service.create_db2_dir(system.DB2_BACKUP_DIR) for dbName in self.databases: service.run_command(backup_command % {'dbname': dbName})