diff options
| author | Andy Grover <andy@groveronline.com> | 2017-12-20 11:19:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-20 11:19:58 -0800 |
| commit | 4bdcf113375f97311679994653bc01c65a0fcdff (patch) | |
| tree | 93186284ba1be546fe13dc4bb5c36fb218757661 /targetcli | |
| parent | 2f209d7749b12047be0c71469bb9b4f2ae2b6e9a (diff) | |
| parent | bf75323d7d678f01c21d0c9825bd55553727e934 (diff) | |
| download | targetcli-4bdcf113375f97311679994653bc01c65a0fcdff.tar.gz | |
Merge pull request #99 from pkalever/backuplimit
backup: global option to tune max no. of backup conf files
Diffstat (limited to 'targetcli')
| -rw-r--r-- | targetcli/ui_node.py | 3 | ||||
| -rw-r--r-- | targetcli/ui_root.py | 14 |
2 files changed, 11 insertions, 6 deletions
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 f398395..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,20 +98,23 @@ 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('^kept_backups\s*=', line)] - kept_backups = int(backups[0].split('=')[1].strip()) + backups = [line for line in prefs.read().splitlines() if re.match('^max_backup_files\s*=', line)] + if max_backup_files < int(backups[0].split('=')[1].strip()): + max_backup_files = int(backups[0].split('=')[1].strip()) except: - kept_backups = default_kept_backups + self.shell.log.debug("No universal prefs file '%s'." % universal_prefs_file) - files_to_unlink = list(reversed(backed_files_list))[kept_backups:] + files_to_unlink = list(reversed(backed_files_list))[max_backup_files:] for f in files_to_unlink: with ignored(IOError): os.unlink(f) self.shell.log.info("Last %d configs saved in %s." % \ - (kept_backups, backup_dir)) + (max_backup_files, backup_dir)) else: self.shell.log.warning("Could not create backup file %s: %s." % \ (backupfile, backup_error)) |
