def run(self, args, config, storage, remotes): table_lines = [('', '<b>NAME</b>', '<b>START DATE</b>', '<b>DURATION</b>')] pattern = '%s/*' % args.remote if args.remote else None for label, backup in sorted(storage.list_backups(pattern=pattern, since=args.since, until=args.until), key=ORDERS[args.order]): flags = [] if backup.parent: flags.append('<b>P</b>') if backup.errors: flags.append('<color fg=red><b>E</b></color>') # Extract remote from backup name: name = label split_name = label.split('/', 1) if len(split_name) == 2 and remotes.get(split_name[0]): name = '<b>%s</b>/%s' % tuple(split_name) else: flags.append('<b>O</b>') table_lines.append( (''.join(flags), name, backup.start_date.format(DATE_FORMAT), str(backup.duration))) printer.table(table_lines) printer.p('\nFlags: <b>P</b> have parent, ' '<color fg=red><b>E</b></color> - have errors, ' '<b>O</b> orphan backup')
def run(self, args, config, storage, remotes): remote = remotes.get(args.remote) backup_label = '%s/%s' % (remote.name, args.name) if not args.overwrite and storage.resolve(backup_label): raise RuntimeError('A backup with this name already exists for this remote') if args.parent: parent = '%s/%s' % (remote.name, args.parent) else: parent = None ref, backup = create_backup(storage, remote, parent=parent) # Create labels for the new backup: storage.set_label(backup_label, ref) storage.set_label('%s/latest' % remote.name, ref) printer.p('<b>Duration:</b> {d}', d=backup.duration) printer.p('<b>Root:</b> {r}', r=backup.root) if backup.errors: printer.hr() printer.p('<b>{n} errors:</b>', n=len(backup.errors)) printer.p() for filename, error in backup.errors.items(): printer.p(' - <b>{fn}</b>: {error}', fn=filename.decode('utf-8', 'replace'), error=error) if args.stats: printer.hr() printer.table(backup.stats_table(), fixed_width=80, center=True) printer.p()
def run(self, args, config, storage, remotes): table_lines = [('<b>NAME</b>', '<b>TYPE</b>', '<b>LAST</b>', '<b>NEXT</b>', '<b>LAST SIZE</b>')] for remote in sorted(remotes.list(), key=lambda x: x.name): latest_ref = '%s/latest' % remote.name latest_backup = storage.get_backup(latest_ref) latest_date_text = '-' next_date_text = '-' size = '-' if latest_backup is None: if remote.scheduler is not None: next_date_text = '<color fg=yellow>now</color>' else: size_total = sum(latest_backup.stats.get(x, 0) for x in STATS_TOTAL) size_new = sum(latest_backup.stats.get(x, 0) for x in STATS_NEW) size = '%s (+%s)' % (humanize.naturalsize(size_total, binary=True), humanize.naturalsize(size_new, binary=True)) latest_date_text = latest_backup.start_date.humanize() if remote.scheduler is not None and remote.scheduler['enabled']: next_date = latest_backup.start_date + datetime.timedelta(seconds=remote.scheduler['interval'] * 60) if next_date > arrow.now(): next_date_text = '<color fg=green>%s</color>' % next_date.humanize() else: next_date_text = '<color fg=red>%s</color>' % next_date.humanize() table_lines.append((remote.name, remote.type, latest_date_text, next_date_text, size)) printer.table(table_lines)
def run(self, args, config, storage, remotes): name = '%s/%s' % (args.remote, args.name) if args.remote else args.name tree = storage.get_tree(name) table_lines = [('<b>NAME</b>', '<b>TYPE</b>', '<b>REF</b>', '<b>ATTRIBUTES</b>')] for name, details in sorted(tree.items()): name = '<b>%s</b>' % name.decode('utf-8', 'replace') type = details.pop('type', '') ref = details.pop('ref', '') fmt = '<color fg=green>%s</color>:<color fg=cyan>%s</color>' attributes = ' '.join(fmt % (k, v) for k, v in sorted(list(details.items()), key=tree_attr_sorter)) table_lines.append((name, type, ref, attributes)) printer.table(table_lines)
def run(self, args, config, storage, remotes): remote = remotes.get(args.remote) if remote is None: raise RuntimeError('Given remote (%s) does not exist' % args.remote) backup_label = '%s/%s' % (remote.name, args.name) if not args.overwrite and storage.resolve(backup_label): raise RuntimeError( 'A backup with this name already exists for this remote') if args.parent: parent = '%s/%s' % (remote.name, args.parent) else: parent = None ref, backup = create_backup(storage, remote, parent=parent) # Create labels for the new backup: storage.set_label(backup_label, ref) storage.set_label('%s/latest' % remote.name, ref) printer.p('<b>Duration:</b> {d}', d=backup.duration) printer.p('<b>Root:</b> {r}', r=backup.root) if backup.errors: printer.hr() printer.p('<b>{n} errors:</b>', n=len(backup.errors)) printer.p() for filename, error in backup.errors.items(): printer.p(' - <b>{fn}</b>: {error}', fn=filename.decode('utf-8', 'replace'), error=error) if args.stats: printer.hr() printer.table(backup.stats_table(), fixed_width=80, center=True) printer.p()
def run(self, args, config, storage, remotes): name = '%s/%s' % (args.remote, args.name) if args.remote else args.name backup = storage.get_backup(name) printer.p('<b>Date:</b> {s} -> {e} ({d})', s=backup.start_date.format('DD/MM/YYYY HH:mm:ss'), e=backup.end_date.format('DD/MM/YYYY HH:mm:ss'), d=backup.duration) printer.p('<b>Root:</b> {r}', r=backup.root) if backup.parent: printer.p('<b>Parent:</b> {b}', b=backup.parent) if backup.errors: printer.hr() printer.p('<b>{n} errors:</b>', n=len(backup.errors)) printer.p() for filename, error in list(backup.errors.items()): printer.p(' - <b>{fn}</b>: {error}', fn=filename.decode('utf-8', 'replace'), error=error) printer.p() printer.p('-' * 80) printer.p() printer.table(backup.stats_table(), fixed_width=80, center=True) printer.p()