Skip to content

Commit

Permalink
WIP Implement restore-backup-content
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePrincipi committed Nov 13, 2024
1 parent ad07d0c commit 06be3d2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
37 changes: 37 additions & 0 deletions imageroot/actions/restore-backup-content/50restore_backup_content
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json
import sys
import os
import subprocess
import agent
import hashlib

request = json.load(sys.stdin)

content_basename = os.path.basename(request['content'])
content_path = os.path.dirname(request['content'])
destroot = request.get("destroot", "Restored folder")

# TODO: create destroot and configure ownership, permissions, ACLs

podman_args = ["--workdir=/srv"] + agent.agent.get_state_volume_args()
restic_args = [
"restore",
"--json",
f"{request['snapshot']}:volumes/shares/{request['share']}/{content_path}",
f"--include={content_basename}",
f"--include={content_basename}/**",
f"--target=volumes/shares/{request['share']}/{destroot}"
]
# TODO: trace the restore progress to UI
agent.run_restic(agent.redis_connect(), request["destination"], request["repopath"], podman_args, restic_args, stdout=sys.stderr).check_returncode()

json.dump({
"request": request,
}, fp=sys.stdout)
40 changes: 40 additions & 0 deletions imageroot/actions/restore-backup-content/validate-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "restore-backup-content input",
"$id": "http://schema.nethserver.org/mail/restore-backup-content-input.json",
"description": "Extract content from a backup snapshot",
"examples": [

],
"type": "object",
"required": [
"destination",
"repopath",
"snapshot",
"share",
"content"
],
"properties": {
"destination": {
"type": "string",
"description": "The UUID of the backup destination where the Restic repository resides."
},
"repopath": {
"type": "string",
"description": "Restic repository path, under the backup destination"
},
"snapshot": {
"type": "string",
"description": "Restic snapshot ID to restore"
},
"share": {
"type": "string",
"pattern": "^[^/\\\\:><\"|?*]+$",
"description": "Seek the paths of this Samba share"
},
"content": {
"type": "string",
"description": "Content path to restore"
}
}
}
32 changes: 32 additions & 0 deletions imageroot/actions/restore-backup-content/validate-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "restore-backup-content output",
"$id": "http://schema.nethserver.org/mail/restore-backup-content-output.json",
"description": "Extract content from a backup snapshot",
"examples": [
{
"request": {
"destination": "14030a59-a4e6-54cc-b8ea-cd5f97fe44c8",
"repopath": "mail/4372a5d5-0886-45d3-82e7-68d913716a4c",
"snapshot": "latest",
"share": "myshare",
"query": "*.php",
"basename": true,
"limit": 1000
},
"contents": [
"dir1/file001.php",
"dir1/file002.php",
"Project/NethServer/Main.php"
],
"limit_reached": false
}
],
"type": "object",
"properties": {
"request": {
"type": "object",
"title": "Original request object"
}
}
}

0 comments on commit 06be3d2

Please sign in to comment.