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

New setting: Allow creating subfolders for each profile #69

Conversation

personalizedrefrigerator
Copy link
Contributor

@personalizedrefrigerator personalizedrefrigerator commented Feb 7, 2024

Summary

Adds an option that, when enabled, creates a subdirectory for the current profile and appends it to the backup path.

Related to laurent22/joplin#9857.

Example

For example, if the user's backup path is set to the home directory and create subfolder is enabled, creating a backup from the default profile might cause the directory structure to look like this:

📂 home/
| 📂 Documents/
| 📂 JoplinBackup/
| | 📂 default/
| | |  📂 profile/
| | |  | 📄 settings.json
| | |  📄 all_notebooks.jex

If a backup is then made from a profile with ID 9y9ql8ji,

📂 home/
| 📂 Documents/
| 📂 JoplinBackup/
| | 📂 default/
| | |  📂 profile/
| | |  | 📄 settings.json
| | |  📄 all_notebooks.jex
| | 📂 profile-9y9ql8ji/
| | |  📂 profile/
| | |  | 📄 settings.json
| | |  📄 all_notebooks.jex

Testing

This pull request has been manually tested using Joplin 2.14.12 by

  1. Launching an instance of Joplin with two profiles configured
  2. Creating a backup from the non-default profile
  3. Verifying that a profile-9y9ql8ji directory has been created in /home/username-here/JoplinBackup/
  4. Creating a backup from the default profile
  5. Verifying that a default directory has been created in /home/username-here/JoplinBackup/

Comment on lines +298 to +304
// We assume that Joplin's profile structure is the following
// rootProfileDir/
// | profileDir/
// | | [[profile content]]
// or, if using the default,
// rootProfileDir/
// | [[profile content]]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what Joplin's profile structure currently looks like. However, it doesn't seem to be documented anywhere...

Reading profiles.json (which seems to not always exist) in the root profile directory may be another way to get this information. It also doesn't seem to be documented though.

@personalizedrefrigerator personalizedrefrigerator changed the base branch from master to develop February 7, 2024 18:15
public: true,
advanced: true,
label: i18n.__("settings.createSubfolderPerProfile.label"),
description: i18n.__("settings.createSubfolderPerProfile.description"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to use SettingStorage.File here so that this setting can be backed up. This wouldn't be consistent with the other settings though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My opinion is that there must be a Joplin API to backup all plugin settings and restore settings from selected plugins.
In my opinion, SettingStorage.File is not a good idea and not a good way to proceed. If so, Joplin should automatically convert all settings in one version to SettingStorage.File and not provide x ways.
I also don't understand why all the settings from the database have to be in a json file. But that is a different topic.

@@ -136,6 +136,15 @@ export namespace Settings {
label: i18n.__("settings.createSubfolder.label"),
description: i18n.__("settings.createSubfolder.description"),
},
createSubfolderPerProfile: {
value: false,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should enable this by default ... But not for already installed versions.
Can be made in the function upgradeBackupPluginVersion.

Or what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what do you think?

Currently, the upstream pull request makes Joplin responsible for setting the default backup directory to the home directory (rather this plugin). As such, there are tradeoffs to having this setting enabled by default.

Some reason(s) to not enable this by default:

  • Extra directories: If the default backup directory for this plugin is kept as the user's profile directory, backups would then look like this: profileDir/JoplinBackup/default. Because each subprofile has its own profile directory, subprofile backups would be in directories like this: profileDir/profile-abcd/JoplinBackup/profile-abcd. Observe that each JoplinBackup directory would have exactly one subdirectory.

Some reasons to enable this by default:

  • Consistency: It will need to be enabled by default in the built-in version of Simple Backup to prevent backups from different profiles from overwriting one another. Enabling it here would then be consistent with the built-in version.
    • The default values of settings in built-in plugins can be overridden here.
  • Data safety: If a user manually changes multiple profiles to back up to the same location, having this setting enabled could prevent backups from being overwritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To summarize, I think enabling this by default only makes sense in the version built-in to Joplin. In other versions, the default backup location is within the profile directory, which is different for each profile.

@JackGruber
Copy link
Owner

The README.md is created in the profile dir of the backup and not in the root directory.
The test for the readme should also consider create subfolder and subfolder for profiles.

@JackGruber JackGruber merged commit a402958 into JackGruber:develop Feb 22, 2024
1 check passed
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 this pull request may close these issues.

2 participants