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

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