-
Notifications
You must be signed in to change notification settings - Fork 276
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
Add ood-control based restore logic #228
Comments
Some of the key design considerations for the implementation of this feature are as follows. Control protocolThe current activation of ood-control is based on the LAN http protocol, so consider adding the restore protocol on top of this, some key points are as follows. 1. The type of data source supported by restoreSince the backup is generated from a data directory, the recovery in principle receives a data directory, but in many cases it can be packaged (tar/zip) into an archive, so in the long run, the recovery logic needs to support the following formats
2. Control protocol via httpBased on the existing restore, still controlled at the granularity of task, the client can start/cancel/query a restore task
3. Security issuesThe current ood-control is based on the LAN http protocol, which itself does not have permission-related security detection, so there are still certain security issues, and it is necessary to consider how to restrict the source requests, mainly for requests initiated by unknown web pages The following three services currently use the ood-control control protocol
So we can consider restricting requests from unknown sources by using the origin of http requests Internal implementationConsider a direct integration of cyfs-backup and cyfs-backup-tool logic in the form of a lib (not directly dependent on cyfs-backup tool), with the following new features:
|
The first version of ood-control based remote restore has been completed, which mainly includes the following core logic 1. Core implementationThe core implementation is in cyfs-backup, including the following two parts
The main implementation is based on http protocol to download and unpack a backup data from the remote end, supporting the following two modes
Task-based management of remote restore, integrating archive download, unpack and existing restore from local logic, and providing progress management 2. Integration with ood-controlIn addition to the existing bind/check logic of ood-control, new logic related to restore is added, including the following.
|
The usage of ood-control based remote restore 1. Supported remote archive url formatThe archive is downloaded in http mode and supports arbitrary custom query string parameters, which can be used for permission control, etc. Currently the url supports two modes - Zip package formatThe data directory generated after backup is packed into a single file by zip, the url example is as follows
- Directory formatThe data directory generated after backup is downloaded directly through the url, the url example is as follows
Where
Then, according to the contents of the index, the corresponding data files will be downloaded in turn, such as
2. Create restore taskCreate a restore task
Params related code as follows: CYFS/src/component/cyfs-backup/src/remote_restore/def.rs Lines 6 to 18 in 1b7b35b
Currently params supports the following fields: - idRequired parameter, task id, needs to satisfy the following conditions: - remote_archiveRequired parameter, the url of the remote backup archive data used for recovery, refer to the description in 1 for the format - cyfs_rootOptional parameter, you can specify a different cyfs_root for recovery, default value is used - isolate
- passwordOptional parameter, if the remote archive is stored in an encrypted way, then you need to specify the corresponding password here After the restore task is created successfully, it can be managed based on the task id, including querying progress and cancellation 3. Get restore task statusAfter the restore task is created successfully, query the status of the task
Returns a status description in json format, defined in CYFS/src/component/cyfs-backup/src/remote_restore/status.rs Lines 18 to 26 in 1b7b35b
Where - phaseThe phase of the current restore task, it should be noted that for tasks with For example, if phase= Phase define code as follows: CYFS/src/component/cyfs-backup/src/remote_restore/status.rs Lines 9 to 16 in 1b7b35b
- resultThe result of the task, which is set at the end of the task; the possible values of result are
"result": null
"result": {
"Ok": null
}
"result": {
"Err": {
"code": "4",
"msg": "not found error"
}
} - download_progressThe progress of the download from the remote archive url, with the following input example "download_progress": {
"total": 1000000,
"completed": 100,
"result": null,
"current": {
"file": "object.0.data",
"total": 100000,
"completed": 100,
"result": null
}
} Where
- unpack_progressThe same definition as - restore_statusThe recovery status of the local ood, which is the same as the standard local archive recovery process, is defined as follows https://github.com/buckyos/CYFS/blob/1b7b35b09a81cb6119fe844058bba8297ae1e3ce/src/component/cyfs-backup-lib/src/backup/restore_ status.rs#L32-L41 The sample status output in json format is as follows "restore_status": {
"phase": "Init",
"phase_last_update_time": 0,
"stat": {
"objects": {
"count": 10000,
"bytes": 0
},
"chunks": {
"count": 1000,
"bytes": 0
},
"files": {
"count": 100,
"bytes": 0
}
},
"complete": {
"objects": {
"count": 100,
"bytes": 0
},
"chunks": {
"count": 0,
"bytes": 0
},
"files": {
"count": 0,
"bytes": 0
}
},
"result": null
} Where
CYFS/src/component/cyfs-backup-lib/src/backup/restore_status.rs Lines 8 to 16 in 1b7b35b
The phases of the ood restore process are described in order of progression
4. Cancel restore taskBefore a restore execution is completed, you can forcibly terminate it with the following command
It should be noted that canceling a restore task will not clean up the restored ood data together, but only the downloaded data files and the decompressed data files (if they already exist); after canceling the restore task, you can restart a new restore task, which will directly overwrite the old state ( generally incomplete state, OOD is not available) 5. Query the current restore taskYou can query the list of currently executing restore task (currently there is and can only have a restore task)
If there is already a restore task executing, the upper layer either waits for the task to finish or cancels the task, and cannot recreate a new restore task. |
When testing remote restore, you can build a simple http server locally to handle the two types of remote_archive cases. |
Add ood-control based restore logic has tested finished. Test environmentOOD : Nightly 1.1.0.756 Create OOD random datasource code
Backup ood dataBackup ood data without password./cyfs-backup --mode backup --id 001 --target-dir /backup/001 --root /cyfs Backup ood data with password./cyfs-backup --mode backup --id 002 --target-dir /backup/002 --root /cyfs --password token-dhjfkfsfsaf --file-max-size 100000000000 Use nginx support a simple http file serverserver {
listen 192.168.200.151:80;
server_name 192.168.200.151;
location / {
root /backup;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
} Backup ood data support zip package format server
we can view zip package by: http://192.168.200.151/001/data.zip Backup ood data support directory format serverwe can view directory by: http://192.168.200.151/002 Restore ood data by ood-daemonCreate restore task
Get restore task statusGET http://192.168.100.205:1320/restore/001 Cancel restore taskDELETE http://192.168.100.205:1320/restore/001 Query the current restore taskGET http://192.168.100.205:1320/restore/tasks Clean datarm -rf /cyfs Test Case Listsource code |
Very detailed test cases, thanks for the help! So this feature will be released in the next version |
…ontrol-based-restore-logic' into main
The current backup and restore mechanism based on cyfs-backup tool is already supported, but it requires command line operation, which is an advanced usage and relatively not very user friendly, so consider adding the corresponding OOD backup and restore related functions in the OOD management page of cyfs-browser, similar to the OOD activation process, which can be activated in the LAN or restore a new OOD (gateway) from an existing backup, so the related functions and protocols need to be supported in the OOD-control component.
The text was updated successfully, but these errors were encountered: