From c91702ce0011c4d3d0e4d4750688a57196b63d9b Mon Sep 17 00:00:00 2001 From: Herbert Poeckl Date: Tue, 11 Sep 2018 16:31:06 +0200 Subject: [PATCH 1/4] insert an option that does not stop the mysql service --- README.rst | 1 + xtrabackup/restoration.py | 4 ++++ xtrabackup/restoration_tools.py | 20 +++++++++++--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index a57eafd..1abbfdb 100644 --- a/README.rst +++ b/README.rst @@ -60,6 +60,7 @@ You can also specify the following options: * --out-file: Log file for innobackupex output (default: */var/log/mysql/xtrabackup.out*). * --backup-threads: You can specify more threads in order to backup quicker (default: 1). * --no-compress: Do not compress the backup archive. +* --no-service-stop: Don't stop mysqld service during restore process. * --webhook: URL to send a POST request after the backup is finished. Will send the *archive_path* and *archive_repository* in JSON. Restoration diff --git a/xtrabackup/restoration.py b/xtrabackup/restoration.py index 1a807d2..9e0015d 100644 --- a/xtrabackup/restoration.py +++ b/xtrabackup/restoration.py @@ -11,6 +11,7 @@ [--log-file=] \ [--out-file=] \ [--backup-threads=] \ +[--no-service-stop] \ [--uncompressed-archives] pyxtrabackup-restore (-h | --help) pyxtrabackup --version @@ -41,6 +42,8 @@ Output file [default: /var/log/mysql/xtrabackup.out]. --backup-threads= \ Threads count [default: 1]. + --no-service-stop \ + Don't stop mysqld service during restore process. --uncompressed-archives \ Specify that the backup archives are not compressed. \ Use this option if you did backup with --no-compress. @@ -57,6 +60,7 @@ def main(): restore_tool = RestorationTool(arguments['--log-file'], arguments['--out-file'], arguments['--data-dir'], + arguments['--no-service-stop'], arguments['--uncompressed-archives']) try: restore_tool.start_restoration(arguments['--base-archive'], diff --git a/xtrabackup/restoration_tools.py b/xtrabackup/restoration_tools.py index 73735e0..1c0b8c2 100644 --- a/xtrabackup/restoration_tools.py +++ b/xtrabackup/restoration_tools.py @@ -8,12 +8,13 @@ class RestorationTool: - def __init__(self, log_file, output_file, data_dir, uncompressed_archives): + def __init__(self, log_file, output_file, data_dir, no_service_stop, uncompressed_archives): self.log_manager = log_manager.LogManager() self.data_dir = data_dir self.stop_watch = timer.Timer() self.setup_logging(log_file) self.command_executor = CommandExecutor(output_file) + self.service_stop = not no_service_stop self.compressed_archives = not uncompressed_archives def setup_logging(self, log_file): @@ -26,14 +27,15 @@ def prepare_workdir(self, path): self.logger.debug("Temporary workdir: " + self.workdir) def stop_service(self): - try: - self.command_executor.exec_manage_service('mysql', 'stop') - except: - self.logger.error( - 'Unable to manage MySQL service.', - exc_info=True) - self.clean() - raise + if self.service_stop: + try: + self.command_executor.exec_manage_service('mysql', 'stop') + except: + self.logger.error( + 'Unable to manage MySQL service.', + exc_info=True) + self.clean() + raise def clean_data_dir(self): try: From 21565dd256f328bdb3e15dafee070d628cc167a8 Mon Sep 17 00:00:00 2001 From: Herbert Poeckl Date: Tue, 11 Sep 2018 16:43:55 +0200 Subject: [PATCH 2/4] update README --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 1abbfdb..318e1f5 100644 --- a/README.rst +++ b/README.rst @@ -60,7 +60,6 @@ You can also specify the following options: * --out-file: Log file for innobackupex output (default: */var/log/mysql/xtrabackup.out*). * --backup-threads: You can specify more threads in order to backup quicker (default: 1). * --no-compress: Do not compress the backup archive. -* --no-service-stop: Don't stop mysqld service during restore process. * --webhook: URL to send a POST request after the backup is finished. Will send the *archive_path* and *archive_repository* in JSON. Restoration @@ -121,6 +120,7 @@ You can also specify the following options: * --log-file: Log file for the script (default: */var/log/mysql/pyxtrabackup-inc.log*). * --out-file: Log file for innobackupex output (default: */var/log/mysql/xtrabackup.out*). * --backup-threads: You can specify more threads in order to backup quicker (default: 1). +* --no-service-stop: Don't stop mysqld service during restore process. * --no-compress: Do not compress the backup archives. @@ -130,7 +130,7 @@ Restoration *WARNING*: The folder structure and the file names created by the *pyxtrabackup-inc* binary needs to be respected in order to restore successfully: * TIMESTAMP_FOLDER/INC/base_backup_DATETIME.tar(.gz) - * TIMESTAMP_FOLDER/INC/inc_1_backup_DATETIME.tar(.gz) + * TIMESTAMP_FOLDER/INC/inc_0_backup_DATETIME.tar(.gz) * TIMESTAMP_FOLDER/INC/inc_N_backup_DATETIME.tar(.gz) To restore an incremental backup, you'll need to use the *pyxtrabackup-restore* binary the following way: :: @@ -147,7 +147,7 @@ For example, using the following parameters: :: $ pyxtrabackup-restore --base-archive=/tmp/repo/20140518/INC/base_backup_20140518_1700.tar.gz --incremental-archive=/tmp/repo/20140518/INC/inc_backup_5_20140518_2200.gz --user=backup-user -The script will restore the inc_N_backup_DATETIME.tar.gz from 1 to 5. +The script will restore the inc_N_backup_DATETIME.tar.gz from 0 to 5. Additional options ^^^^^^^^^^^^^^^^^^ From 761a1d931aa1d880dac8c5a8bc88cdcca39d4f62 Mon Sep 17 00:00:00 2001 From: Herbert Poeckl Date: Thu, 13 Sep 2018 11:45:41 +0200 Subject: [PATCH 3/4] Update README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 318e1f5..e8ab253 100644 --- a/README.rst +++ b/README.rst @@ -120,7 +120,6 @@ You can also specify the following options: * --log-file: Log file for the script (default: */var/log/mysql/pyxtrabackup-inc.log*). * --out-file: Log file for innobackupex output (default: */var/log/mysql/xtrabackup.out*). * --backup-threads: You can specify more threads in order to backup quicker (default: 1). -* --no-service-stop: Don't stop mysqld service during restore process. * --no-compress: Do not compress the backup archives. @@ -160,6 +159,7 @@ You can also specify the following options: * --log-file: Log file for the script (default: */var/log/mysql/pyxtrabackup-restore.log*). * --out-file: Log file for innobackupex output (default: */var/log/mysql/xtrabackup.out*). * --backup-threads: You can specify more threads in order to backup quicker (default: 1). +* --no-service-stop: Don't stop mysqld service during restore process. * --uncompressed-archives: Do not try to uncompress backup archives. Use this option if you used the backup tool with --no-compress. From bf170e6870025e6f3afd50217a381df10eb8b1a2 Mon Sep 17 00:00:00 2001 From: Herbert Poeckl Date: Wed, 19 Dec 2018 21:23:36 +0100 Subject: [PATCH 4/4] make sure the --redo-only option is called befor the backup_directory --- xtrabackup/command_executor.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/xtrabackup/command_executor.py b/xtrabackup/command_executor.py index b216d3a..f0d0e50 100644 --- a/xtrabackup/command_executor.py +++ b/xtrabackup/command_executor.py @@ -45,12 +45,17 @@ def exec_incremental_backup(self, user, password, self.exec_command(command) def exec_backup_preparation(self, backup_directory, redo_logs): - command = [ - 'innobackupex', - '--apply-log', - backup_directory] if redo_logs: - command.append('--redo-only') + command = [ + 'innobackupex', + '--apply-log', + '--redo-only', + backup_directory] + else: + command = [ + 'innobackupex', + '--apply-log', + backup_directory] self.exec_command(command) def exec_incremental_preparation(self, backup_directory,