Commit d917cf23 authored by Kristian Feldsam's avatar Kristian Feldsam

Prune old backups

Signed-off-by: Kristian Feldsam's avatarKristián Feldsam <feldsam@gmail.com>
parent 3a119997
......@@ -169,6 +169,13 @@ def backup_live(one, image, vm, vm_disk_id, verbose):
if not one.vm.disksnapshotdelete(vm.ID, vm_disk_id, snap_id):
raise Exception('Can not delete snapshot! Check VM logs.')
# prune old backups
if verbose:
print 'Pruning old backups...'
result = borgprune(name)
if verbose:
print result
def backup(image, verbose):
# get source name and wwn
......@@ -209,6 +216,13 @@ def backup(image, verbose):
print 'Unexporting volume %s from backup server...' % name
unexport_vv(name, config.EXPORT_HOST)
# prune old backups
if verbose:
print 'Pruning old backups...'
result = borgprune(name)
if verbose:
print result
def borgbackup(name, dev, size_mb):
size = size_mb*1024*1024
......@@ -216,4 +230,12 @@ def borgbackup(name, dev, size_mb):
try:
return subprocess.check_output('dd if=%s bs=256K | pv -pterab -s %d | borg create --compression auto,zstd,3 %s::%s-{now} -' % (dev, size, config.BACKUP_REPO, name), shell=True)
except subprocess.CalledProcessError as ex:
raise Exception('Can not backup dev using borgbackup!', ex)
\ No newline at end of file
raise Exception('Can not backup dev using borgbackup!', ex)
def borgprune(name):
try:
return subprocess.check_output('borg prune -v --list --stats --keep-daily=7 --keep-weekly=4 --keep-monthly=6 --prefix=%s %s' % (name, config.BACKUP_REPO), shell=True)
except subprocess.CalledProcessError as ex:
raise Exception('Can not run borg prune!', ex)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment