source: people/joerg.steffens/technical/bareos/triggerjob/purge.py@ 1241

Last change on this file since 1241 was 1232, checked in by joergs, on Jan 26, 2017 at 6:02:00 PM

purge and truncate volumes

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2
3from __future__ import print_function
4import argparse
5import bareos.bsock
6import logging
7import sys
8
9def get_volumes(director):
10 result = director.call('list volumes all')['volumes']
11 volumes = [ volume['volumename'] for volume in result ]
12 return volumes
13
14def prune_and_truncate_volumes(director):
15 for volume in get_volumes(director):
16 director.call('prune volume={} yes'.format(volume))
17 director.call('truncate volstatus=Purged yes')
18
19def getArguments():
20 parser = argparse.ArgumentParser(description='Console to Bareos Director.' )
21 parser.add_argument('-d', '--debug', action='store_true', help="enable debugging output")
22 parser.add_argument('--name', default="*UserAgent*", help="use this to access a specific Bareos director named console. Otherwise it connects to the default console (\"*UserAgent*\")")
23 parser.add_argument('-p', '--password', help="password to authenticate to a Bareos Director console", required=True)
24 parser.add_argument('--port', default=9101, help="Bareos Director network port")
25 parser.add_argument('--dirname', help="Bareos Director name")
26 parser.add_argument('address', nargs='?', default="localhost", help="Bareos Director network address")
27 args = parser.parse_args()
28 return args
29
30if __name__ == '__main__':
31 logging.basicConfig(format='%(levelname)s %(module)s.%(funcName)s: %(message)s', level=logging.INFO)
32 logger = logging.getLogger()
33
34 args=getArguments()
35 if args.debug:
36 logger.setLevel(logging.DEBUG)
37
38 try:
39 options = [ 'address', 'port', 'dirname', 'name' ]
40 parameter = {}
41 for i in options:
42 if hasattr(args, i) and getattr(args,i) != None:
43 logger.debug( "%s: %s" %(i, getattr(args,i)))
44 parameter[i] = getattr(args, i)
45 else:
46 logger.debug( '%s: ""' %(i))
47 logger.debug('options: %s' % (parameter))
48 password = bareos.bsock.Password(args.password)
49 parameter['password']=password
50 director = bareos.bsock.DirectorConsoleJson(**parameter)
51 except RuntimeError as e:
52 print(str(e))
53 sys.exit(1)
54 logger.debug( "authentication successful" )
55 get_empty_volumes(director)
Note: See TracBrowser for help on using the repository browser.