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

Release v2.0.3 #450

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v2.0.3 (2021-10-03)

* , #449 by @ShahriyarR
* , #448 by @ShahriyarR

## v2.0.2 (2021-05-06)

* Increased code coverage and did code base refactoring, #444 by @shahriyarr
Expand Down
24 changes: 19 additions & 5 deletions mysql_autoxtrabackup/autoxtrabackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from mysql_autoxtrabackup.backup_prepare.prepare import Prepare
from mysql_autoxtrabackup.general_conf import path_config
from mysql_autoxtrabackup.general_conf.generalops import GeneralClass
from mysql_autoxtrabackup.general_conf.generate_default_conf import (
GenerateDefaultConfig,
)
from mysql_autoxtrabackup.process_runner.process_runner import ProcessRunner
from mysql_autoxtrabackup.utils import version

Expand Down Expand Up @@ -103,12 +106,11 @@ def validate_file(file: str) -> Optional[bool]:
# filename extension should be .cnf
pattern = re.compile(r".*\.cnf")

if pattern.match(file):
# Lastly the file should have all 5 required headers
if check_file_content(file):
return None
else:
if not pattern.match(file):
raise ValueError("Invalid file extension. Expecting .cnf")
# Lastly the file should have all 5 required headers
if check_file_content(file):
return None
return None


Expand All @@ -133,6 +135,12 @@ def validate_file(file: str) -> Optional[bool]:
show_default=True,
help="Read options from the given file",
)
@click.option(
"--generate-config-file",
is_flag=True,
is_eager=True,
help="Create a config file template in default directory",
)
@click.option("--tag", help="Pass the tag string for each backup")
@click.option("--show-tags", is_flag=True, help="Show backup tags and exit")
@click.option("-v", "--verbose", is_flag=True, help="Be verbose (print to console)")
Expand Down Expand Up @@ -188,6 +196,7 @@ def all_procedure(
log_file,
log,
defaults_file,
generate_config_file,
dry_run,
log_file_max_bytes,
log_file_backup_count,
Expand Down Expand Up @@ -256,6 +265,7 @@ def all_procedure(
and dry_run is False
and show_tags is False
and run_server is False
and generate_config_file is False
):
print_help(ctx, None, value=True)

Expand All @@ -264,6 +274,10 @@ def all_procedure(
elif show_tags and defaults_file:
backup_ = Backup(config=defaults_file)
backup_.show_tags(backup_dir=str(backup_options.get("backup_dir")))
elif generate_config_file:
gen_ = GenerateDefaultConfig()
gen_.generate_config_file()
logger.info(f"Default config file is generated in {defaults_file}")
elif prepare:
prepare_ = Prepare(config=defaults_file, dry_run=dry_run_, tag=tag)
prepare_.prepare_backup_and_copy_back()
Expand Down
9 changes: 9 additions & 0 deletions mysql_autoxtrabackup/backup_backup/backup_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mysql_autoxtrabackup.backup_backup.backup_builder import BackupBuilderChecker
from mysql_autoxtrabackup.general_conf import path_config
from mysql_autoxtrabackup.general_conf.generalops import GeneralClass
from mysql_autoxtrabackup.process_runner.errors import BackupArchiveNotConfigured
from mysql_autoxtrabackup.process_runner.process_runner import ProcessRunner
from mysql_autoxtrabackup.utils import helpers

Expand Down Expand Up @@ -126,6 +127,14 @@ def clean_old_archives(self) -> None:
archive_dir = str(self.backup_archive_options.get("archive_dir"))
# Finding if last full backup older than the interval or more from now!
cleanup_msg = "Removing archive {}/{} due to {}"
if not self.backup_archive_options.get(
"archive_max_duration", None
) and not self.backup_archive_options.get("archive_max_size", None):
raise BackupArchiveNotConfigured(
expression="BackupArchiveNotConfigured",
message="You need to both set archive_max_size and archive_max_duration in config file.",
)

for archive in helpers.sorted_ls(archive_dir):
if "_archive" in archive:
archive_date = datetime.strptime(archive, "%Y-%m-%d_%H-%M-%S_archive")
Expand Down
18 changes: 8 additions & 10 deletions mysql_autoxtrabackup/general_conf/generalops.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,21 @@ def backup_archive_options(self) -> Dict[str, Union[str, float]]:
archive_max_size = self.con.get(section, "max_archive_size", fallback=None)
if archive_max_size:
archive_max_size = humanfriendly.parse_size(archive_max_size)
else:
if self.con.get(section, "archive_max_size", fallback=None):
archive_max_size = humanfriendly.parse_size(
self.con.get(section, "archive_max_size", fallback=None)
)
elif self.con.get(section, "archive_max_size", fallback=None):
archive_max_size = humanfriendly.parse_size(
self.con.get(section, "archive_max_size", fallback=None)
)

# backward compatible with old config 'max_archive_duration' and newer 'archive_max_duration'
archive_max_duration = self.con.get(
section, "max_archive_duration", fallback=None
)
if archive_max_duration:
archive_max_duration = humanfriendly.parse_timespan(archive_max_duration)
else:
if self.con.get(section, "archive_max_size", fallback=None):
archive_max_duration = humanfriendly.parse_timespan(
self.con.get(section, "archive_max_size", fallback=None)
)
elif self.con.get(section, "archive_max_duration", fallback=None):
archive_max_duration = humanfriendly.parse_timespan(
self.con.get(section, "archive_max_duration", fallback=None)
)

return {
"archive_dir": self.con.get(section, "archive_dir", fallback=None), # type: ignore
Expand Down
11 changes: 11 additions & 0 deletions mysql_autoxtrabackup/process_runner/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ def __init__(self, expression: str, message: str) -> None:
self.expression = expression
self.message = message
log_error(self.expression, self.message)


class BackupArchiveNotConfigured(Error):
"""
Exception raised when archive_max_size and archive_max_duration configs are not set
"""

def __init__(self, expression: str, message: str) -> None:
self.expression = expression
self.message = message
log_error(self.expression, self.message)
2 changes: 1 addition & 1 deletion mysql_autoxtrabackup/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = "VERSION"

VERSION = "2.0.2"
VERSION = "2.0.3"