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

Allow specifing database backup paths. #7035

Conversation

libklein
Copy link
Contributor

@libklein libklein commented Oct 10, 2021

Resolves #3279.

Allow to specify a custom backup location & filename. The filename may contain patterns "{DB_NAME}" and "{TIME:xxx}" which will be replaced with the database name and the current time, formatted according to "xxx", respectively.

The backup path can be relative or absolute. The former creates the backup relative to the database file.

The following changes have been made:

  • backupDatabase() now takes a destination file path as argument
  • Propagated method signature changes to saveAs, save and performSave functions
  • Added a getDefault(key) method to Config. This returns the default value.
  • Added new config keys backupFileNamePattern and backupFilePath
  • Added textfields to ApplicationSettingsWidget accordingly

Limitations/open issues (please comment)

  • Old databases are not removed when the backup location changes. I believe this is out of scope and should not be the responsibility of keepassxc. Especially since there is no way to handle relative paths properly if this is required.
  • A section on the structure of backupFileNamePattern needs to created. Or do you think it suffices to explain it in a tooltip?

Screenshots

image

Testing strategy

Modified database backup unit test accordingly.

Type of change

  • ✅ New feature (change that adds functionality)

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2021

Codecov Report

Merging #7035 (00394c6) into develop (7811f10) will increase coverage by 0.05%.
The diff coverage is 86.52%.

❗ Current head 00394c6 differs from pull request most recent head 0ca3638. Consider uploading reports for the commit 0ca3638 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #7035      +/-   ##
===========================================
+ Coverage    63.87%   63.92%   +0.05%     
===========================================
  Files          330      330              
  Lines        41838    41897      +59     
===========================================
+ Hits         26720    26779      +59     
  Misses       15118    15118              
Impacted Files Coverage Δ
src/core/Config.h 100.00% <ø> (ø)
src/core/Database.h 100.00% <ø> (ø)
src/core/Tools.h 0.00% <ø> (ø)
src/gui/ApplicationSettingsWidget.h 100.00% <ø> (ø)
src/gui/ApplicationSettingsWidget.cpp 52.72% <50.00%> (-0.14%) ⬇️
src/core/Database.cpp 83.69% <80.00%> (+0.45%) ⬆️
src/cli/Add.cpp 90.14% <100.00%> (ø)
src/cli/AddGroup.cpp 94.87% <100.00%> (ø)
src/cli/Create.cpp 91.67% <100.00%> (ø)
src/cli/Edit.cpp 89.77% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7811f10...0ca3638. Read the comment docs.

@libklein
Copy link
Contributor Author

@ijordse The current behavior is to name backups according to the pattern specified and save them under the given path. So a pattern of "{DB_NAME}-{TIME:dd.MM.yyyy}.backup" with a path of "/tmp" and db name "test" would save backups as "/tmp/test-11.10.2021.backup". Is that not what your comment suggests? Could you elaborate?

src/core/Config.cpp Outdated Show resolved Hide resolved
src/core/Database.cpp Outdated Show resolved Hide resolved
src/gui/ApplicationSettingsWidget.cpp Outdated Show resolved Hide resolved
src/gui/DatabaseWidget.cpp Outdated Show resolved Hide resolved
src/gui/DatabaseWidget.cpp Outdated Show resolved Hide resolved
src/gui/DatabaseWidget.cpp Outdated Show resolved Hide resolved
src/cli/Add.cpp Show resolved Hide resolved
tests/TestDatabase.cpp Show resolved Hide resolved
src/gui/ApplicationSettingsWidget.cpp Outdated Show resolved Hide resolved
src/gui/ApplicationSettingsWidget.cpp Outdated Show resolved Hide resolved
src/gui/ApplicationSettingsWidget.cpp Outdated Show resolved Hide resolved
@droidmonkey droidmonkey force-pushed the feature/3279-choose-backup-location branch from 7d74520 to 5166f83 Compare October 25, 2021 03:30
@droidmonkey
Copy link
Member

droidmonkey commented Oct 25, 2021

Minor cleanup. I removed the ConfigContext since it doesn't conform to our code standards and it really should be handled in the init() instead. Although I am getting a failure in the backup test locally but in autoreload test on ci.

tests/gui/TestGui.cpp Outdated Show resolved Hide resolved
@libklein
Copy link
Contributor Author

Minor cleanup. I removed the ConfigContext since it doesn't conform to our code standards and it really should be handled in the init() instead. Although I am getting a failure in the backup test locally but in autoreload test on ci.

Im not sure if this is a good idea, especially against the background of the test failure the last commit caused. I think we need a more robust solution here, it's way to easy to forget adding/removing respective config()->set calls when editing tests.

I think it makes sense that the init() method is responsible for providing a clean test environment and would suggest simply reloading the config in init() or resetting it to defaults. In line with this, tests should not depend on the value of specific settings even after calls to init() but rather set those they depend on in the test body (thats essentially why the AutoreloadDatabase test failed).

@libklein libklein requested a review from droidmonkey October 30, 2021 14:44
@libklein
Copy link
Contributor Author

Would you mind labeling the PR with "hacktoberfest-accepted"? I'm fine with doing further modifications, but it's almost the end of October and i believe that it satisfies their expectations w.r.t. quality at this point.

I believe that the windows gui test failure is transient and not caused by the PR.

@droidmonkey
Copy link
Member

I was actually working on this as you committed. I simplified the tools function a lot.

src/core/Tools.cpp Outdated Show resolved Hide resolved
@droidmonkey
Copy link
Member

I'm going to look into the test failure...

tests/gui/TestGui.cpp Outdated Show resolved Hide resolved
@droidmonkey droidmonkey force-pushed the feature/3279-choose-backup-location branch 3 times, most recently from fdf0fab to 2bccaf8 Compare November 4, 2021 11:06
libklein and others added 2 commits November 7, 2021 17:18
Update database saveAs() and save() usages.

- Default backupFilePath is '{DB_FILENAME}.old.kdbx' to conform to existing standards
- Implement backupPathPattern tests.
- Show tooltip on how to format database backup location text field.

Code cleanup

* Remove ConfigContext addition

Remove dependency on default config setting in AutoreloadDatabase, Lines 361-368.

Create substituteBackupFilePathPattern in Tools.cpp.

Add tests for substituteBackupFilePathPattern.
@droidmonkey droidmonkey force-pushed the feature/3279-choose-backup-location branch from 00394c6 to 0ca3638 Compare November 7, 2021 22:18
@droidmonkey droidmonkey merged commit 84ff6a1 into keepassxreboot:develop Nov 7, 2021
@s-KaiNet
Copy link

Thank you for this feature! That was the only missing thing that prevented me to migrate from classic KeePass.

@phoerious phoerious added pr: new feature Pull request that adds a new feature and removed new feature labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest pr: new feature Pull request that adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Choose Backup Location
5 participants