-
Notifications
You must be signed in to change notification settings - Fork 24
Backup action changes for UX improvements #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DavidePrincipi
wants to merge
3
commits into
main
Choose a base branch
from
feat-7810
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 1 addition & 10 deletions
11
core/imageroot/var/lib/nethserver/cluster/actions/get-defaults/validate-input.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "get-defaults input", | ||
| "$id": "http://schema.nethserver.org/cluster/get-defaults-input.json", | ||
| "description": "The action expects a null value as input", | ||
| "examples": [ | ||
| null | ||
| ], | ||
| "type": "null" | ||
| } | ||
| {} | ||
DavidePrincipi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ar/lib/nethserver/cluster/actions/import-backup-destinations/10import_backup_destinations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # | ||
| # Copyright (C) 2026 Nethesis S.r.l. | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
| # | ||
|
|
||
| import base64 | ||
| import json | ||
| import os | ||
| import gzip | ||
| import subprocess | ||
| import sys | ||
| import agent | ||
|
|
||
| def import_destinations(cluster_backup): | ||
| """Import backup destination configurations into Redis""" | ||
| rdb = agent.redis_connect(privileged=True) | ||
| imported_count = 0 | ||
| skipped_count = 0 | ||
| local_cluster_uuid = rdb.get("cluster/uuid") or "unknown_local" | ||
| import_cluster_uuid = cluster_backup["cluster"].get("uuid", "unknown_import") | ||
| for dkey, odest in cluster_backup["cluster"]["backup_repository"].items(): | ||
| # Check if the destination UUID key exists. Historically, a backup | ||
| # destination was named "backup repository". | ||
| if odest["provider"] == "cluster" and local_cluster_uuid != import_cluster_uuid: | ||
| skipped_count += 1 | ||
| continue # internal destination of another cluster, ignore | ||
| elif rdb.exists(f"cluster/backup_repository/{dkey}"): | ||
| skipped_count += 1 | ||
| continue | ||
| print("Importing backup destination", dkey, odest["name"], file=sys.stderr) | ||
| # FIXME: validate configuration before storing odest in Redis | ||
| rdb.hset(f"cluster/backup_repository/{dkey}", mapping=odest) | ||
| imported_count += 1 | ||
| return imported_count, skipped_count | ||
|
|
||
| def main(): | ||
| request = json.load(sys.stdin) | ||
| try: | ||
| cipher_data = base64.b64decode(request["backup_data"], validate=True) | ||
| except Exception as ex: | ||
| print(agent.SD_ERR + "backup_data decode error:", ex, file=sys.stderr) | ||
| agent.set_status("validation-failed") | ||
| json.dump([{"error":"invalid_base64","field":"backup_data","parameter":"backup_data","value":""}], fp=sys.stdout) | ||
| sys.exit(2) | ||
|
|
||
| passphrase_fd, wfd = os.pipe() | ||
| os.write(wfd, request["backup_password"].encode("utf-8") + b"\n") | ||
| # NOTE: close wfd, assuming for simplicity that password is few bytes | ||
| # short and fits the pipe buffer size: | ||
| os.close(wfd) | ||
| gpg_cmd = [ | ||
| "gpg", "--decrypt", "--batch", | ||
| "--pinentry-mode", "loopback", | ||
| "--passphrase-fd", str(passphrase_fd), | ||
| ] | ||
| gpg_proc = subprocess.run(gpg_cmd, | ||
| input=cipher_data, | ||
| stdout=subprocess.PIPE, | ||
| pass_fds=[passphrase_fd] | ||
| ) | ||
| os.close(passphrase_fd) | ||
| if gpg_proc.returncode != 0: | ||
| agent.set_status("validation-failed") | ||
| json.dump([{"error":"invalid_passphrase","field":"backup_password","parameter":"backup_password","value":""}], fp=sys.stdout) | ||
| sys.exit(3) | ||
| json_data = gzip.decompress(gpg_proc.stdout) | ||
| cluster_backup = json.loads(json_data) | ||
DavidePrincipi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| imported_count, skipped_count = import_destinations(cluster_backup) | ||
| json.dump({"imported_destinations": imported_count, "skipped_destinations": skipped_count}, fp=sys.stdout) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
30 changes: 30 additions & 0 deletions
30
...ageroot/var/lib/nethserver/cluster/actions/import-backup-destinations/validate-input.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "import-backup-destinations input", | ||
| "$id": "http://schema.nethserver.org/cluster/import-backup-destinations-input.json", | ||
| "description": "Import backup destination configurations from raw cluster backup data", | ||
| "examples": [ | ||
| { | ||
| "backup_password": "mypassword", | ||
| "backup_data": "jA0ECQMC2c...94FL/8y2KV" | ||
| } | ||
| ], | ||
| "type": "object", | ||
| "required": [ | ||
| "backup_password", | ||
| "backup_data" | ||
| ], | ||
| "properties": { | ||
| "backup_password": { | ||
| "description": "GPG passphrase to decrypt backup_data field", | ||
| "type": "string", | ||
| "maxLength": 4096 | ||
| }, | ||
| "backup_data": { | ||
| "description": "base64-encoded string of GPG-encrypted, gzip-compressed backup data", | ||
| "type": "string", | ||
| "contentEncoding": "base64", | ||
| "contentMediaType": "application/octet-stream" | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...geroot/var/lib/nethserver/cluster/actions/import-backup-destinations/validate-output.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "title": "import-backup-destinations output", | ||
| "$id": "http://schema.nethserver.org/cluster/import-backup-destinations-output.json", | ||
| "description": "Import backup destination configurations from raw cluster backup data", | ||
| "examples": [ | ||
| { | ||
| "imported_destinations": 2, | ||
| "skipped_destinations": 1 | ||
| } | ||
| ], | ||
| "type": "object", | ||
| "required": [ | ||
| "imported_destinations", | ||
| "skipped_destinations" | ||
| ], | ||
| "properties": { | ||
| "imported_destinations": { | ||
| "description": "Number of backup destinations successfully imported", | ||
| "type": "integer", | ||
| "minimum": 0 | ||
| }, | ||
| "skipped_destinations": { | ||
| "description": "Number of backup destinations not imported because already configured in the cluster DB", | ||
| "type": "integer", | ||
| "minimum": 0 | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.