Increase AdminJob support for cinder mode backup

Currently, when use 'freezer-agent --action admin --remove-older-than
xx --mode cinder --cinder-vol-id xx --storage xx --container xx' to
remove the old backups, the result is successful, but the backup data
is not really deleted. This path will increase AdminJob support for
cinder mode backup and fix the issue.

Change-Id: I8c9bb86a6d6d82f0609f340df42e220204794940
Closes-Bug: #1701422
This commit is contained in:
Pengju Jiao 2017-06-30 16:17:40 +08:00
parent f8060ae001
commit df1119174d
2 changed files with 48 additions and 4 deletions

View File

@ -421,6 +421,14 @@ class AdminJob(Job):
datetime.timedelta(days=float(self.conf.remove_older_than))
timestamp = int(time.mktime(timestamp.timetuple()))
if self.conf.backup_media == 'cinder':
old_backups = self.get_cinder_old_backups(
timestamp,
self.conf.cinder_vol_id
)
self.remove_backup_dirs(old_backups, self.conf.cinder_vol_id)
return {}
hostname_backup_name_set = set()
if self.conf.backup_media == 'nova':
@ -445,6 +453,40 @@ class AdminJob(Job):
backup_name)
return {}
def get_cinder_old_backups(self, timestamp, cinder_vol_id):
path_to_list = self.get_path_prefix(cinder_vol_id)
old_backups = []
backup_dirs = self.storage.listdir(path_to_list)
for backup_dir in backup_dirs:
if int(backup_dir) <= int(timestamp):
old_backups.append(backup_dir)
return old_backups
def remove_backup_dirs(self, backups_to_remove, cinder_vol_id):
path_prefix = self.get_path_prefix(cinder_vol_id)
for backup_to_remove in backups_to_remove:
path_to_remove = "{0}/{1}".format(path_prefix, backup_to_remove)
LOG.info("Remove backup: {0}".format(path_to_remove))
self.storage.rmtree(path_to_remove)
def get_path_prefix(self, cinder_vol_id):
if self.storage.type == 'swift':
path_prefix = "{0}/{1}/{2}".format(
self.storage.container,
self.storage.segments,
cinder_vol_id
)
elif self.storage.type in ['local', 'ssh', 's3']:
path_prefix = "{0}/{1}".format(
self.storage.storage_path,
cinder_vol_id
)
else:
path_prefix = ''
return path_prefix
class ExecJob(Job):

View File

@ -226,12 +226,14 @@ class SwiftStorage(physical.PhysicalStorage):
# split[0] = freezer_backups which is container name
# split[1] = tar/server1.cloud.com_testest/
split = path.split('/', 1)
files = self.swift().get_container(container=split[0],
full_listing=True,
prefix=split[1])[1]
files = self.swift().get_container(
container=split[0],
full_listing=True,
prefix="{0}/".format(split[1]),
delimiter='/')[1]
# @todo normalize intro plain for loop to be easily
# understandable (szaher)
return set(f['name'][len(split[1]):].split('/', 2)[1] for f in
return set(f['subdir'].rsplit('/', 2)[1] for f in
files)
except Exception as e:
LOG.info(e)