Detect if a repository should be initialized
This is better than trying to initialize it every time
This commit is contained in:
parent
6347529701
commit
1e21ff422f
|
@ -54,15 +54,20 @@ def status(config, containers):
|
||||||
logger.info("Status for compose project '%s'", containers.project_name)
|
logger.info("Status for compose project '%s'", containers.project_name)
|
||||||
logger.info("Repository: '%s'", config.repository)
|
logger.info("Repository: '%s'", config.repository)
|
||||||
logger.info("Backup currently running?: %s", containers.backup_process_running)
|
logger.info("Backup currently running?: %s", containers.backup_process_running)
|
||||||
logger.info("%s Detected Config %s", "-" * 25, "-" * 25)
|
|
||||||
|
|
||||||
if containers.stale_backup_process_containers:
|
if containers.stale_backup_process_containers:
|
||||||
utils.remove_containers(containers.stale_backup_process_containers)
|
utils.remove_containers(containers.stale_backup_process_containers)
|
||||||
|
|
||||||
# Check if repository is initialized with restic snapshots
|
# Check if repository is initialized with restic snapshots
|
||||||
if restic.snapshots(config.repository) != 0:
|
if not restic.is_initialized(config.repository):
|
||||||
logger.info("Initializing repository")
|
logger.info("Could not get repository info. Attempting to initialize it.")
|
||||||
restic.init_repo(config.repository)
|
result = restic.init_repo(config.repository)
|
||||||
|
if result == 0:
|
||||||
|
logger.info("Successfully initialized repository: %s", config.repository)
|
||||||
|
else:
|
||||||
|
logger.error("Failed to initialize repository")
|
||||||
|
|
||||||
|
logger.info("%s Detected Config %s", "-" * 25, "-" * 25)
|
||||||
|
|
||||||
# Start making snapshots
|
# Start making snapshots
|
||||||
backup_containers = containers.containers_for_backup()
|
backup_containers = containers.containers_for_backup()
|
||||||
|
|
|
@ -58,12 +58,23 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str])
|
||||||
|
|
||||||
|
|
||||||
def snapshots(repository: str, last=True) -> Tuple[str, str]:
|
def snapshots(repository: str, last=True) -> Tuple[str, str]:
|
||||||
|
"""Returns the stdout and stderr info"""
|
||||||
args = ["snapshots"]
|
args = ["snapshots"]
|
||||||
if last:
|
if last:
|
||||||
args.append('--last')
|
args.append('--last')
|
||||||
return commands.run_capture_std(restic(repository, args))
|
return commands.run_capture_std(restic(repository, args))
|
||||||
|
|
||||||
|
|
||||||
|
def is_initialized(repository: str) -> bool:
|
||||||
|
"""
|
||||||
|
Checks if a repository is initialized using snapshots command.
|
||||||
|
Note that this cannot separate between uninitalized repo
|
||||||
|
and other errors, but this method is reccomended by the restic
|
||||||
|
community.
|
||||||
|
"""
|
||||||
|
return commands.run(restic(repository, ["snapshots", '--last'])) == 0
|
||||||
|
|
||||||
|
|
||||||
def forget(repository: str, daily: str, weekly: str, monthly: str, yearly: str):
|
def forget(repository: str, daily: str, weekly: str, monthly: str, yearly: str):
|
||||||
return commands.run(restic(repository, [
|
return commands.run(restic(repository, [
|
||||||
'forget',
|
'forget',
|
||||||
|
|
Loading…
Reference in New Issue