Merge branch 'master' of git.selfprivacy.org:SelfPrivacy/selfprivacy-rest-api into system-configuration

pull/6/head
Inex Code 2021-11-30 23:30:26 +03:00
commit 8e0a5f5ec0
2 changed files with 100 additions and 2 deletions

View File

@ -32,7 +32,7 @@ class ListAllBackups(Resource):
backup_listing_command = [
"restic",
"-r",
f"b2:{repository_name}:/sfbackup",
f"rclone:backblaze:{repository_name}:/sfbackup",
"snapshots",
"--json",
]
@ -72,7 +72,7 @@ class AsyncCreateBackup(Resource):
backup_command = [
"restic",
"-r",
f"b2:{repository_name}:/sfbackup",
f"rclone:backblaze:{repository_name}:/sfbackup",
"--verbose",
"--json",
"backup",
@ -128,6 +128,45 @@ class CheckBackupStatus(Resource):
return backup_process_status
class AsyncRestoreBackup(Resource):
"""Trigger backup restoration process"""
def put(self):
"""
Start backup restoration
---
tags:
- Backups
security:
- bearerAuth: []
responses:
200:
description: Backup restoration process started
400:
description: Bad request
401:
description: Unauthorized
"""
backup_restoration_command = ["restic", "-r", "rclone:backblaze:sfbackup", "var", "--json"]
with open("/tmp/backup.log", "w", encoding="utf-8") as backup_log_file_descriptor:
with subprocess.Popen(
backup_restoration_command,
shell=False,
stdout=subprocess.PIPE,
stderr=backup_log_file_descriptor,
) as backup_restoration_process_descriptor:
backup_restoration_status = (
"Backup restoration procedure started"
)
return {
"status": 0,
"message": backup_restoration_status
}
api.add_resource(ListAllBackups, "/restic/backup/list")
api.add_resource(AsyncCreateBackup, "/restic/backup/create")
api.add_resource(CheckBackupStatus, "/restic/backup/status")
api.add_resource(AsyncRestoreBackup, "/restic/backup/restore")

View File

@ -0,0 +1,59 @@
#!/usr/bin/env/python3
"""Update dispatch module"""
import os
import subprocess
from flask_restful import Resource, reqparse
from selfprivacy_api.resources.services import api
class PullRepositoryChanges(Resource):
def get(self):
"""
Pull Repository Changes
---
tags:
- Update
security:
- bearerAuth: []
responses:
200:
description: Got update
201:
description: Nothing to update
401:
description: Unauthorized
500:
description: Something went wrong
"""
git_pull_command = ["git", "pull"]
current_working_directory = os.getcwd()
os.chdir("/etc/nixos")
git_pull_process_descriptor = subprocess.Popen(
git_pull_command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=False
)
git_pull_process_descriptor.communicate()[0]
os.chdir(current_working_directory)
if git_pull_process_descriptor.returncode == 0:
return {
"status": 0,
"message": "Update completed successfully"
}
elif git_pull_process_descriptor.returncode > 0:
return {
"status": git_pull_process_descriptor.returncode,
"message": "Something went wrong"
}, 500
api.add_resource(PullRepositoryChanges, "/update")