-
Notifications
You must be signed in to change notification settings - Fork 9
feat: pass custom options to restic backup #101
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
base: main
Are you sure you want to change the base?
Conversation
add stack-back.restic.backup.options label to the stack-back container to take `restic backup` options. Defaults to `--verbose` for backward compatibility. Also: - add LABEL_RESTIC_BACKUP_OPTIONS as enum. - feature works for both volumes and database backup. - change backup(), backup_from_stdin() signature to take restic_backup_options as argument. - add --tag test-tag to test compose file and integration_test. - enhance integration_test parsing of snapshots (could use json, but less readable). - improve visibility of logs when integration tests run showing output of restic command in pytest log (with --log-cli-level=DEBUG). - documentation.
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.
Pull request overview
This PR adds support for passing custom restic backup options through a Docker label stack-back.restic.backup.options. The feature aims to allow users to customize restic backup behavior (e.g., adding tags) while maintaining backward compatibility with the default --verbose flag.
Changes:
- Added
LABEL_RESTIC_BACKUP_OPTIONSconstant to enums - Modified backup function signatures to accept
restic_backup_optionsparameter - Enhanced integration tests with snapshot parsing and tag verification
- Added documentation for the new feature
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/restic_compose_backup/enums.py | Added new label constant for restic backup options |
| src/restic_compose_backup/restic.py | Updated backup functions to accept and pass custom options |
| src/restic_compose_backup/containers.py | Updated base container backup method signature |
| src/restic_compose_backup/containers_db.py | Updated database container backup methods to accept options |
| src/restic_compose_backup/cli.py | Added label parsing logic and option passing |
| src/tests/integration/test_volume_backups.py | Added snapshot parsing helper and tag verification |
| src/tests/integration/conftest.py | Added debug logging for test diagnostics |
| docker-compose.test.yaml | Added test label with --tag option |
| docs/guide/configuration.rst | Documented the new feature |
| README.md | Added note about pytest debug options |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/restic_compose_backup/cli.py
Outdated
| restic_backup_options = ["--verbose"] | ||
| backup_args_label = containers.this_container.get_label(enums.LABEL_RESTIC_BACKUP_OPTIONS) | ||
| if backup_args_label: | ||
| restic_backup_options.extend(backup_args_label.split()) |
Copilot
AI
Jan 24, 2026
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.
Using .split() without arguments to parse the backup options may not handle quoted strings correctly. For example, if a user wants to pass an option with a space in it like --tag "my backup tag", the .split() method will incorrectly split it into three separate arguments: ["--tag", '"my', 'backup', 'tag"'].
Consider using shlex.split() instead, which properly handles quoted strings and follows shell parsing rules. This would allow users to pass more complex option values safely.
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.
Not sure about this one.
src/restic_compose_backup/restic.py
Outdated
| def backup_files(repository: str, restic_backup_options: List[str], source="/volumes"): | ||
| return commands.run( | ||
| restic( | ||
| repository, | ||
| [ | ||
| "--verbose", | ||
| "backup", | ||
| source, | ||
| ], | ||
| ] + restic_backup_options, |
Copilot
AI
Jan 24, 2026
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.
The order of arguments being passed to restic may cause issues. The backup options are appended after the source path (source is added first at line 34, then restic_backup_options is appended). However, some restic options must come before the command arguments. For example, global flags like --verbose should come before backup, while backup-specific flags come after.
The current implementation puts all custom options after the source path, which means they're treated as backup-specific options. This works for --verbose and --tag, but users might expect to be able to pass global restic options as well. Consider documenting this limitation, or restructure to separate global options from backup-specific options.
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.
I feel the name of the label says it back-stack.restic.backup.options. Those are the options passed to restic backup. Let me know if you'd like to make a change.
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.
I'm worried that Copilot might be right here about the order of options being important. We may not be able to simply append all restic_backup_options to the end of the command. I'll do some testing and report back.
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.
Ok, let me know how to do it differently.
In my mind, back-stack.restic.backup.options are options that are listed in the output for restic backup --help. Maybe I should make that clear in the documentation.
If anyone wants options before backup those probably could be listed as back-stack.restic.options but I don't have a use case for anything before backup.
Per lawndoc#101 (comment). It does feel less surprising. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Hi @elmotec thanks for the PR! In addition to your use cases from the discussion, I know this will be handy for people who want to use glacier s3 class and need to pass through additional args for that to work.
Just a few comments for you to review.
src/restic_compose_backup/restic.py
Outdated
| def backup_files(repository: str, restic_backup_options: List[str], source="/volumes"): | ||
| return commands.run( | ||
| restic( | ||
| repository, | ||
| [ | ||
| "--verbose", | ||
| "backup", | ||
| source, | ||
| ], | ||
| ] + restic_backup_options, |
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.
I'm worried that Copilot might be right here about the order of options being important. We may not be able to simply append all restic_backup_options to the end of the command. I'll do some testing and report back.
src/restic_compose_backup/restic.py
Outdated
| "--stdin-filename", | ||
| filename, | ||
| ], | ||
| ] + restic_backup_options, |
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.
Same comment here, we need to make sure that all potential options can be appended to the end of the restic command and can come after the backup argument.
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.
we can follow up on this conversation.
docker-compose.test.yaml
Outdated
| backup: | ||
| build: ./src | ||
| labels: | ||
| stack-back.restic.backup.options: "--tag test-tag" |
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.
Since these options override the default --verbose flag, it might be a good idea to add --verbose to these arguments since this is a test and the verbose output may be useful to us.
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.
good point, I was initially adding to the existing options and later the LLM convinced me to switch to a complete override. I did not update the compose test though but it is fixed in 57fdbdd.
Thanks @lawndoc, I addressed your comments. Re-requested review. |
|
Also I am wondering if we should support a |
add
stack-back.restic.backup.optionslabel to the stack-back container (not the backed up containers because all volumes are backed up with one restic command) to takerestic backupoptions. Defaults to--verbosefor backward compatibility.Also:
LABEL_RESTIC_BACKUP_OPTIONSas enum.backup(),backup_from_stdin()signature to takerestic_backup_optionsas argument.