-
Notifications
You must be signed in to change notification settings - Fork 138
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
Convert share ID during snapshot task restore #2355 #2507
Convert share ID during snapshot task restore #2355 #2507
Conversation
We previously recreated a scheduled task of type snapshot literally from the config backup file. As share IDs are highly likely to differ between system installations, this resulted in scheduled tasks of type snapshot being re-created upon config backup restore against the wrong share. This commit fixes this by: 1. fetching the share name from the ID in the backup file (source) 2. fetching the corresponding share ID in the new (target) system 3. updating the restore API call accordingly This commit also fixes some related issues by: - updating the API endpoint for scheduled tasks following rockstor#2365 - continuing restore process if a taskdef fails to be validated rockstor#2355 Moreover, the current `restore_scheduled_tasks()` logic does both the preparation/parsing of the API payload, and the API call. This makes it difficult to test the former. This commit thus refactors this part to split into: - parsing/preparation: `validate_task_definitions()` - API call: `restore_scheduled_tasks()` Accordingly two new unit tests are included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing
Restore by share name not share id:
VM1
Creating two snap tasks of two shares:
Share IDs
dnsmasq-config: 2
pihole-config: 4
Config-back created and the above id confirmed within the file.
Delete existing share with id: 3
VM1 shutdown and data pool devices moved to VM2
VM2 (4.5.7-2507 rpm upgrade to 4.5.6-0 installer instance)
Create share on ROOT pool to take up share id 2 ('home' is share id 1)
Import prior VM1 pool and check target share ids of to-be-restored snapshot tasks:
Share IDs
dnsmasq-config: 3 # miss-match from VM1 and config save
pihole-config: 4 # same as in VM1 and config save
Upload VM1 config save file
Restore config from uploaded file.
[05/Mar/2023 14:50:02] INFO [storageadmin.views.config_backup:228] Started restoring scheduled tasks.
[05/Mar/2023 14:50:02] INFO [storageadmin.views.config_backup:57] Successfully created resource: https://localhost/api/sm/tasks. Payload: {'task_type': u'snapshot', 'name': u'snap_dnsmasq', 'crontabwindow': u'*-*-*-*-*-*', 'enabled': True, 'crontab': u'*/5 * * * *', 'meta': {u'writable': True, u'visible': True, u'prefix': u'test2507', u'share': u'3', u'max_count': u'5'}}
[05/Mar/2023 14:50:02] INFO [storageadmin.views.config_backup:57] Successfully created resource: https://localhost/api/sm/tasks. Payload: {'task_type': u'snapshot', 'name': u'snap_pihole-config', 'crontabwindow': u'*-*-*-*-*-*', 'enabled': True, 'crontab': u'*/5 * * * *', 'meta': {u'writable': True, u'visible': True, u'prefix': u'test2507', u'share': u'4', u'max_count': u'5'}}
[05/Mar/2023 14:50:02] INFO [storageadmin.views.config_backup:232] Finished restoring scheduled tasks.
5 mins later we have:
Mar 05 14:55:01 buildvm CRON[21032]: (root) CMD (/opt/rockstor/.venv/bin/st-snapshot 2 \*-*-*-*-*-*)
Mar 05 14:55:01 buildvm CRON[21033]: (root) CMD (/opt/rockstor/.venv/bin/st-snapshot 1 \*-*-*-*-*-*)
Mar 05 14:55:02 buildvm CRON[21029]: (root) CMDEND (/opt/rockstor/.venv/bin/st-snapshot 2 \*-*-*-*-*-*)
Mar 05 14:55:02 buildvm kernel: BTRFS warning (device sda): qgroup rescan is already in progress
Mar 05 14:55:02 buildvm kernel: BTRFS info (device sda): qgroup scan completed (inconsistency flag cleared)
Mar 05 14:55:03 buildvm CRON[21030]: (root) CMDEND (/opt/rockstor/.venv/bin/st-snapshot 1 \*-*-*-*-*-*)
And the update in our already restored tasks:
So we have a functional test of restore by share name where id matches (between config save and target db) and where it does not.
And the resulting restored scheduled snapshot task is creating new snapshots:
@FroggyFlox Note this last image:
We have an anomaly regarding the visibility component of the imported and restored snapshots. I very much think this is for another issue and relates to our import of these snapshots.
This is a very important fix. Thanks for seeing it through to conclusion. Much appreciated.
I'll merge so we can include in the next testing channel release.
@FroggyFlox by way of the spin-off issue of the future, when I re-attached the pool to the still off VM1 of the review it successfully picked up from where it left with the following interpretation on the snapshots it and then VM2, and then again itself had taken: |
Fixes #2355
@phillxnet, @Hooverdan96: ready for testing.
We previously recreated a scheduled task of type snapshot literally from the config backup file. As share IDs are highly likely to differ between system installations, this resulted in scheduled tasks of type snapshot being re-created upon config backup restore against the wrong share.
This PR fixes this by:
This PR also fixes some related issues by:
Moreover, the current
restore_scheduled_tasks()
logic does both the preparation/parsing of the API payload, and the API call. This makes it difficult to test the former. This commit thus refactors this part to split into:validate_task_definitions()
restore_scheduled_tasks()
Demonstration and Testing
test_share01
andtest_share02
.snap_daily_ts01
andsnap_daily_ts02
.storageadmin.share
model.snap_daily_ts01
refers to an invalid share ID (one that does not exist in the config backup file). This is to test we do not attempt restoring an invalid share ID and that we do not fail the entire config restore process in case of an invalid taskdefinition in the config backup file; this is failing in our current testing/master branch. In the example below, it now refers to share id55
which does not exist:snap_daily_ts01
failed due to the invalid share IDsnap_daily_ts02
successfullyThe scheduled tasks webUI confirms the above:
Unit testing
Two new unit tests are included:
Overall unit tests: