fix(backups): Do not shut down the service during backup

We do not want the user to expirience outages during automatic backups.
Generally, they are not even needed.
We should use hooks to service-specific tasks, such as
creating the database dump, so we don't have to shut down Postgres.
This commit is contained in:
Inex Code 2023-07-20 17:11:02 +03:00
parent f4ac3d29a9
commit 2df448a4a9

View file

@ -4,8 +4,10 @@ from typing import List, Optional
from selfprivacy_api.utils import ReadUserData, WriteUserData from selfprivacy_api.utils import ReadUserData, WriteUserData
from selfprivacy_api.services import get_service_by_id from selfprivacy_api.services import (
from selfprivacy_api.services import get_all_services get_service_by_id,
get_all_services,
)
from selfprivacy_api.services.service import ( from selfprivacy_api.services.service import (
Service, Service,
ServiceStatus, ServiceStatus,
@ -210,8 +212,6 @@ class Backups:
Jobs.update(job, status=JobStatus.RUNNING) Jobs.update(job, status=JobStatus.RUNNING)
try: try:
with StoppedService(service):
Backups.assert_dead(service) # to be extra sure
service.pre_backup() service.pre_backup()
snapshot = Backups.provider().backupper.start_backup( snapshot = Backups.provider().backupper.start_backup(
folders, folders,
@ -489,9 +489,12 @@ class Backups:
@staticmethod @staticmethod
def assert_dead(service: Service): def assert_dead(service: Service):
# if we backup the service that is failing to restore it to the """
# previous snapshot, its status can be FAILED
# And obviously restoring a failed service is the main route If we backup the service that is failing to restore it to the previous snapshot,
its status can be FAILED.
And obviously restoring a failed service is the main route
"""
if service.get_status() not in [ if service.get_status() not in [
ServiceStatus.INACTIVE, ServiceStatus.INACTIVE,
ServiceStatus.FAILED, ServiceStatus.FAILED,