-
Notifications
You must be signed in to change notification settings - Fork 666
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
Extend backup API with file name field #5567
Open
agners
wants to merge
5
commits into
main
Choose a base branch
from
allow--specifying-backup-filename
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+41
−5
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
34301b1
Extend backup API with file name field
agners 8c14810
Check passed file name using regex
agners bcb8f2a
Use custom filename on download only if backup file name is backup slug
agners e295348
ruff format
agners 997b281
Remove path from location for download file name
agners File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,7 @@ def _list_backup_files(self, path: Path) -> Iterable[Path]: | |
def _create_backup( | ||
self, | ||
name: str, | ||
filename: str | None, | ||
sys_type: BackupType, | ||
password: str | None, | ||
compressed: bool = True, | ||
|
@@ -196,7 +197,11 @@ def _create_backup( | |
""" | ||
date_str = utcnow().isoformat() | ||
slug = create_slug(name, date_str) | ||
tar_file = Path(self._get_base_path(location), f"{slug}.tar") | ||
|
||
if filename: | ||
tar_file = Path(self._get_base_path(location), Path(filename).name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this |
||
else: | ||
tar_file = Path(self._get_base_path(location), f"{slug}.tar") | ||
|
||
# init object | ||
backup = Backup(self.coresys, tar_file, slug, self._get_location_name(location)) | ||
|
@@ -482,6 +487,7 @@ async def _do_backup( | |
async def do_backup_full( | ||
self, | ||
name: str = "", | ||
filename: str | None = None, | ||
*, | ||
password: str | None = None, | ||
compressed: bool = True, | ||
|
@@ -500,7 +506,7 @@ async def do_backup_full( | |
) | ||
|
||
backup = self._create_backup( | ||
name, BackupType.FULL, password, compressed, location, extra | ||
name, filename, BackupType.FULL, password, compressed, location, extra | ||
) | ||
|
||
_LOGGER.info("Creating new full backup with slug %s", backup.slug) | ||
|
@@ -526,6 +532,7 @@ async def do_backup_full( | |
async def do_backup_partial( | ||
self, | ||
name: str = "", | ||
filename: str | None = None, | ||
*, | ||
addons: list[str] | None = None, | ||
folders: list[str] | None = None, | ||
|
@@ -558,7 +565,7 @@ async def do_backup_partial( | |
_LOGGER.error("Nothing to create backup for") | ||
|
||
backup = self._create_backup( | ||
name, BackupType.PARTIAL, password, compressed, location, extra | ||
name, filename, BackupType.PARTIAL, password, compressed, location, extra | ||
) | ||
|
||
_LOGGER.info("Creating new partial backup with slug %s", backup.slug) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
Right! Actually I use it for
web.FileResponse
on the next line, so the fix is somewhat more complicated.But fixed and tested, should be fine now!