From bf75323d7d678f01c21d0c9825bd55553727e934 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 15 Dec 2017 17:23:25 +0530 Subject: [PATCH] backup: global option to tune max no. of backup conf files Eg: /> set global max_backup_files=1000 Parameter max_backup_files is now '1000'. If 'max_backup_files' is set in /etc/target/targetcli.conf, then max value between conf file setting and global option settings is considered. Signed-off-by: Prasanna Kumar Kalever --- scripts/targetcli | 1 + targetcli/ui_node.py | 3 +++ targetcli/ui_root.py | 8 +++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/targetcli b/scripts/targetcli index 5404fcd..371edbe 100755 --- a/scripts/targetcli +++ b/scripts/targetcli @@ -49,6 +49,7 @@ class TargetCLI(ConfigShell): 'auto_add_mapped_luns': True, 'auto_cd_after_create': False, 'auto_save_on_exit': True, + 'max_backup_files': '10', 'auto_add_default_portal': True, } diff --git a/targetcli/ui_node.py b/targetcli/ui_node.py index c91dae2..a6982f1 100644 --- a/targetcli/ui_node.py +++ b/targetcli/ui_node.py @@ -46,6 +46,9 @@ class UINode(ConfigNode): self.define_config_group_param( 'global', 'auto_add_default_portal', 'bool', 'If true, adds a portal listening on all IPs to new targets.') + self.define_config_group_param( + 'global', 'max_backup_files', 'string', + 'Max no. of configurations to be backed up in /etc/target/backup/ directory.') def assert_root(self): ''' diff --git a/targetcli/ui_root.py b/targetcli/ui_root.py index f84d33d..a54845f 100644 --- a/targetcli/ui_root.py +++ b/targetcli/ui_root.py @@ -35,7 +35,6 @@ from .ui_target import UIFabricModule default_save_file = "/etc/target/saveconfig.json" universal_prefs_file = "/etc/target/targetcli.conf" -default_kept_backups = 10 class UIRoot(UINode): ''' @@ -99,12 +98,15 @@ class UIRoot(UINode): if backup_error == None: # Kill excess backups + max_backup_files = int(self.shell.prefs['max_backup_files']) + try: with open(universal_prefs_file) as prefs: backups = [line for line in prefs.read().splitlines() if re.match('^max_backup_files\s*=', line)] - max_backup_files = int(backups[0].split('=')[1].strip()) + if max_backup_files < int(backups[0].split('=')[1].strip()): + max_backup_files = int(backups[0].split('=')[1].strip()) except: - max_backup_files = default_kept_backups + self.shell.log.debug("No universal prefs file '%s'." % universal_prefs_file) files_to_unlink = list(reversed(backed_files_list))[max_backup_files:] for f in files_to_unlink: -- 1.8.3.1