Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions xtrabackup/backup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
19 changes: 8 additions & 11 deletions xtrabackup/full_backup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
"""Xtrabackup script

Usage:
pyxtrabackup <repository> --user=<user> \
[--password=<pwd>] \
[--tmp-dir=<tmp>] \
[--log-file=<log>] \
[--out-file=<log>] \
[--backup-threads=<threads>] \
[--no-compress] \
[--webhook=<url>]
pyxtrabackup <repository> --user=<user> [options]
pyxtrabackup (-h | --help)
pyxtrabackup --version


Options:
-h --help \
Show this screen.
-d --debug \
Enable verbose error
--version \
Show version.
--user=<user> \
Expand Down Expand Up @@ -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['<repository>'],
arguments['--tmp-dir'],
arguments['--user'],
Expand All @@ -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)

Expand Down
32 changes: 15 additions & 17 deletions xtrabackup/incremental_backup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
"""Xtrabackup script

Usage:
pyxtrabackup-inc <repository> --user=<user> \
[--password=<pwd>] \
[--incremental] \
[--tmp-dir=<tmp>] \
[--log-file=<log>] \
[--out-file=<log>] \
[--backup-threads=<threads>] \
[--no-compress]
pyxtrabackup-inc <repository> --user=<user> [options]
pyxtrabackup-inc (-h | --help)
pyxtrabackup --version


Options:
-h --help \
Show this screen.
-d --debug \
Enable verbose error
--version \
Show version.
--user=<user> \
Expand Down Expand Up @@ -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['<repository>'],
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['<repository>'],
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)

Expand Down
6 changes: 5 additions & 1 deletion xtrabackup/log_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down