Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 51afdd4

Browse files
Shahriyar Rzayevgitmstoute
andauthored
release_v1.5.5 (#347)
* Version bump * Bugfix issue345 (#346) * Config accepts both max_archive_[size/duration] OR archive_max_[size/duration], for backward compatibility * update comparison to use archive_max_[size/duration] * update variable names in test config generator (archive_max_[size/duration]) * Fixed #307 * update logging format to include module/line# * create process_runner / ProcessRunner class * use ProcessRunner for prepare statements. * use ProcessRunner for Backup statements; update add_tag() function to require fewer arguments. closes #307 * include process_runner module in setup.py * Update process_runner.py * fix add_tag() logic * Updating some portions (#352) * update pigz test so it will return exitcode 0 for ProcessRunner to function. update 2 incorrect calls to ProcessRunner(). (#357) * small updates to logging in autoxtrabackup.py (#359) * logging debug -> info for most modules (#360) * subprocess str -> args update; upgrade to subprocess logging; update subprocess calls with '--password=' string; log a subprocess summary on quit; (#362) * Removed redundant dependency package Co-authored-by: gitmstoute <mstoute@eyereturn.com>
1 parent a0cdd65 commit 51afdd4

14 files changed

Lines changed: 740 additions & 726 deletions

File tree

autoxtrabackup.py

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
import click
2-
from master_backup_script.backuper import Backup
3-
from backup_prepare.prepare import Prepare
4-
from partial_recovery.partial import PartialRecovery
5-
from general_conf.generalops import GeneralClass
6-
from prepare_env_test_mode.runner_test_mode import RunnerTestMode
7-
from sys import platform as _platform
8-
from sys import exit
9-
import pid
10-
import time
11-
import re
12-
import os
132
import humanfriendly
143
import logging
154
import logging.handlers
5+
import os
6+
import pid
7+
import re
8+
import time
9+
import sys
10+
1611
from logging.handlers import RotatingFileHandler
17-
from general_conf import path_config
12+
from sys import platform as _platform
13+
from sys import exit
1814

19-
logger = logging.getLogger('')
15+
from backup_prepare.prepare import Prepare
16+
from general_conf.generalops import GeneralClass
17+
from general_conf import path_config
18+
from master_backup_script.backuper import Backup
19+
from partial_recovery.partial import PartialRecovery
20+
from prepare_env_test_mode.runner_test_mode import RunnerTestMode
21+
from process_runner.process_runner import ProcessRunner
2022

2123

22-
destinations_hash = {'linux':'/dev/log', 'linux2': '/dev/log', 'darwin':'/var/run/syslog'}
24+
logger = logging.getLogger('')
25+
destinations_hash = {'linux': '/dev/log', 'linux2': '/dev/log', 'darwin': '/var/run/syslog'}
2326

2427

2528
def address_matcher(plt):
@@ -38,6 +41,7 @@ def print_help(ctx, param, value):
3841
click.echo(ctx.get_help())
3942
ctx.exit()
4043

44+
4145
def print_version(ctx, param, value):
4246
if not value or ctx.resilient_parsing:
4347
return
@@ -47,7 +51,7 @@ def print_version(ctx, param, value):
4751
click.echo("Email: rzayev.shahriyar@yandex.com")
4852
click.echo(
4953
"Based on Percona XtraBackup: https://github.com/percona/percona-xtrabackup/")
50-
click.echo('MySQL-AutoXtraBackup Version: 1.5.4')
54+
click.echo('MySQL-AutoXtraBackup Version: 1.5.5')
5155
ctx.exit()
5256

5357

@@ -94,7 +98,7 @@ def validate_file(file):
9498
configuration file, throw error.
9599
"""
96100
if os.path.isfile(file):
97-
# filename extension should be .conf
101+
# filename extension should be .cnf
98102
pattern = re.compile(r'.*\.cnf')
99103

100104
if pattern.match(file):
@@ -141,7 +145,7 @@ def validate_file(file):
141145
@click.option('-l',
142146
'--log',
143147
'--log-level',
144-
default='DEBUG',
148+
default='INFO',
145149
show_default=True,
146150
type=click.Choice(['DEBUG',
147151
'INFO',
@@ -177,21 +181,23 @@ def validate_file(file):
177181
expose_value=False,
178182
is_eager=False,
179183
help="Print help message and exit.")
184+
185+
180186
@click.pass_context
181187
def all_procedure(ctx, prepare, backup, partial, tag, show_tags,
182188
verbose, log_file, log, defaults_file,
183189
dry_run, test_mode, log_file_max_bytes,
184190
log_file_backup_count, keyring_vault):
191+
185192
config = GeneralClass(defaults_file)
186-
if config.log_level:
187-
logger.setLevel(config.log_level)
188-
else:
189-
logger.setLevel(log)
190-
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s',
193+
194+
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s [%(module)s:%(lineno)d] %(message)s',
191195
datefmt='%Y-%m-%d %H:%M:%S')
192196

193197
if verbose:
194198
ch = logging.StreamHandler()
199+
# control console output log level
200+
ch.setLevel(logging.INFO)
195201
ch.setFormatter(formatter)
196202
logger.addHandler(ch)
197203

@@ -209,25 +215,36 @@ def all_procedure(ctx, prepare, backup, partial, tag, show_tags,
209215
except PermissionError as err:
210216
exit("{} Please consider to run as root or sudo".format(err))
211217

218+
# set log level in order: 1. user argument 2. config file 3. @click default
219+
if log is not None:
220+
logger.setLevel(log)
221+
elif 'log_level' in config.__dict__:
222+
logger.setLevel(config.log_level)
223+
else:
224+
# this is the fallback default log-level.
225+
logger.setLevel('INFO')
226+
212227
validate_file(defaults_file)
213228
pid_file = pid.PidFile(piddir=config.pid_dir)
214229

215230
try:
216231
with pid_file: # User PidFile for locking to single instance
217232
if (prepare is False and
218-
backup is False and
219-
partial is False and
220-
verbose is False and
221-
dry_run is False and
222-
test_mode is False and
223-
show_tags is False):
233+
backup is False and
234+
partial is False and
235+
verbose is False and
236+
dry_run is False and
237+
test_mode is False and
238+
show_tags is False):
224239
print_help(ctx, None, value=True)
240+
225241
elif show_tags and defaults_file:
226242
b = Backup(config=defaults_file)
227243
b.show_tags(backup_dir=b.backupdir)
244+
228245
elif test_mode and defaults_file:
229246
logger.warning("Enabled Test Mode!!!")
230-
logger.debug("Starting Test Mode")
247+
logger.info("Starting Test Mode")
231248
test_obj = RunnerTestMode(config=defaults_file)
232249
for basedir in test_obj.basedirs:
233250
if ('5.7' in basedir) and ('2_4_ps_5_7' in defaults_file):
@@ -315,6 +332,11 @@ def all_procedure(ctx, prepare, backup, partial, tag, show_tags,
315332
except pid.PidFileError as error:
316333
logger.warning("Generic error with pid file: " + str(error))
317334

335+
logger.info("Xtrabackup command history:")
336+
for i in ProcessRunner.xtrabackup_history_log:
337+
logger.info(str(i))
338+
logger.info("Autoxtrabackup completed successfully!")
339+
return True
318340

319341
if __name__ == "__main__":
320342
all_procedure()

0 commit comments

Comments
 (0)