diff --git a/autoxtrabackup.py b/autoxtrabackup.py index ce3d627f..dd04a31a 100644 --- a/autoxtrabackup.py +++ b/autoxtrabackup.py @@ -127,6 +127,8 @@ def validate_file(file): default='/etc/bck.conf', show_default=True, help="Read options from the given file") +@click.option('--tag', + help="Pass the tag string for each backup") @click.option('-v', '--verbose', is_flag=True, help="Be verbose (print to console)") @click.option('-lf', @@ -156,7 +158,7 @@ def validate_file(file): is_eager=False, help="Print help message and exit.") @click.pass_context -def all_procedure(ctx, prepare, backup, partial, verbose, log_file, log, defaults_file, dry_run, test_mode): +def all_procedure(ctx, prepare, backup, partial, tag, verbose, log_file, log, defaults_file, dry_run, test_mode): logger.setLevel(log) formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') diff --git a/master_backup_script/backuper.py b/master_backup_script/backuper.py index 8e13d21c..b4485644 100755 --- a/master_backup_script/backuper.py +++ b/master_backup_script/backuper.py @@ -24,12 +24,19 @@ class Backup(GeneralClass): - def __init__(self, config='/etc/bck.conf', dry_run=0): + def __init__(self, config='/etc/bck.conf', dry_run=0, tag=None): self.conf = config self.dry = dry_run + self.tag = tag # Call GeneralClass for storing configuration options super().__init__(self.conf) + @staticmethod + def add_tag(backup_dir, backup_name, type, tag_string): + with open('{}/backup_tags.txt'.format(backup_dir), 'w') as bcktags: + bcktags.write("{0}\t{1}\t{2}\n".format(backup_name, type, tag_string)) + pass + @staticmethod def sorted_ls(path): ''' diff --git a/test/conftest.py b/test/conftest.py index f284f378..6bb13cc5 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -3,6 +3,7 @@ from prepare_env_test_mode.run_benchmark import RunBenchmark from prepare_env_test_mode.config_generator import ConfigGenerator from prepare_env_test_mode.runner_test_mode import RunnerTestMode +from master_backup_script.backuper import Backup clb_obj = CloneBuildStartServer() diff --git a/test/test_backup.py b/test/test_backup.py new file mode 100644 index 00000000..f0b14af9 --- /dev/null +++ b/test/test_backup.py @@ -0,0 +1,14 @@ +# PyTest file for testing Backup class +from master_backup_script.backuper import Backup +from general_conf.generalops import GeneralClass + +class TestBackup: + + def test_add_tag(self): + # Method for checking the add_tag() static method. All parameters are hard coded. + gen_obj = GeneralClass() + for conf_files in gen_obj.xb_configs.split(): + if '2_3' in conf_files and '5_6' in conf_files: + obj = Backup(config='{}/{}'.format(gen_obj.testpath, conf_files), dry_run=0, tag="My first full backup") + backup_name = obj.recent_full_backup_file() + obj.add_tag(backup_dir=obj.backupdir, backup_name=backup_name, type=obj.tag) diff --git a/test/test_prepare_backup.py b/test/test_test_prepare_backup.py similarity index 97% rename from test/test_prepare_backup.py rename to test/test_test_prepare_backup.py index bc85a720..da67d76b 100644 --- a/test/test_prepare_backup.py +++ b/test/test_test_prepare_backup.py @@ -1,6 +1,7 @@ from general_conf.generalops import GeneralClass from prepare_env_test_mode.prepare_backup import WrapperForPrepareTest +# Part of TEST MODE class TestPrepareBackup: # class for prepare_env_test_mode.prepare_backup.py diff --git a/test/test_take_backup.py b/test/test_test_take_backup.py similarity index 95% rename from test/test_take_backup.py rename to test/test_test_take_backup.py index a17896f1..c25e184a 100644 --- a/test/test_take_backup.py +++ b/test/test_test_take_backup.py @@ -2,6 +2,8 @@ from prepare_env_test_mode.take_backup import WrapperForBackupTest from general_conf.generalops import GeneralClass +# Part of TEST MODE + class TestTakeBackup: # Test class for take_backup.py