Merge "Automatically prune the inventory backup"
This commit is contained in:
commit
c8619eed66
@ -21,10 +21,12 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from osa_toolkit import dictutils as du
|
import subprocess
|
||||||
import tarfile
|
import tarfile
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from osa_toolkit import dictutils as du
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('osa-inventory')
|
logger = logging.getLogger('osa-inventory')
|
||||||
|
|
||||||
@ -154,6 +156,19 @@ def _make_backup(backup_path, source_file_path):
|
|||||||
'backup_openstack_inventory.tar'
|
'backup_openstack_inventory.tar'
|
||||||
)
|
)
|
||||||
with tarfile.open(inventory_backup_file, 'a') as tar:
|
with tarfile.open(inventory_backup_file, 'a') as tar:
|
||||||
|
# tar.getmembers() is always ordered with the
|
||||||
|
# tar standard append file order
|
||||||
|
members = [i.name for i in tar.getmembers()]
|
||||||
|
if len(members) > 15:
|
||||||
|
with open(os.devnull, 'w') as null:
|
||||||
|
for member in members[:-15]:
|
||||||
|
subprocess.call(
|
||||||
|
['tar', '-vf', inventory_backup_file,
|
||||||
|
'--delete', member],
|
||||||
|
stdout=null,
|
||||||
|
stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
|
||||||
basename = os.path.basename(source_file_path)
|
basename = os.path.basename(source_file_path)
|
||||||
backup_name = _get_backup_name(basename)
|
backup_name = _get_backup_name(basename)
|
||||||
tar.add(source_file_path, arcname=backup_name)
|
tar.add(source_file_path, arcname=backup_name)
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
issues:
|
||||||
|
- We are limiting the tarred inventory backups to 15 in addition to changes
|
||||||
|
that only apply backups when the config has changed. These changes are to
|
||||||
|
address an issue where the inventory was corruped with parallel runs on
|
||||||
|
large clusters.
|
Loading…
Reference in New Issue
Block a user