mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-05 23:54:19 +00:00
Added backup process status check endpoint
This commit is contained in:
parent
a1e6c77cc1
commit
5c4d871bcd
|
@ -2,7 +2,7 @@
|
|||
from flask import request
|
||||
from flask_restful import Resource
|
||||
import subprocess
|
||||
import threading
|
||||
import json
|
||||
|
||||
from selfprivacy_api.resources.services import api
|
||||
|
||||
|
@ -28,10 +28,10 @@ class ListAllBackups(Resource):
|
|||
|
||||
|
||||
# Create a new restic backup
|
||||
class AsyncCreateBackup(Resource, threading.Thread):
|
||||
class AsyncCreateBackup(Resource):
|
||||
def put(self):
|
||||
backupCommand = """
|
||||
restic -r b2:{0}:/sfbackup --verbose backup /var --password-file /var/lib/restic/rpass
|
||||
restic -r b2:{0}:/sfbackup --verbose backup /var --password-file /var/lib/restic/rpass > tmp/backup.log
|
||||
""".format(
|
||||
request.headers.get("X-Repository-Name")
|
||||
)
|
||||
|
@ -45,6 +45,28 @@ class AsyncCreateBackup(Resource, threading.Thread):
|
|||
"message": "Backup creation has started",
|
||||
}
|
||||
|
||||
class CheckBackupStatus(Resource):
|
||||
def get(self):
|
||||
backupStatusCheckCommand = """
|
||||
tail -1 /tmp/backup.log
|
||||
"""
|
||||
|
||||
backupStatusCheckProcessDescriptor = subprocess.Popen(
|
||||
backupStatusCheckCommand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
|
||||
backupProcessStatus = backupStatusCheckProcessDescriptor.communicate()[0]
|
||||
backupProcessStatus = backupProcessStatus.decode("utf-8")
|
||||
|
||||
try:
|
||||
json.loads(backupProcessStatus)
|
||||
except ValueError:
|
||||
return {
|
||||
"message": backupProcessStatus
|
||||
}
|
||||
return backupProcessStatus
|
||||
|
||||
|
||||
api.add_resource(ListAllBackups, "/restic/backup/list")
|
||||
api.add_resource(AsyncCreateBackup, "/restic/backup/create")
|
||||
api.add_resource(CheckBackupStatus, "/restic/backup/status")
|
||||
|
|
Loading…
Reference in a new issue