Commit 14102f60 authored by Kristian Feldsam's avatar Kristian Feldsam

Added prune only option + added check to borgprune def

Signed-off-by: Kristian Feldsam's avatarKristián Feldsam <feldsam@gmail.com>
parent d917cf23
......@@ -18,8 +18,9 @@ parser.add_argument('-S', '--startImage', help='Image id to start backup from. B
parser.add_argument('-a', '--datastore', help='Datastore id or comma separated list of datastore ids to backup from. Omit to backup from all datastores to backup', type=functions.list_of_int_arg)
parser.add_argument('-l', '--label', help='Label or comma separated list of labels of tagged images', type=functions.list_arg)
parser.add_argument('-e', '--exclude', help='Skip (exclude) by label or comma separated list of labels of tagged images', type=functions.list_arg)
parser.add_argument('-D', '--deployments', help='Backup also deployments files from system datastores', action='store_true')
parser.add_argument('-d', '--dryRun', help='Dry run - not execute any commands, all cmds will be just printed', action='store_true')
parser.add_argument('-P', '--pruneOnly', help='Don\'t backup anything, just prune old backups', action='store_true')
parser.add_argument('-D', '--deployments', help='Not implemented yet! Backup also deployments files from system datastores', action='store_true')
parser.add_argument('-d', '--dryRun', help='Not implemented yet! Dry run - not execute any commands, all cmds will be just printed', action='store_true')
parser.add_argument('-v', '--verbose', help='Verbose mode', action='store_true')
# -------------------------------------
......@@ -41,7 +42,8 @@ from drivers import _3par
_3par.login()
# starting backup
functions.send_email('Backup started! Images count: %d' % len(images))
if not args.pruneOnly:
functions.send_email('Backup started! Images count: %d' % len(images))
for image_key in images:
image = images[image_key]
......@@ -51,6 +53,15 @@ for image_key in images:
if datastore.TM_MAD != '3par':
continue
# prune only?
if args.pruneOnly:
try:
_3par.prune(image, args.verbose)
except Exception as ex:
print ex
functions.send_email('Error prune image %d:%s: "%s"' % (image.ID, image.NAME, ex))
continue
# mark start of backup in verbose output
if args.verbose:
print '#============================================================'
......
import os
import re
import subprocess
import sys
import time
......@@ -224,6 +225,18 @@ def backup(image, verbose):
print result
def prune(image, verbose):
# get source name and wwn
name, wwn = vv_name_wwn(image.SOURCE)
# 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
......@@ -234,6 +247,10 @@ def borgbackup(name, dev, size_mb):
def borgprune(name):
# check if name is defined, prevent deleting more that we want
if not re.match('^feldcloud\.one\.[0-9]+\.vv$', name):
raise Exception('Can not run borg prune!', 'Name doesn\'t match pattern. Should be in format feldcloud.one.[0-9]+.vv, given "%s"' % 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:
......
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