Make list backups init backups

pull/6/head
Inex Code 2021-12-02 23:08:25 +03:00
parent 71fc93914a
commit dc4c9a89e1
1 changed files with 16 additions and 13 deletions

View File

@ -38,19 +38,31 @@ class ListAllBackups(Resource):
"--json",
]
init_command = [
"restic",
"-r",
f"rclone:backblaze:{bucket}/sfbackup",
"init",
]
with subprocess.Popen(
backup_listing_command,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
) as backup_listing_process_descriptor:
snapshots_list = backup_listing_process_descriptor.communicate()[0]
snapshots_list = backup_listing_process_descriptor.communicate()[0].decode(
"utf-8"
)
try:
json.loads(snapshots_list.decode("utf-8"))
json.loads(snapshots_list)
except ValueError:
return {"error": snapshots_list.decode("utf-8")}, 500
return json.loads(snapshots_list.decode("utf-8"))
if "Is there a repository at the following location?" in snapshots_list:
subprocess.call(init_command)
return {"error": "Initializating"}, 500
return {"error": snapshots_list}, 500
return json.loads(snapshots_list)
class AsyncCreateBackup(Resource):
@ -74,13 +86,6 @@ class AsyncCreateBackup(Resource):
"""
bucket = current_app.config["B2_BUCKET"]
init_command = [
"restic",
"-r",
f"rclone:backblaze:{bucket}/sfbackup",
"init",
]
backup_command = [
"restic",
"-r",
@ -91,8 +96,6 @@ class AsyncCreateBackup(Resource):
"/var",
]
subprocess.call(init_command)
with open("/tmp/backup.log", "w", encoding="utf-8") as log_file:
subprocess.Popen(
backup_command, shell=False, stdout=log_file, stderr=subprocess.STDOUT