Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Mar 16, 2024
0 parents commit 9f45cef
Show file tree
Hide file tree
Showing 20 changed files with 3,475 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
/dist/
/dev/
26 changes: 26 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"eqeqeq": 2,
"no-duplicate-imports": "error",
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "never"]
},
"env": {
"node": true
}
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto eol=lf
/dist/* -diff linguist-generated=true
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: szapp
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: build

on:
workflow_dispatch:
push:
pull_request:
branches: [main]

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint

build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: rm -rf dist
- run: npm ci
- run: npm run build
- run: npm pack --dry-run
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
/dev/
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules/
/.*
/src/
/dev/
/tsconfig.json
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
/dist/
/dev/
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": false,
"singleQuote": true,
"singleAttributePerLine": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 140,
"endOfLine": "lf"
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"files.eol": "\n",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "never",
"source.fixAll.format": "never"
},
"typescript.tsdk": "./node_modules/typescript/lib"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sören Zapp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Filen Snapshot

[![build](https://github.com/szapp/filen-snapshot/actions/workflows/build.yml/badge.svg)](https://github.com/szapp/filen-snapshot/actions/workflows/build.yml)

Create simple snapshots to back up your files and directories in your Filen.io drive

## Features

Simple backup tool that copies one or several directory trees into a designated directory to serve as a snapshot in time.

There is no functionality beyond the automated copy process.
This package can be setup locally to run on a schedule.

## Usage

Install

```
npm install szapp/filen-snapshot
```

Import

```typescript
// JavaScript
const createSnapshot = require('filen-snapshot')
// TypeScript
import createSnapshot from 'filen-snapshot'
```

Use

```typescript
await createSnapshot({
email: 'filen-user@example.com', // Filen account email
password: 'filen-password', // Filen account password
twoFactorCode: '123456', // Two-factor authentication TOTP (if enabled and twoFactorSecret is not specified)
twoFactorSecret: 'JFSU4NNSFGFLOPL2' // Two-factor authentication secret (if enabled and twoFactorCode is not specified)
localPath: 'C:/Users/Admin/Filen/' // Local path to Filen (if available, allows faster backups by uploading local files instead of downloading and uploading cloud files)
source: ['/Documents/Important/', '/Documents/Work/', '/Photos/'] // Source directories (one or several paths relative to the root directory of the Filen drive)
destination: '/Snapshots/' // Snapshot directory (relative to the root directory of the Filen drive, in which the snapshot will be created)
snapshotName: 'yyyy-MM-dd_HH.mm.ss' // Default: 'yyyy-MM-dd_HH-mm-ss' (name of the snapshot directory, formatted with Luxon.DateTime.toFormat)
})
```

Mind that the login information is exposed if entered into the node REPL.
A more secure alternative is to store the arguments safely to disk and provide a path to the JSON file.

```typescript
await createSnapshot('path/to/config.json')
```

The code above will result in the following directory backup:

```
Filen drive/
├── Documents/
├── Photos/
├── ...
└── Snapshots/
├── ...
└── 2024-03-16_23.10.45/
├── Documents/
│ ├── Important/
│ └── Work/
└── Photos/
```

## Usage without knowledge of Node.js

1. Download and install [`nvm`](https://github.com/nvm-sh/nvm) (or [`nvm for windows`](https://github.com/coreybutler/nvm-windows))
2. Install the latest node version and npm
```bash
nvm install latest && nvm use latest
```
(Possibly restart your terminal)
3. Install this package
```bash
npm install -g szapp/filen-snapshot
```
(Possibly restart your terminal)
4. Create JavaScript file `runSnapshot.js` and adjust the following content
```javascript
const createSnapshot = require('filen-snapshot')
async function main() {
await createSnapshot({
email: 'filen-user@example.com', // Filen account email
password: 'filen-password', // Filen account password
twoFactorCode: '123456', // Two-factor authentication TOTP (if enabled and twoFactorSecret is not specified)
twoFactorSecret: 'JFSU4NNSFGFLOPL2' // Two-factor authentication secret (if enabled and twoFactorCode is not specified)
localPath: 'C:/Users/Admin/Filen/' // Local path to Filen (if available, allows faster backups by uploading local files instead of downloading and uploading cloud files)
source: ['/Documents/Important/', '/Documents/Work/', '/Photos/'] // Source directories (one or several paths relative to the root directory of the Filen drive)
destination: '/Snapshots/' // Snapshot directory (relative to the root directory of the Filen drive, in which the snapshot will be created)
snapshotName: 'yyyy-MM-dd_HH.mm.ss' // Default: 'yyyy-MM-dd_HH-mm-ss' (name of the snapshot directory, formatted with Luxon.DateTime.toFormat)
})
}
main()
```
5. Run from terminal with
```bash
node runSnapshot.js
```

## Details

- Because of the encryption there is no simple copy functionality in the cloud.
All files will be decrypted downloaded and uploaded into the snapshot directory.
This will be quite a slow process and demanding on traffic and possibly unsafe (depending on the use of the local machine).
A safer alternative is to provide the `localPath` to the Filen drive on the computer (if available).
The files will then be uploaded directly which is much faster.
Note that in both cases, the files are copied directly into the cloud and the snapshot directory does not have to be synced locally.

- Use at your own risk.
The Filen SDK is still under active development and not meant for production.
Although the logic of this package here is very concise, it was not thoroughly tested.
12 changes: 12 additions & 0 deletions dist/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f45cef

Please sign in to comment.