Blame SOURCES/0006-backup-global-option-to-tune-max-no.-of-backup-conf-.patch

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