Skip to content

Commit

Permalink
#11 Make zip compression level selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
JackGruber committed Jul 19, 2021
1 parent 27ef3d3 commit c4b0097
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Improved: Use of moments token
- Fix: #16 Prevent multiple simultaneous backup runs
- Add: #11 Make zip compression level selectable

## v1.0.1 (2021-07-03)

Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ The backup started manually by `Create backup` respects all the settings except

Go to `Tools > Options > Backup`

| Option | Description | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------- |
| `Backup path` | Where to save the backups to. <br>This path is exclusive for the Joplin backups, there should be no other data in it! | |
| `Single JEX` | Create only one JEX file for all notebooks | `false` |
| `Keep x backups` | How many backups should be kept | `1` |
| `Backups interval in hours` | Create a backup every X hours | `24` |
| `Only on change` | Creates a backup at the specified backup interval only if there was a change to a `note`, `tag`, `resource` or `notebook` | `false` |
| `Password protected backups` | Protect the backups via encrypted Zip archive. | `false` |
| `Logfile` | Loglevel for backup.log | `error` |
| `Create zip archive` | Save backup data in a Zip archive | `No` |
| `Temporary export path` | The data is first exported into this path before it is copied to the backup `Backup path`. | `` |
| `Backup set name` | Name of the backup set if multiple backups are to be keep. [Available moment tokens](https://momentjs.com/docs/#/displaying/format/), which can be used with `{<TOKEN>}` | `{YYYYMMDDHHmm}` |
| Option | Description | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |
| `Backup path` | Where to save the backups to. <br>This path is exclusive for the Joplin backups, there should be no other data in it! | |
| `Single JEX` | Create only one JEX file for all notebooks | `false` |
| `Keep x backups` | How many backups should be kept | `1` |
| `Backups interval in hours` | Create a backup every X hours | `24` |
| `Only on change` | Creates a backup at the specified backup interval only if there was a change to a `note`, `tag`, `resource` or `notebook` | `false` |
| `Password protected backups` | Protect the backups via encrypted Zip archive. | `false` |
| `Logfile` | Loglevel for backup.log | `error` |
| `Create zip archive` | Save backup data in a Zip archive | `No` |
| `Zip compression Level` | Compression level for zip archive archive | `Copy (no compression)` |
| `Temporary export path` | The data is first exported into this path before it is copied to the backup `Backup path`. | `` |
| `Backup set name` | Name of the backup set if multiple backups are to be keep. [Available moment tokens](https://momentjs.com/docs/#/displaying/format/), which can be used with `{<TOKEN>}` | `{YYYYMMDDHHmm}` |

## Keyboard Shortcuts

Expand Down
15 changes: 14 additions & 1 deletion src/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Backup {
private password: string;
private backupStartTime: Date;
private zipArchive: string;
private compressionLevel: number;
private singleJex: boolean;
private backupSetName: string;

Expand Down Expand Up @@ -202,6 +203,9 @@ class Backup {
this.backupRetention = await joplinWrapper.settingsValue("backupRetention");

this.zipArchive = await joplinWrapper.settingsValue("zipArchive");
this.compressionLevel = await joplinWrapper.settingsValue(
"compressionLevel"
);
this.singleJex = await joplin.settings.value("singleJex");

this.backupSetName = await joplinWrapper.settingsValue("backupSetName");
Expand Down Expand Up @@ -284,6 +288,7 @@ class Backup {
"lastBackup",
"fileLogLevel",
"zipArchive",
"compressionLevel",
"exportPath",
"backupSetName",
"backupInfo",
Expand Down Expand Up @@ -454,7 +459,15 @@ class Backup {
options: string[] = null
): Promise<string> {
this.log.verbose(`Add ${addFile} to zip ${zipFile}`);
const status = await sevenZip.add(zipFile, addFile, password, options);

let zipOptions: any = {};
if (options) {
zipOptions = { ...zipOptions, ...options };
}
zipOptions.method = [];
zipOptions.method.push("x" + this.compressionLevel);

const status = await sevenZip.add(zipFile, addFile, password, zipOptions);
if (status !== true) {
await this.showError("createZipArchive: " + status);
throw new Error("createZipArchive: " + status);
Expand Down
18 changes: 18 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ export namespace Settings {
description:
"If a password protected backups is set, a zip archive is always created.",
},
compressionLevel: {
value: 0,
type: SettingItemType.Int,
section: "backupSection",
isEnum: true,
public: true,
label: "Zip compression level",
advanced: true,
options: {
0: "Copy (no compression)",
1: "Fastest",
3: "Fast",
5: "Normal",
7: "Maximum",
9: "Ultra",
},
description: "Compression level for zip archive.",
},
exportPath: {
value: "",
type: SettingItemType.String,
Expand Down
3 changes: 0 additions & 3 deletions src/sevenZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export namespace sevenZip {
_7zOptions = { ..._7zOptions, ...options };
}

_7zOptions.method = [];
_7zOptions.method.push("x0");

if (password !== null) {
_7zOptions = await addPassword(_7zOptions, password);
_7zOptions.method.push("he");
Expand Down

0 comments on commit c4b0097

Please sign in to comment.