diff --git a/xtrabackup/backup_tools.py b/xtrabackup/backup_tools.py index 51d66a6..0916bc7 100644 --- a/xtrabackup/backup_tools.py +++ b/xtrabackup/backup_tools.py @@ -10,10 +10,18 @@ class BackupTool: - def __init__(self, log_file, output_file, no_compression): + def __init__(self, log_file, output_file, no_compression, debug=False): + self.debug = debug self.log_manager = log_manager.LogManager() self.stop_watch = timer.Timer() self.setup_logging(log_file) + try: + with open(output_file, 'a+'): + pass + except Exception as error: + self.logger.error('Output file error: %s', str(error), + exc_info=self.debug) + raise self.command_executor = CommandExecutor(output_file) self.compress = not no_compression self.http = HttpManager() @@ -26,15 +34,17 @@ def check_prerequisites(self, repository): try: filesystem_utils.check_required_binaries(['innobackupex', 'tar']) filesystem_utils.check_path_existence(repository) - except exception.ProgramError: - self.logger.error('Prerequisites check failed.', exc_info=True) + except exception.ProgramError as error: + self.logger.error('Prerequisites check failed. %s', str(error), + exc_info=self.debug) raise def prepare_workdir(self, path): try: filesystem_utils.mkdir_path(path, 0o755) except exception.ProgramError: - self.logger.error('Workdir preparation failed.', exc_info=True) + self.logger.error('Workdir preparation failed.', + exc_info=self.debug) raise self.workdir = path + '/xtrabackup_tmp' self.logger.debug("Temporary workdir: " + self.workdir) @@ -53,7 +63,8 @@ def prepare_repository(self, repository, incremental): self.backup_repository = filesystem_utils.create_sub_repository( repository, sub_directory) except exception.ProgramError: - self.logger.error('Unable to create repository.', exc_info=True) + self.logger.error('Unable to create repository.', + exc_info=self.debug) raise def prepare_archive_name(self, incremental, incremental_cycle): @@ -79,7 +90,7 @@ def exec_incremental_backup(self, user, password, thread_count): except ProcessError: self.logger.error( 'An error occured during the incremental backup process.', - exc_info=True) + exc_info=self.debug) self.clean() raise self.logger.info("Incremental backup time: %s - Duration: %s", @@ -96,7 +107,8 @@ def exec_full_backup(self, user, password, thread_count): self.workdir) except ProcessError: self.logger.error( - 'An error occured during the backup process.', exc_info=True) + 'An error occured during the backup process.', + exc_info=self.debug) self.clean() raise self.logger.info("Backup time: %s - Duration: %s", @@ -111,7 +123,7 @@ def prepare_backup(self, redo_logs): except ProcessError: self.logger.error( 'An error occured during the preparation process.', - exc_info=True) + exc_info=self.debug) self.clean() raise self.logger.info("Backup preparation time: %s - Duration: %s", @@ -126,7 +138,7 @@ def archive_backup(self): except ProcessError: self.logger.error( 'An error occured during the archiving of the backup.', - exc_info=True) + exc_info=self.debug) self.clean() raise self.logger.info("Backup archiving time: %s - Duration: %s", @@ -142,7 +154,7 @@ def transfer_backup(self, repository): except Exception: self.logger.error( 'An error occured during the backup transfer.', - exc_info=True) + exc_info=self.debug) self.clean() raise self.logger.info("Archive copy time: %s - Duration: %s", @@ -178,7 +190,7 @@ def save_incremental_data(self, incremental): except: self.logger.error( 'Unable to save the incremental backup data.', - exc_info=True) + exc_info=self.debug) self.clean() raise @@ -197,7 +209,7 @@ def load_incremental_data(self): except: self.logger.error( 'Unable to load the incremental backup data.', - exc_info=True) + exc_info=self.debug) self.clean() raise diff --git a/xtrabackup/full_backup.py b/xtrabackup/full_backup.py index a147589..b3958df 100755 --- a/xtrabackup/full_backup.py +++ b/xtrabackup/full_backup.py @@ -1,14 +1,7 @@ """Xtrabackup script Usage: - pyxtrabackup --user= \ -[--password=] \ -[--tmp-dir=] \ -[--log-file=] \ -[--out-file=] \ -[--backup-threads=] \ -[--no-compress] \ -[--webhook=] + pyxtrabackup --user= [options] pyxtrabackup (-h | --help) pyxtrabackup --version @@ -16,6 +9,8 @@ Options: -h --help \ Show this screen. + -d --debug \ + Enable verbose error --version \ Show version. --user= \ @@ -44,9 +39,11 @@ def main(): arguments = docopt(__doc__, version='3.1.2') - backup_tool = BackupTool(arguments['--log-file'], arguments['--out-file'], - arguments['--no-compress']) try: + backup_tool = BackupTool( + arguments['--log-file'], arguments['--out-file'], + arguments['--no-compress'], arguments['--debug']) + backup_tool.start_full_backup(arguments[''], arguments['--tmp-dir'], arguments['--user'], @@ -55,7 +52,7 @@ def main(): arguments['--webhook']) except Exception: logger = logging.getLogger(__name__) - logger.error("pyxtrabackup failed.", exc_info=True) + logger.error("pyxtrabackup failed.", exc_info=arguments['--debug']) exit(1) exit(0) diff --git a/xtrabackup/incremental_backup.py b/xtrabackup/incremental_backup.py index dd32825..ea38784 100755 --- a/xtrabackup/incremental_backup.py +++ b/xtrabackup/incremental_backup.py @@ -1,14 +1,7 @@ """Xtrabackup script Usage: - pyxtrabackup-inc --user= \ -[--password=] \ -[--incremental] \ -[--tmp-dir=] \ -[--log-file=] \ -[--out-file=] \ -[--backup-threads=] \ -[--no-compress] + pyxtrabackup-inc --user= [options] pyxtrabackup-inc (-h | --help) pyxtrabackup --version @@ -16,6 +9,8 @@ Options: -h --help \ Show this screen. + -d --debug \ + Enable verbose error --version \ Show version. --user= \ @@ -44,18 +39,21 @@ def main(): arguments = docopt(__doc__, version='3.1.2') - backup_tool = BackupTool(arguments['--log-file'], arguments['--out-file'], - arguments['--no-compress']) try: - backup_tool.start_incremental_backup(arguments[''], - arguments['--incremental'], - arguments['--tmp-dir'], - arguments['--user'], - arguments['--password'], - arguments['--backup-threads']) + backup_tool = BackupTool( + arguments['--log-file'], arguments['--out-file'], + arguments['--no-compress'], arguments['--debug']) + + backup_tool.start_incremental_backup( + arguments[''], + arguments['--incremental'], + arguments['--tmp-dir'], + arguments['--user'], + arguments['--password'], + arguments['--backup-threads']) except Exception: logger = logging.getLogger(__name__) - logger.error("pyxtrabackup failed.", exc_info=True) + logger.error("pyxtrabackup failed.", exc_info=arguments['--debug']) exit(1) exit(0) diff --git a/xtrabackup/log_manager.py b/xtrabackup/log_manager.py index c7ab20a..c6e953a 100644 --- a/xtrabackup/log_manager.py +++ b/xtrabackup/log_manager.py @@ -7,7 +7,11 @@ def __init__(self): logging.basicConfig(level=logging.INFO) def attach_file_handler(self, logger, log_file): - handler = logging.FileHandler(log_file) + try: + handler = logging.FileHandler(log_file) + except Exception as error: + print(error) + raise error handler.setLevel(logging.INFO) formatter = logging.Formatter( '%(asctime)s - %(levelname)s - %(message)s')