mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-03-18 20:39:46 +00:00
Make list backups init backups
This commit is contained in:
parent
71fc93914a
commit
dc4c9a89e1
1 changed files with 16 additions and 13 deletions
|
@ -38,19 +38,31 @@ class ListAllBackups(Resource):
|
||||||
"--json",
|
"--json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
init_command = [
|
||||||
|
"restic",
|
||||||
|
"-r",
|
||||||
|
f"rclone:backblaze:{bucket}/sfbackup",
|
||||||
|
"init",
|
||||||
|
]
|
||||||
|
|
||||||
with subprocess.Popen(
|
with subprocess.Popen(
|
||||||
backup_listing_command,
|
backup_listing_command,
|
||||||
shell=False,
|
shell=False,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
) as backup_listing_process_descriptor:
|
) 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:
|
try:
|
||||||
json.loads(snapshots_list.decode("utf-8"))
|
json.loads(snapshots_list)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return {"error": snapshots_list.decode("utf-8")}, 500
|
if "Is there a repository at the following location?" in snapshots_list:
|
||||||
return json.loads(snapshots_list.decode("utf-8"))
|
subprocess.call(init_command)
|
||||||
|
return {"error": "Initializating"}, 500
|
||||||
|
return {"error": snapshots_list}, 500
|
||||||
|
return json.loads(snapshots_list)
|
||||||
|
|
||||||
|
|
||||||
class AsyncCreateBackup(Resource):
|
class AsyncCreateBackup(Resource):
|
||||||
|
@ -74,13 +86,6 @@ class AsyncCreateBackup(Resource):
|
||||||
"""
|
"""
|
||||||
bucket = current_app.config["B2_BUCKET"]
|
bucket = current_app.config["B2_BUCKET"]
|
||||||
|
|
||||||
init_command = [
|
|
||||||
"restic",
|
|
||||||
"-r",
|
|
||||||
f"rclone:backblaze:{bucket}/sfbackup",
|
|
||||||
"init",
|
|
||||||
]
|
|
||||||
|
|
||||||
backup_command = [
|
backup_command = [
|
||||||
"restic",
|
"restic",
|
||||||
"-r",
|
"-r",
|
||||||
|
@ -91,8 +96,6 @@ class AsyncCreateBackup(Resource):
|
||||||
"/var",
|
"/var",
|
||||||
]
|
]
|
||||||
|
|
||||||
subprocess.call(init_command)
|
|
||||||
|
|
||||||
with open("/tmp/backup.log", "w", encoding="utf-8") as log_file:
|
with open("/tmp/backup.log", "w", encoding="utf-8") as log_file:
|
||||||
subprocess.Popen(
|
subprocess.Popen(
|
||||||
backup_command, shell=False, stdout=log_file, stderr=subprocess.STDOUT
|
backup_command, shell=False, stdout=log_file, stderr=subprocess.STDOUT
|
||||||
|
|
Loading…
Add table
Reference in a new issue