Skip to content

Commit

Permalink
Merge pull request #10 from CodeLit/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
CodeLit authored Sep 22, 2023
2 parents 153ba6f + e7fca82 commit 245dbf3
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 19 deletions.
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,34 @@ docker-compose up
## Advanced configuration

You can also exclude files and folders from backup. Use **filter** option
with [predefined patterns](https://www.npmjs.com/package/maximatch).
with [patterns](https://www.npmjs.com/package/maximatch).

```js
const backup_config_json = {
Example of backups-config.json:

```json
{
"type": "local-storage",
"copies": {
"daily": 1
},
"filter": [
"/node_modules/**", // exclude node_modules folder recursively
"!**/*.bin", // exclude .bin files from filter
"/data/logs/**",
"/package.lock",
"/(?<=\\/).*(\n?=\\.log)/", // filtering .log files using regular expression
"**" // exclude all files
"node_modules/**",
"**/*.log",
"data/folder/*",
"package.lock",
"**/*_fileending.*"
]
}
```

Options above is:

- Exclude files inside **node_modules** folder recursively
- Exclude all **.log** files recursively
- Exclude all inside **data/folder** not-recursively
- Exclude **package.lock**
- Exclude files recursively by ending **_fileending**

## Mega Online Cloud storage integration

[Link to official mega website](https://mega.nz/)
Expand All @@ -75,10 +87,7 @@ Config example:
"email": "email-name@mail.me",
"password": "!test24passWord",
"copies": {
"daily": 1,
"weekly": 1,
"monthly": 1,
"annually": 1
"daily": 1
}
}
```
7 changes: 7 additions & 0 deletions src/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ async function handeBackup(

// https://www.npmjs.com/package/maximatch
backup.filter = backupJsonData.filter || [];

// Add ! at the beginning of each pattern to exclude it
backup.filter = backup.filter.map((element) => '!' + element);

// Adding ** at the beginning of filter to match all files recursively
backup.filter.unshift('**');

if (backupJsonData.copies.daily)
await backup.daily(backupJsonData.copies.daily);
if (backupJsonData.copies.weekly)
Expand Down
6 changes: 3 additions & 3 deletions tests/projects/single-project/backups-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"annually": 1
},
"filter": [
"**",
"!**/*.jar",
"/(?<=\\/).*(\n?=\\.jar)/"
"**/*.bak",
"**/excluded_file.txt",
"excluded_folder/**"
]
}
1 change: 1 addition & 0 deletions tests/projects/single-project/excluded_extension.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
1 change: 1 addition & 0 deletions tests/projects/single-project/excluded_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
1 change: 1 addition & 0 deletions tests/projects/single-project/src/excluded_extension.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
1 change: 1 addition & 0 deletions tests/projects/single-project/src/excluded_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
7 changes: 4 additions & 3 deletions tests/projects/test-project/backups-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"annually": 2
},
"filter": [
"**",
"!**/*.jar",
"/(?<=\\/).*(\n?=\\.jar)/"
"**/*.bak",
"*_filename.bkp",
"**/excluded_file.txt",
"excluded_folder/**"
]
}
1 change: 1 addition & 0 deletions tests/projects/test-project/excluded_extension.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
1 change: 1 addition & 0 deletions tests/projects/test-project/excluded_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
1 change: 1 addition & 0 deletions tests/projects/test-project/src/excluded_extension.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.
1 change: 1 addition & 0 deletions tests/projects/test-project/src/excluded_filename.bkp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file content.

0 comments on commit 245dbf3

Please sign in to comment.