Skip to content
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

Backup/Restore references incorrect shares for Scheduled Tasks #2355

Closed
mattyvau opened this issue Feb 3, 2022 · 7 comments · Fixed by #2507
Closed

Backup/Restore references incorrect shares for Scheduled Tasks #2355

mattyvau opened this issue Feb 3, 2022 · 7 comments · Fixed by #2507
Assignees

Comments

@mattyvau
Copy link

mattyvau commented Feb 3, 2022

Creating a backup from rockstor 3.9 and restoring in 4.1 incorrectly restores scheduled tasks by pointing them to the wrong shares. Example as per the screenshot below, a task for a photos share now points to a music share.

Scheduled tasks - 4 1 - edit - scaled

As discussed in forum thread 8249, this likely stems from the backup referencing shares numerically rather than by name. Relevant extract from backup JSON below.

{
		"fields": {
			"task_type": "snapshot",
			"name": "photos-weekly-snapshot",
			"enabled": true,
			"crontabwindow": "*-*-*-*-*-*",
			"crontab": "15 8 * * 5",
			"json_meta": "{\"share\": \"19\", \"max_count\": \"5\", \"writable\": false, \"visible\": false, \"prefix\": \"photos-weekly\"}"
		},
		"model": "smart_manager.taskdefinition",
		"pk": 5
	},
@phillxnet
Copy link
Member

phillxnet commented Feb 4, 2022

@mattyvau Thanks for opening this issue. I'm pretty sure this has failed since we changed our shares api towards the end of 3.9, so it's good we have an issue open on this now.

@FroggyFlox
Copy link
Member

@phillxnet, I just had a better look at this issue.

It actually seems to be related to the fact that we are indeed looking for a share ID in the API call to create a scheduled task:

if "share" in meta:
if not meta["share"].isdigit():
raise Exception(
"Non-digit share element ({}) in meta {}".format(
meta["share"], meta
)
)

Of course, these share IDs can and most likely will vary in a re-install scenario so that is why it will most likely be problematic in such situations. It should be fine when restoring a config backup on the same system used as during the creation of the config backup.

While we could maybe alter what info we originally gather and expect for this API call, this seems rather cumbersome and heavy-handed.
We could alternatively, add some share validation routine in the restore_scheduled_tasks() process to fetch the share.name from the config backup itself, and then get the new share.id matching this name on the new system. We already do something similar during the restore_rockons() process for similar reasons; this means we might be able to re-use some of that code for it, thereby lowering the workload.

I personally would vote for the second approach.

@phillxnet
Copy link
Member

While we could maybe alter what info we originally gather and expect for this API call, this seems rather cumbersome and heavy-handed.

Agreed, plus it changes the format of our config save file which is something it would be good to avoid. Given folks will have some going back in time. Plus we then have to account for older and newer formats etc. So if the info is in there and we have to do just a little one-off work to retrieve the names that should do it. Complicated by the changing of share names, but we don't support that yet anyway. And when we do we may have to advertise this side-effect unless we can address it at that time.

We could alternatively, add some share validation routine in the restore_scheduled_tasks() process to fetch the share.name from the config backup itself, and then get the new share.id matching this name on the new system.

Agreed; and as you say, we (you as it goes) wrote similar code to do this back when the Rock-ons restore capability was added.

I personally would vote for the second approach.

Agreed also.

@FroggyFlox FroggyFlox self-assigned this Jan 30, 2023
@FroggyFlox
Copy link
Member

FroggyFlox commented Jan 31, 2023

After a brief look, it seems that Pool-related scheduled tasks (Scrub) would suffer from the same issue. It may be better to deal with that in its own separate issue, though.

@FroggyFlox
Copy link
Member

Following #2365 , we also have a failure to restore any scheduled tasks as the API endpoint has changed (an extra trailing slash needs to be removed). This simple fix will be included in the coming PR.

FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Feb 26, 2023
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:
  - fetching the share name from the ID from the config backup file (source)
  - fetch the corresponding share ID in the new (target) system
  - update the restore API call accordingly

This commit also update the API endpoint for scheduled tasks following rockstor#2365.
@FroggyFlox
Copy link
Member

I now have a simple share ID conversion logic that replaces the corresponding json_meta in the config backup:

"json_meta": "{\"writable\": true, \"visible\": true, \"prefix\": \"snap_daily_ts01\", \"share\": \"77\", \"max_count\": \"4\"}",

with the update share ID (was 77 in the config backup file, now is 3 on the target system):
(below is an excerpt from a successful config restore)

'meta': {u'writable': True, u'visible': True, u'prefix': u'snap_daily_ts01', u'share': u'3', u'max_count': u'4'}

We now need to write a few unit tests to cover the scheduled tasks restore as that isn't currently covered.

FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Feb 26, 2023
Currently, a failed validation will fail the entire restore_scheduled_tasks() process.

This commit instead catches any Exception during this process and logs it as INFO
before moving on to the next task definition to be restored.
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Feb 26, 2023
@FroggyFlox FroggyFlox added this to the First Stable Poetry build milestone Feb 28, 2023
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Mar 2, 2023
Currently, the `restore_scheduled_tasks()` logic does both the
preparation and parsing of the API payload, and the API call. This
makes it difficult to test the former.

This commit thus refactors this to split into:
  - parsing/preparation: `validate_task_definitions()`
  - API call: `restore_scheduled_tasks()`

Accordingly, a new unit test is added for the first one.
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Mar 2, 2023
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Mar 3, 2023
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.
@FroggyFlox FroggyFlox linked a pull request Mar 3, 2023 that will close this issue
phillxnet added a commit that referenced this issue Mar 5, 2023
…_incorrect_shares

Convert share ID during snapshot task restore #2355
@FroggyFlox
Copy link
Member

Closing as fixed by #2507.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants