mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-05 23:54:19 +00:00
Merge branch 'master' of git.selfprivacy.org:SelfPrivacy/selfprivacy-rest-api into system-configuration
This commit is contained in:
commit
8e0a5f5ec0
|
@ -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")
|
||||
|
|
59
selfprivacy_api/resources/services/update.py
Normal file
59
selfprivacy_api/resources/services/update.py
Normal 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")
|
Loading…
Reference in a new issue