add listing of backups and backends
This commit is contained in:
parent
00997464f1
commit
e5737f3af8
|
@ -43,12 +43,15 @@ class Application(object):
|
|||
self.stderr_handler.disable()
|
||||
|
||||
def get_due_backups(self):
|
||||
backups = self.config.configured_backups.backups_due()
|
||||
backups = self.config.configured_backup_set().backups_due()
|
||||
self.logger.info("Backups due: {}".format(", ".join([b.name for b in backups])))
|
||||
return backups
|
||||
|
||||
def get_all_backups(self):
|
||||
return self.config.configured_backups.all_backups()
|
||||
return self.config.all_configured_backups()
|
||||
|
||||
def get_all_backends(self):
|
||||
return self.config.all_configured_backends()
|
||||
|
||||
def note_successful_backups(self, backups):
|
||||
self.config.save_state_given_new_backups(backups)
|
||||
|
@ -91,13 +94,25 @@ class Application(object):
|
|||
human_time = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
sys.stdout.write("\t\t{} ({})\n".format(human_time, archive.time))
|
||||
|
||||
def list_configured_backups(self):
|
||||
for backup in self.get_all_backups():
|
||||
sys.stdout.write("{}\n".format(backup.name))
|
||||
for backend in backup.get_backends():
|
||||
sys.stdout.write("\tto {}\n".format(backend.name))
|
||||
|
||||
def list_backends(self):
|
||||
for backend in self.get_all_backends():
|
||||
sys.stdout.write("{}\n".format(backend))
|
||||
|
||||
def unknown_verb(self):
|
||||
raise Exception("Unknown verb")
|
||||
|
||||
def run(self):
|
||||
verbs = {
|
||||
"backup": self.perform_backups,
|
||||
"list": self.list_backups
|
||||
"list": self.list_backups,
|
||||
"list-configured-backups": self.list_configured_backups,
|
||||
"list-backends": self.list_backends
|
||||
}
|
||||
try:
|
||||
self.bootstrap()
|
||||
|
|
|
@ -36,5 +36,8 @@ class BackupBackend(object):
|
|||
if self.name is None:
|
||||
raise BackendConfigurationError("Missing name for backend")
|
||||
|
||||
def __str__(self):
|
||||
return "{}: {}".format(self.__class__.__name__, self.name)
|
||||
|
||||
def load_backend_types():
|
||||
from . import backup_backends
|
||||
|
|
|
@ -36,6 +36,10 @@ class TarsnapBackend(backend_types.BackupBackend):
|
|||
self.keyfile = config.pop("keyfile", None)
|
||||
self.host = config.pop("host", None)
|
||||
|
||||
def __str__(self):
|
||||
addendum = " ({} with {})".format(self.host, self.keyfile)
|
||||
return super(TarsnapBackend, self).__str__() + addendum
|
||||
|
||||
def create_backup_identifier(self, backup_name):
|
||||
ctx = hashlib.sha1()
|
||||
ctx.update(self.name.decode("utf-8"))
|
||||
|
|
|
@ -148,6 +148,9 @@ class ConfiguredBackup(object):
|
|||
|
||||
return pairs
|
||||
|
||||
def get_backends(self):
|
||||
return list(self.backends)
|
||||
|
||||
|
||||
class ConfiguredBackupSet(object):
|
||||
@property
|
||||
|
@ -221,6 +224,10 @@ class Config(object):
|
|||
type=parse_simple_date)
|
||||
parser_list.add_argument("--after", dest="after", default=None,
|
||||
type=parse_simple_date)
|
||||
parser_list_backups = subparsers.add_parser("list-configured-backups")
|
||||
parser_list_backups.set_defaults(verb="list-configured-backups")
|
||||
parser_list_backends = subparsers.add_parser("list-backends")
|
||||
parser_list_backends.set_defaults(verb="list-backends")
|
||||
return parser.parse_args(self.argv)
|
||||
|
||||
def default_state(self):
|
||||
|
@ -245,6 +252,15 @@ class Config(object):
|
|||
new_state = self.configured_backups.state_after_backups(backups)
|
||||
self.save_state(new_state)
|
||||
|
||||
def all_configured_backups(self):
|
||||
return self.configured_backups.all_backups()
|
||||
|
||||
def configured_backup_set(self):
|
||||
return self.configured_backups
|
||||
|
||||
def all_configured_backends(self):
|
||||
return self.configured_backends.values()
|
||||
|
||||
def __init__(self, argv, prog):
|
||||
self.argv = argv
|
||||
self.prog = prog
|
||||
|
|
Loading…
Reference in New Issue