enh(config): limit backup/restore to specific files#3338
Conversation
496132a to
1d09773
Compare
There was a problem hiding this comment.
Pull request overview
This PR refines motionEye’s configuration backup/restore mechanism to only include a small, intentionally-restorable set of files, and switches away from invoking the external tar command in favor of Python’s tarfile module.
Changes:
- Limit backups to
motion.conf,camera-*.conf, and (optionally present)prefs.json. - Apply the same allowlist when restoring from a backup archive.
- Replace external
tarsubprocess usage with in-processtarfilecreation/extraction.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| motioneye/config.py | Implements selective backup/restore and migrates backup format handling to Python tarfile. |
| motioneye/locale/motioneye.pot | Updates source line references for translation strings due to code movement. |
Backup and restore only those files which are actually generated by motionEye, and reasonable to restore: motion.conf, camera-*.conf, and prefs.json. uploadservices.json contains mostly redundant overridden info (dedicated cleanup needed), and refresh + access tokens for Google and Dropbox OAuth2. Restoring expired or revoked tokens does not make sense. If any is invalid, the OAuth2 authorization loop needs to be done in any case. All other files need to be created on console, manually or via motioneye_init. They do not necessarily need to be writable by the daemon, and should hence be consequently excluded. In case the config path contains more than 100 files, it was assumed to be "a system-wide config directory", and selective motion.conf + camera-*.conf were added to the backup already, indicating that these were the major files this feature was intended for. This commit aligns things by doing selective backup in any case, adding the reasonable/harmless prefs.json (visual preferences for the GUI), and applying the same file selecting for restoring backups. For easier OS-agnistic filtering, the native Python tarfile module is used instead of the external `tar` command. Signed-off-by: MichaIng <micha@dietpi.com>
|
@copilot |
Agent-Logs-Url: https://github.com/motioneye-project/motioneye/sessions/eba06baa-d0f9-4778-90f4-7512ebb9a461 Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
Added Backup tests verify:
Restore tests verify:
|
…test Agent-Logs-Url: https://github.com/motioneye-project/motioneye/sessions/4311136d-49de-4897-83d2-ecc5d7811f19 Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
Agent-Logs-Url: https://github.com/motioneye-project/motioneye/sessions/94a127e9-f638-40d6-9c30-498e6043bb60 Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
|
Motion/privacy mask files probably also need to be backed up like before? Maybe monitor scripts and action button scripts too, although I’m less sure about those because restoring executable scripts from a backup may have security implications? (I’m currently not able to test these changes until tomorrow.) But I think it looks good. 👍 |
|
@copilot |
Agent-Logs-Url: https://github.com/motioneye-project/motioneye/sessions/0bcf4331-1842-44fe-aba6-158dbca7e6fd Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
|
@Marijn0 |
Fixed in commit a9a7142. The CI failure was a mypy error — |
|
@copilot |
Agent-Logs-Url: https://github.com/motioneye-project/motioneye/sessions/519e1401-efb2-4fca-863e-cb4d85645e98 Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
Done in commit 74cf97c. Added |
Signed-off-by: MichaIng <micha@dietpi.com>
Backup and restore only those files which are actually generated by motionEye, and reasonable to restore:
motion.conf,camera-*.conf, andprefs.json.uploadservices.jsoncontains mostly redundant overridden info (dedicated cleanup needed), and refresh + access tokens for Google and Dropbox OAuth2. Restoring expired or revoked tokens does not make sense. If any is invalid, the OAuth2 authorization loop needs to be done in any case. All other files need to be created on console, manually or via motioneye_init. They do not necessarily need to be writable by the daemon, and should hence be consequently excluded.In case the config path contains more than 100 files, it was assumed to be "a system-wide config directory", and selective
motion.conf+camera-*.confwere added to the backup already, indicating that these were the major files this feature was intended for. This commit aligns things by doing selective backup in any case, adding the reasonable/harmlessprefs.json(visual preferences for the GUI), and applying the same file selecting for restoring backups.For easier OS-agnistic filtering, the native Python
tarfilemodule is used instead of the externaltarcommand.