Skip to content

Commit

Permalink
Add ability to delete app backup
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicaj committed Dec 22, 2024
1 parent be31970 commit 57c1170
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'DockerEntry', 'DockerUpdateArgs', 'DockerUpdateResult', 'DockerStatusArgs', 'DockerStatusResult',
'DockerNvidiaPresentArgs', 'DockerNvidiaPresentResult', 'DockerBackupArgs', 'DockerBackupResult',
'DockerListBackupArgs', 'DockerListBackupResult', 'DockerRestoreBackupArgs', 'DockerRestoreBackupResult',
'DockerDeleteBackupArgs', 'DockerDeleteBackupResult',
]


Expand Down Expand Up @@ -120,3 +121,11 @@ class DockerRestoreBackupArgs(BaseModel):

class DockerRestoreBackupResult(BaseModel):
result: None


class DockerDeleteBackupArgs(BaseModel):
backup_name: NonEmptyString


class DockerDeleteBackupResult(BaseModel):
result: None
17 changes: 16 additions & 1 deletion src/middlewared/middlewared/plugins/docker/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from middlewared.api import api_method
from middlewared.api.current import (
DockerBackupResult, DockerUpdateArgs, DockerListBackupArgs, DockerListBackupResult,
DockerBackupResult, DockerUpdateArgs, DockerListBackupArgs, DockerListBackupResult, DockerDeleteBackupArgs,
DockerDeleteBackupResult,
)
from middlewared.plugins.apps.ix_apps.path import get_collective_config_path, get_collective_metadata_path
from middlewared.plugins.zfs_.validation_utils import validate_snapshot_name
Expand Down Expand Up @@ -108,3 +109,17 @@ def list_backups(self):
}

return backups

@api_method(DockerDeleteBackupArgs, DockerDeleteBackupResult, roles=['DOCKER_WRITE'])
def delete_backup(self, backup_name):
"""
Delete `backup_name` app backup.
"""
self.middleware.call_sync('docker.state.validate')

backup = self.middleware.call_sync('docker.list_backups').get(backup_name)
if not backup:
raise CallError(f'Backup {backup_name!r} does not exist', errno=errno.ENOENT)

self.middleware.call_sync('zfs.snapshot.delete', backup['snapshot_name'], {'recursive': True})
shutil.rmtree(backup['backup_path'], True)

0 comments on commit 57c1170

Please sign in to comment.