Browse Source

Automatically prune the inventory backup

The inventory backup process takes the running inventory json file and
adds it to a tar archive. This process has no limits and will add files
to the tar archive until that is no longer possible and limited by the
underlying operating system. This change automatically prunes the backup
file and retains only the last 15 inventory files. This should provide
the same backup capabilities we've had without trying to saving
archives indefinitely.

> It should be noted that this change is using a subprocess call to
  prune the tar file. This is being done because the "tarfile" library
  does not provide an interface for deleting a file within an archive.

Change-Id: Ida5a9be0d0910c223fe05401bc4f75aef100e456
Closes-Bug: #1750233
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
tags/19.0.0.0rc1
Kevin Carter 1 year ago
parent
commit
ac28ad1329

+ 16
- 1
osa_toolkit/filesystem.py View File

@@ -21,10 +21,12 @@ import datetime
21 21
 import json
22 22
 import logging
23 23
 import os
24
-from osa_toolkit import dictutils as du
24
+import subprocess
25 25
 import tarfile
26 26
 import yaml
27 27
 
28
+from osa_toolkit import dictutils as du
29
+
28 30
 
29 31
 logger = logging.getLogger('osa-inventory')
30 32
 
@@ -154,6 +156,19 @@ def _make_backup(backup_path, source_file_path):
154 156
         'backup_openstack_inventory.tar'
155 157
     )
156 158
     with tarfile.open(inventory_backup_file, 'a') as tar:
159
+        # tar.getmembers() is always ordered with the
160
+        # tar standard append file order
161
+        members = [i.name for i in tar.getmembers()]
162
+        if len(members) > 15:
163
+            with open(os.devnull, 'w') as null:
164
+                for member in members[:-15]:
165
+                    subprocess.call(
166
+                        ['tar', '-vf', inventory_backup_file,
167
+                         '--delete', member],
168
+                        stdout=null,
169
+                        stderr=subprocess.STDOUT
170
+                    )
171
+
157 172
         basename = os.path.basename(source_file_path)
158 173
         backup_name = _get_backup_name(basename)
159 174
         tar.add(source_file_path, arcname=backup_name)

+ 7
- 0
releasenotes/notes/limit-inventory-backkups.yaml-c96577e9de284cf2.yaml View File

@@ -0,0 +1,7 @@
1
+---
2
+
3
+issues:
4
+ - We are limiting the tarred inventory backups to 15 in addition to changes
5
+   that only apply backups when the config has changed. These changes are to
6
+   address an issue where the inventory was corruped with parallel runs on
7
+   large clusters.

Loading…
Cancel
Save