@ps-aux/nodebup 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bup/AggregateBackupController.js +3 -3
- package/lib/config/Config.js +1 -1
- package/lib/config/index.js +14 -0
- package/lib/config/validateConfigAgainstSchema.js +3 -1
- package/lib/ctx/Context.js +5 -1
- package/lib/storage/BackupClient.js +5 -0
- package/lib/storage/{restic/ResticStorageBackend.js → BackupClientStorageBackend.js} +4 -4
- package/lib/storage/StorageBackendProvider.js +31 -7
- package/lib/storage/b2/B2CredentialsProvider.js +55 -0
- package/lib/storage/rclone/RCloneClientFactory.js +69 -0
- package/lib/storage/rclone/RcloneClient.js +87 -0
- package/lib/storage/rclone/RcloneClient.spec.js +85 -0
- package/lib/storage/restic/ResticClient.js +6 -15
- package/lib/storage/restic/ResticClient.spec.js +6 -20
- package/lib/storage/restic/ResticClientFactory.js +10 -34
- package/lib/storage/restic/ResticController.js +2 -2
- package/lib/tools/gpg/Gpg.js +8 -1
- package/lib/tools/gpg/Gpg.spec.js +15 -4
- package/lib/tools/shell/Shell.js +1 -1
- package/package.json +3 -2
@@ -7,8 +7,6 @@ exports.AggregateBackupController = void 0;
|
|
7
7
|
|
8
8
|
var _FsSyncer = require("../fs/fssync/FsSyncer");
|
9
9
|
|
10
|
-
var _Config = require("../config/Config");
|
11
|
-
|
12
10
|
var _Gpg = require("../tools/gpg/Gpg");
|
13
11
|
|
14
12
|
var _Fs = require("../fs/Fs");
|
@@ -25,13 +23,15 @@ var _Path = require("../fs/path/Path");
|
|
25
23
|
|
26
24
|
var _StorageBackendProvider = require("../storage/StorageBackendProvider");
|
27
25
|
|
26
|
+
var _config = require("../config");
|
27
|
+
|
28
28
|
var _dec, _dec2, _dec3, _dec4, _class;
|
29
29
|
|
30
30
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
31
31
|
|
32
32
|
let AggregateBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
33
33
|
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 6);
|
34
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _Gpg.Gpg === "undefined" ? Object : _Gpg.Gpg, typeof _SshKeyManager.SshKeyManager === "undefined" ? Object : _SshKeyManager.SshKeyManager, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _StorageBackendProvider.StorageBackendProvider === "undefined" ? Object : _StorageBackendProvider.StorageBackendProvider, typeof
|
34
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _Gpg.Gpg === "undefined" ? Object : _Gpg.Gpg, typeof _SshKeyManager.SshKeyManager === "undefined" ? Object : _SshKeyManager.SshKeyManager, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _StorageBackendProvider.StorageBackendProvider === "undefined" ? Object : _StorageBackendProvider.StorageBackendProvider, typeof _config.Config === "undefined" ? Object : _config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class AggregateBackupController {
|
35
35
|
constructor(gpg, ssh, fs, fsSyncer, log, storageBackendProvider, cfg) {
|
36
36
|
this.gpg = gpg;
|
37
37
|
this.ssh = ssh;
|
package/lib/config/Config.js
CHANGED
@@ -17,7 +17,7 @@ const expandPaths = (cfg, exp, cwd) => {
|
|
17
17
|
cfg.storage.filter(s => s.type === 'file').map(s => s).forEach(s => {
|
18
18
|
s.path = exp(s.path);
|
19
19
|
});
|
20
|
-
cfg.storage.filter(s => s.type === 'restic').map(s => s).forEach(s => {
|
20
|
+
cfg.storage.filter(s => s.type === 'restic' || s.type === 'rclone').map(s => s).forEach(s => {
|
21
21
|
if (s.credentialsFile) s.credentialsFile = exp(s.credentialsFile);
|
22
22
|
s.passwordFile = exp(s.passwordFile);
|
23
23
|
if (s.repo.startsWith('local:')) s.repo = (0, _expandAndCreatePath.expandStrPath)(s.repo, cwd);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.StorageTypeConst = void 0;
|
7
|
+
let StorageTypeConst;
|
8
|
+
exports.StorageTypeConst = StorageTypeConst;
|
9
|
+
|
10
|
+
(function (StorageTypeConst) {
|
11
|
+
StorageTypeConst["Restic"] = "restic";
|
12
|
+
StorageTypeConst["File"] = "file";
|
13
|
+
StorageTypeConst["RClone"] = "rclone";
|
14
|
+
})(StorageTypeConst || (exports.StorageTypeConst = StorageTypeConst = {}));
|
@@ -7,6 +7,8 @@ exports.validateConfigAgainstSchema = void 0;
|
|
7
7
|
|
8
8
|
var _joi = _interopRequireDefault(require("@hapi/joi"));
|
9
9
|
|
10
|
+
var _index = require("./index");
|
11
|
+
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
13
|
|
12
14
|
const DirTaskSchema = _joi.default.object({
|
@@ -23,7 +25,7 @@ const KeyTaskSchema = _joi.default.object({
|
|
23
25
|
|
24
26
|
const createStorageSchema = props => _joi.default.object({
|
25
27
|
name: _joi.default.string(),
|
26
|
-
type: _joi.default.string(),
|
28
|
+
type: _joi.default.string().valid(_index.StorageTypeConst.Restic, _index.StorageTypeConst.File, _index.StorageTypeConst.RClone),
|
27
29
|
...props
|
28
30
|
});
|
29
31
|
|
package/lib/ctx/Context.js
CHANGED
@@ -29,13 +29,17 @@ var _ResticClientFactory = require("../storage/restic/ResticClientFactory");
|
|
29
29
|
|
30
30
|
var _ResticController = require("../storage/restic/ResticController");
|
31
31
|
|
32
|
+
var _B2CredentialsProvider = require("../storage/b2/B2CredentialsProvider");
|
33
|
+
|
34
|
+
var _RCloneClientFactory = require("../storage/rclone/RCloneClientFactory");
|
35
|
+
|
32
36
|
const createContext = cfg => {
|
33
37
|
const c = new _inversify.Container();
|
34
38
|
c.bind(_ContextSymbols.AppConfig_).toConstantValue(cfg);
|
35
39
|
const log = new _AppLogger.AppLogger();
|
36
40
|
c.bind(_ContextSymbols.Log_).toConstantValue(log);
|
37
41
|
c.bind(_AppLogger.AppLogger).toConstantValue(log);
|
38
|
-
const self = [_Gpg.Gpg, _Shell.Shell, _Fs.Fs, _FsSyncer.FsSyncer, _SshKeyManager.SshKeyManager, _StorageBackendProvider.StorageBackendProvider, _ResticClientFactory.ResticClientFactory, _AggregateBackupController.AggregateBackupController, _ResticController.ResticController];
|
42
|
+
const self = [_Gpg.Gpg, _Shell.Shell, _Fs.Fs, _FsSyncer.FsSyncer, _SshKeyManager.SshKeyManager, _StorageBackendProvider.StorageBackendProvider, _ResticClientFactory.ResticClientFactory, _AggregateBackupController.AggregateBackupController, _ResticController.ResticController, _B2CredentialsProvider.B2CredentialsProvider, _RCloneClientFactory.RCloneClientFactory];
|
39
43
|
self.forEach(s => c.bind(s).toSelf());
|
40
44
|
return c;
|
41
45
|
};
|
@@ -3,13 +3,13 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.BackupClientStorageBackend = void 0;
|
7
7
|
|
8
|
-
var _Path = require("
|
8
|
+
var _Path = require("../fs/path/Path");
|
9
9
|
|
10
10
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
11
|
|
12
|
-
class
|
12
|
+
class BackupClientStorageBackend {
|
13
13
|
constructor(client) {
|
14
14
|
this.client = client;
|
15
15
|
|
@@ -20,4 +20,4 @@ class ResticStorageBackend {
|
|
20
20
|
|
21
21
|
}
|
22
22
|
|
23
|
-
exports.
|
23
|
+
exports.BackupClientStorageBackend = BackupClientStorageBackend;
|
@@ -13,35 +13,59 @@ var _LocalFileStorageBackend = require("./local-file/LocalFileStorageBackend");
|
|
13
13
|
|
14
14
|
var _ContextSymbols = require("../ctx/ContextSymbols");
|
15
15
|
|
16
|
-
var
|
16
|
+
var _config = require("../config");
|
17
17
|
|
18
18
|
var _ResticClientFactory = require("./restic/ResticClientFactory");
|
19
19
|
|
20
|
-
var
|
20
|
+
var _BackupClientStorageBackend = require("./BackupClientStorageBackend");
|
21
21
|
|
22
22
|
var _Fs = require("../fs/Fs");
|
23
23
|
|
24
|
+
var _RCloneClientFactory = require("./rclone/RCloneClientFactory");
|
25
|
+
|
24
26
|
var _dec, _dec2, _dec3, _dec4, _class;
|
25
27
|
|
26
28
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
27
29
|
|
28
30
|
let StorageBackendProvider = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
29
|
-
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined,
|
30
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof
|
31
|
-
constructor(fsSyncer, resticFac, fs, cfg) {
|
31
|
+
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 4);
|
32
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _FsSyncer.FsSyncer === "undefined" ? Object : _FsSyncer.FsSyncer, typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _RCloneClientFactory.RCloneClientFactory === "undefined" ? Object : _RCloneClientFactory.RCloneClientFactory, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _config.Config === "undefined" ? Object : _config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class StorageBackendProvider {
|
33
|
+
constructor(fsSyncer, resticFac, rcloneFac, fs, cfg) {
|
32
34
|
this.fsSyncer = fsSyncer;
|
33
35
|
this.resticFac = resticFac;
|
36
|
+
this.rcloneFac = rcloneFac;
|
34
37
|
this.fs = fs;
|
35
38
|
this.cfg = cfg;
|
36
39
|
|
37
40
|
_defineProperty(this, "provide", name => {
|
38
41
|
const s = this.cfg.storage.find(s => s.name === name);
|
39
42
|
if (!s) throw new Error(`No such storage '${name}'`);
|
40
|
-
|
43
|
+
let b;
|
44
|
+
|
45
|
+
switch (s.type) {
|
46
|
+
case _config.StorageTypeConst.File:
|
47
|
+
b = this.localFile(s);
|
48
|
+
break;
|
49
|
+
|
50
|
+
case _config.StorageTypeConst.Restic:
|
51
|
+
b = this.restic(s);
|
52
|
+
break;
|
53
|
+
|
54
|
+
case _config.StorageTypeConst.RClone:
|
55
|
+
b = this.rclone(s);
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
|
59
|
+
if (!b) throw new Error(`Unsupported storage type ${s.type}`);
|
60
|
+
return b;
|
61
|
+
});
|
62
|
+
|
63
|
+
_defineProperty(this, "rclone", cfg => {
|
64
|
+
return new _BackupClientStorageBackend.BackupClientStorageBackend(this.rcloneFac.create(cfg));
|
41
65
|
});
|
42
66
|
|
43
67
|
_defineProperty(this, "restic", cfg => {
|
44
|
-
return new
|
68
|
+
return new _BackupClientStorageBackend.BackupClientStorageBackend(this.resticFac.create(cfg));
|
45
69
|
});
|
46
70
|
|
47
71
|
_defineProperty(this, "localFile", cfg => {
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.B2CredentialsProvider = void 0;
|
7
|
+
|
8
|
+
var _joi = _interopRequireDefault(require("@hapi/joi"));
|
9
|
+
|
10
|
+
var _inversify = require("inversify");
|
11
|
+
|
12
|
+
var _Fs = require("../../fs/Fs");
|
13
|
+
|
14
|
+
var _dec, _dec2, _dec3, _class;
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
|
+
|
20
|
+
const CredentialsFileSchema = _joi.default.object({
|
21
|
+
keyID: _joi.default.string(),
|
22
|
+
keyName: _joi.default.string().optional(),
|
23
|
+
applicationKey: _joi.default.string()
|
24
|
+
});
|
25
|
+
|
26
|
+
const validateCredentials = obj => {
|
27
|
+
const r = CredentialsFileSchema.validate(obj, {
|
28
|
+
presence: 'required',
|
29
|
+
allowUnknown: false
|
30
|
+
});
|
31
|
+
return r.error ? JSON.stringify(r.error) : null;
|
32
|
+
};
|
33
|
+
|
34
|
+
let B2CredentialsProvider = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs]), _dec(_class = _dec2(_class = _dec3(_class = class B2CredentialsProvider {
|
35
|
+
constructor(fs) {
|
36
|
+
this.fs = fs;
|
37
|
+
|
38
|
+
_defineProperty(this, "fromFile", path => {
|
39
|
+
const credJson = this.fs.readJson(path);
|
40
|
+
const validationErr = validateCredentials(credJson);
|
41
|
+
|
42
|
+
if (validationErr) {
|
43
|
+
throw new Error(`Invalid B2 credential in ${path}: ${validationErr}`);
|
44
|
+
}
|
45
|
+
|
46
|
+
const creds = credJson;
|
47
|
+
return {
|
48
|
+
accountId: creds.keyID,
|
49
|
+
key: creds.applicationKey
|
50
|
+
};
|
51
|
+
});
|
52
|
+
}
|
53
|
+
|
54
|
+
}) || _class) || _class) || _class);
|
55
|
+
exports.B2CredentialsProvider = B2CredentialsProvider;
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.RCloneClientFactory = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _Shell = require("../../tools/shell/Shell");
|
11
|
+
|
12
|
+
var _AppLogger = require("../../log/AppLogger");
|
13
|
+
|
14
|
+
var _Fs = require("../../fs/Fs");
|
15
|
+
|
16
|
+
var _RcloneClient = require("./RcloneClient");
|
17
|
+
|
18
|
+
var _B2CredentialsProvider = require("../b2/B2CredentialsProvider");
|
19
|
+
|
20
|
+
var _dec, _dec2, _dec3, _class;
|
21
|
+
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
|
+
|
24
|
+
const parseRepoUrl = url => {
|
25
|
+
const split = url.split(':');
|
26
|
+
if (split.length !== 2) throw new Error(`Illegal rclone URL ${url}`);
|
27
|
+
const type = split[0];
|
28
|
+
if (!['b2', 'local'].includes(type)) throw new Error(`Unknown rclone repo type ${type}`);
|
29
|
+
return {
|
30
|
+
type: type,
|
31
|
+
location: split[1]
|
32
|
+
};
|
33
|
+
};
|
34
|
+
|
35
|
+
let RCloneClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _B2CredentialsProvider.B2CredentialsProvider === "undefined" ? Object : _B2CredentialsProvider.B2CredentialsProvider]), _dec(_class = _dec2(_class = _dec3(_class = class RCloneClientFactory {
|
36
|
+
constructor(sh, log, fs, b2) {
|
37
|
+
this.sh = sh;
|
38
|
+
this.log = log;
|
39
|
+
this.fs = fs;
|
40
|
+
this.b2 = b2;
|
41
|
+
|
42
|
+
_defineProperty(this, "create", cfg => {
|
43
|
+
const {
|
44
|
+
type,
|
45
|
+
location
|
46
|
+
} = parseRepoUrl(cfg.repo);
|
47
|
+
const props = {
|
48
|
+
type,
|
49
|
+
location
|
50
|
+
};
|
51
|
+
const password = cfg.passwordFile && this.fs.readFile(cfg.passwordFile).trim();
|
52
|
+
if (password) props.encryption = {
|
53
|
+
password
|
54
|
+
};
|
55
|
+
const creds = cfg.credentialsFile && this.b2.fromFile(cfg.credentialsFile);
|
56
|
+
|
57
|
+
if (type === 'b2') {
|
58
|
+
if (!creds) throw new Error(`Credentials are required for '${cfg.name}'`);
|
59
|
+
props.creds = creds;
|
60
|
+
} else {
|
61
|
+
if (creds) throw new Error(`Credentials not supported for local rclone`);
|
62
|
+
}
|
63
|
+
|
64
|
+
return new _RcloneClient.RcloneClient(props, this.sh, this.log);
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
}) || _class) || _class) || _class);
|
69
|
+
exports.RCloneClientFactory = RCloneClientFactory;
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.RcloneClient = void 0;
|
7
|
+
|
8
|
+
var _inversify = require("inversify");
|
9
|
+
|
10
|
+
var _types = require("../../types");
|
11
|
+
|
12
|
+
var _Shell = require("../../tools/shell/Shell");
|
13
|
+
|
14
|
+
var _dec, _dec2, _dec3, _class;
|
15
|
+
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Tested with: rclone v1.57.0
|
20
|
+
* TODO forwarding stdout to the logger
|
21
|
+
*/
|
22
|
+
let RcloneClient = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof RcloneConfig === "undefined" ? Object : RcloneConfig, typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _types.Log === "undefined" ? Object : _types.Log]), _dec(_class = _dec2(_class = _dec3(_class = class RcloneClient {
|
23
|
+
constructor(cfg, shell, log) {
|
24
|
+
this.cfg = cfg;
|
25
|
+
this.shell = shell;
|
26
|
+
this.log = log;
|
27
|
+
|
28
|
+
_defineProperty(this, "remoteName", 'my');
|
29
|
+
|
30
|
+
_defineProperty(this, "cryptRemoteName", 'crypt');
|
31
|
+
|
32
|
+
_defineProperty(this, "backup", from => {
|
33
|
+
this.log.debug('Running backup for ', this.cfg.type, this.cfg.location);
|
34
|
+
this.shell.exec(`rclone sync ${from.str()} ${this.actualRemoteName}:${this.cfg.location} --config=noconfig`, // Rclone logs error if the file is not set even though it supports env var interface
|
35
|
+
{
|
36
|
+
env: this.env()
|
37
|
+
});
|
38
|
+
});
|
39
|
+
|
40
|
+
_defineProperty(this, "restore", to => {
|
41
|
+
this.log.debug('Running restore for ', this.cfg.type, this.cfg.location);
|
42
|
+
this.shell.exec(`rclone sync ${this.actualRemoteName}:${this.cfg.location} ${to.str()} --config=noconfig`, {
|
43
|
+
env: this.env()
|
44
|
+
});
|
45
|
+
});
|
46
|
+
|
47
|
+
_defineProperty(this, "env", () => {
|
48
|
+
const {
|
49
|
+
type,
|
50
|
+
creds
|
51
|
+
} = this.cfg;
|
52
|
+
|
53
|
+
const myKey = val => `RCLONE_CONFIG_${this.remoteName.toUpperCase()}_${val.toUpperCase()}`;
|
54
|
+
|
55
|
+
const res = {
|
56
|
+
[myKey('type')]: type,
|
57
|
+
[myKey('hard_delete')]: true + ''
|
58
|
+
};
|
59
|
+
|
60
|
+
if (type === 'b2') {
|
61
|
+
if (!creds) throw new Error('B2 Rclone remote has to have credentials');
|
62
|
+
res[myKey('account')] = creds.accountId;
|
63
|
+
res[myKey('key')] = creds.key;
|
64
|
+
}
|
65
|
+
|
66
|
+
if (this.cfg.encryption) {
|
67
|
+
const pass = this.cfg.encryption.password;
|
68
|
+
|
69
|
+
const cryptKey = val => `RCLONE_CONFIG_${this.cryptRemoteName.toUpperCase()}_${val.toUpperCase()}`;
|
70
|
+
|
71
|
+
res[cryptKey('type')] = 'crypt';
|
72
|
+
res[cryptKey('remote')] = this.remoteName + ':' + this.cfg.location;
|
73
|
+
res[cryptKey('password')] = this.obscure(pass);
|
74
|
+
}
|
75
|
+
|
76
|
+
return res;
|
77
|
+
});
|
78
|
+
|
79
|
+
_defineProperty(this, "obscure", str => this.shell.execAndReturnVal(`rclone obscure ${str}`));
|
80
|
+
}
|
81
|
+
|
82
|
+
get actualRemoteName() {
|
83
|
+
return this.cfg.encryption ? this.cryptRemoteName : this.remoteName;
|
84
|
+
}
|
85
|
+
|
86
|
+
}) || _class) || _class) || _class);
|
87
|
+
exports.RcloneClient = RcloneClient;
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _AppLogger = require("../../log/AppLogger");
|
4
|
+
|
5
|
+
var _Shell = require("../../tools/shell/Shell");
|
6
|
+
|
7
|
+
var _test = require("../../../test");
|
8
|
+
|
9
|
+
var _Path = require("../../fs/path/Path");
|
10
|
+
|
11
|
+
var _RcloneClient = require("./RcloneClient");
|
12
|
+
|
13
|
+
var _dirCompare = require("dir-compare");
|
14
|
+
|
15
|
+
var _b2TestConfig = require("../../../test/b2TestConfig");
|
16
|
+
|
17
|
+
var _testHelper = require("../../../test/testHelper");
|
18
|
+
|
19
|
+
describe('RcloneClient', () => {
|
20
|
+
const l = new _AppLogger.AppLogger();
|
21
|
+
const getRestoreDir = (0, _test.testdataDirBuilder)('b2/restore');
|
22
|
+
describe('local', () => {
|
23
|
+
const backupDir = (0, _test.testDir)('backup/1');
|
24
|
+
const restoreDir = getRestoreDir('local');
|
25
|
+
const storeDir = (0, _test.testdataDir)('b2/store');
|
26
|
+
const cfg = {
|
27
|
+
type: 'local',
|
28
|
+
location: (0, _test.testdataDir)(storeDir),
|
29
|
+
encryption: {
|
30
|
+
password: 'foo123'
|
31
|
+
}
|
32
|
+
};
|
33
|
+
afterEach(() => {
|
34
|
+
(0, _testHelper.cleanDir)(storeDir);
|
35
|
+
(0, _testHelper.cleanDir)(restoreDir);
|
36
|
+
});
|
37
|
+
it('backup & restore', () => {
|
38
|
+
const sut = new _RcloneClient.RcloneClient(cfg, new _Shell.Shell(l), l);
|
39
|
+
sut.backup(_Path.AbsPath.from(backupDir));
|
40
|
+
sut.restore(_Path.AbsPath.from(restoreDir));
|
41
|
+
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
42
|
+
expect(res.same).toBeTrue();
|
43
|
+
});
|
44
|
+
it('backup & restore unencrypted', () => {
|
45
|
+
const sut = new _RcloneClient.RcloneClient({ ...cfg,
|
46
|
+
encryption: undefined
|
47
|
+
}, new _Shell.Shell(l), l);
|
48
|
+
sut.backup(_Path.AbsPath.from(backupDir));
|
49
|
+
sut.restore(_Path.AbsPath.from(restoreDir));
|
50
|
+
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
51
|
+
expect(res.same).toBeTrue();
|
52
|
+
});
|
53
|
+
});
|
54
|
+
describe('b2', () => {
|
55
|
+
const backupDir = (0, _test.testDir)('backup/2');
|
56
|
+
const b2Cfg = (0, _b2TestConfig.getB2TestConfig)('rclone');
|
57
|
+
|
58
|
+
if (!b2Cfg) {
|
59
|
+
console.log('No B2 config - skipping');
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
|
63
|
+
const sut = new _RcloneClient.RcloneClient({
|
64
|
+
type: 'b2',
|
65
|
+
location: b2Cfg.bucket,
|
66
|
+
creds: {
|
67
|
+
accountId: b2Cfg.accountId,
|
68
|
+
key: b2Cfg.key
|
69
|
+
},
|
70
|
+
encryption: {
|
71
|
+
password: 'foo123'
|
72
|
+
}
|
73
|
+
}, new _Shell.Shell(l), l);
|
74
|
+
const restoreDir = getRestoreDir('b2');
|
75
|
+
afterAll(() => {
|
76
|
+
(0, _testHelper.cleanDir)(restoreDir);
|
77
|
+
});
|
78
|
+
it('push adn restore data', () => {
|
79
|
+
sut.backup(_Path.AbsPath.from(backupDir));
|
80
|
+
sut.restore(_Path.AbsPath.from(restoreDir));
|
81
|
+
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
82
|
+
expect(res.same).toBeTrue();
|
83
|
+
});
|
84
|
+
});
|
85
|
+
});
|
@@ -5,16 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.ResticClient = void 0;
|
7
7
|
|
8
|
-
var _inversify = require("inversify");
|
9
|
-
|
10
|
-
var _types = require("../../types");
|
11
|
-
|
12
|
-
var _ContextSymbols = require("../../ctx/ContextSymbols");
|
13
|
-
|
14
|
-
var _Shell = require("../../tools/shell/Shell");
|
15
|
-
|
16
|
-
var _dec, _dec2, _dec3, _dec4, _class;
|
17
|
-
|
18
8
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
9
|
|
20
10
|
const normalizeUrl = url => {
|
@@ -30,9 +20,7 @@ const normalizeUrl = url => {
|
|
30
20
|
*/
|
31
21
|
|
32
22
|
|
33
|
-
|
34
|
-
return (0, _inversify.inject)(_ContextSymbols.TaskConfig_)(target, undefined, 2);
|
35
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof ResticConfig === "undefined" ? Object : ResticConfig, typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _types.Log === "undefined" ? Object : _types.Log]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class ResticClient {
|
23
|
+
class ResticClient {
|
36
24
|
constructor(cfg, shell, log) {
|
37
25
|
this.cfg = cfg;
|
38
26
|
this.shell = shell;
|
@@ -48,6 +36,7 @@ let ResticClient = (_dec = (0, _inversify.injectable)(), _dec2 = function (targe
|
|
48
36
|
});
|
49
37
|
|
50
38
|
_defineProperty(this, "backup", (cwd, from) => {
|
39
|
+
this.log.debug(`Running backup for repo=${this.url}`);
|
51
40
|
this.shell.exec(`restic backup ${from.str()}`, {
|
52
41
|
cwd: cwd.str(),
|
53
42
|
env: this.env()
|
@@ -55,6 +44,7 @@ let ResticClient = (_dec = (0, _inversify.injectable)(), _dec2 = function (targe
|
|
55
44
|
});
|
56
45
|
|
57
46
|
_defineProperty(this, "restore", to => {
|
47
|
+
this.log.debug('Running restore for repo=', this.url);
|
58
48
|
this.shell.exec(`restic restore latest --target ${to.str()}`, {
|
59
49
|
env: this.env()
|
60
50
|
});
|
@@ -72,7 +62,7 @@ let ResticClient = (_dec = (0, _inversify.injectable)(), _dec2 = function (targe
|
|
72
62
|
if (!cfg) throw new Error(`Repo url ${url} refers to Backblaze but no Backblaze config provided`);
|
73
63
|
return {
|
74
64
|
B2_ACCOUNT_ID: cfg.accountId,
|
75
|
-
B2_ACCOUNT_KEY: cfg.
|
65
|
+
B2_ACCOUNT_KEY: cfg.key
|
76
66
|
};
|
77
67
|
}
|
78
68
|
|
@@ -82,5 +72,6 @@ let ResticClient = (_dec = (0, _inversify.injectable)(), _dec2 = function (targe
|
|
82
72
|
this.url = normalizeUrl(cfg.repo.url);
|
83
73
|
}
|
84
74
|
|
85
|
-
}
|
75
|
+
}
|
76
|
+
|
86
77
|
exports.ResticClient = ResticClient;
|
@@ -8,34 +8,19 @@ var _Shell = require("../../tools/shell/Shell");
|
|
8
8
|
|
9
9
|
var _test = require("../../../test");
|
10
10
|
|
11
|
-
var _fs = _interopRequireDefault(require("fs"));
|
12
|
-
|
13
|
-
var _path = _interopRequireDefault(require("path"));
|
14
|
-
|
15
11
|
var _Path = require("../../fs/path/Path");
|
16
12
|
|
17
13
|
var _dirCompare = require("dir-compare");
|
18
14
|
|
19
15
|
var _testHelper = require("../../../test/testHelper");
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
const getBackblazeConfig = () => {
|
24
|
-
const path = _path.default.resolve(__dirname, '../../../.keys.json');
|
25
|
-
|
26
|
-
if (!_fs.default.existsSync(path)) return undefined;
|
27
|
-
const data = JSON.parse(_fs.default.readFileSync(path).toString());
|
28
|
-
return {
|
29
|
-
accountId: data.restic.backblaze.keyID,
|
30
|
-
accountKey: data.restic.backblaze.applicationKey
|
31
|
-
};
|
32
|
-
};
|
17
|
+
var _b2TestConfig = require("../../../test/b2TestConfig");
|
33
18
|
|
34
19
|
describe('ResticClient', () => {
|
35
20
|
const l = new _AppLogger.AppLogger();
|
36
21
|
const password = 'foo123';
|
37
|
-
const backupDir = (0, _test.testDir)('backup-me');
|
38
22
|
describe('local', () => {
|
23
|
+
const backupDir = (0, _test.testDir)('backup/1');
|
39
24
|
const repoDir = (0, _test.testdataDir)('my-repo');
|
40
25
|
const restoreDir = (0, _test.testdataDir)('restore/local');
|
41
26
|
const sut = new _ResticClient.ResticClient({
|
@@ -61,7 +46,8 @@ describe('ResticClient', () => {
|
|
61
46
|
});
|
62
47
|
});
|
63
48
|
describe('b2', () => {
|
64
|
-
const
|
49
|
+
const backupDir = (0, _test.testDir)('backup/2');
|
50
|
+
const b2Cfg = (0, _b2TestConfig.getB2TestConfig)('restic');
|
65
51
|
|
66
52
|
if (!b2Cfg) {
|
67
53
|
console.log('No B2 config - skipping');
|
@@ -69,7 +55,7 @@ describe('ResticClient', () => {
|
|
69
55
|
}
|
70
56
|
|
71
57
|
const restoreDir = (0, _test.testdataDir)('restore/b2');
|
72
|
-
const repoUrl = `b2
|
58
|
+
const repoUrl = `b2:` + b2Cfg.bucket;
|
73
59
|
const sut = new _ResticClient.ResticClient({
|
74
60
|
repo: {
|
75
61
|
password,
|
@@ -81,7 +67,7 @@ describe('ResticClient', () => {
|
|
81
67
|
(0, _testHelper.cleanDir)(restoreDir);
|
82
68
|
});
|
83
69
|
it('push adn restore data', () => {
|
84
|
-
//
|
70
|
+
// sut.prepareRepo()
|
85
71
|
sut.backup(_Path.AbsPath.from(backupDir), _Path.RelativePath.from('.'));
|
86
72
|
sut.restore(_Path.AbsPath.from(restoreDir));
|
87
73
|
const res = (0, _dirCompare.compareSync)(backupDir, restoreDir);
|
@@ -15,33 +15,18 @@ var _AppLogger = require("../../log/AppLogger");
|
|
15
15
|
|
16
16
|
var _Fs = require("../../fs/Fs");
|
17
17
|
|
18
|
-
var
|
18
|
+
var _B2CredentialsProvider = require("../b2/B2CredentialsProvider");
|
19
19
|
|
20
20
|
var _dec, _dec2, _dec3, _class;
|
21
21
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
-
|
24
22
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
keyName: _joi.default.string().optional(),
|
29
|
-
applicationKey: _joi.default.string()
|
30
|
-
});
|
31
|
-
|
32
|
-
const validateCredentials = obj => {
|
33
|
-
const r = CredentialsFileSchema.validate(obj, {
|
34
|
-
presence: 'required',
|
35
|
-
allowUnknown: false
|
36
|
-
});
|
37
|
-
return r.error ? JSON.stringify(r.error) : null;
|
38
|
-
};
|
39
|
-
|
40
|
-
let ResticClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs]), _dec(_class = _dec2(_class = _dec3(_class = class ResticClientFactory {
|
41
|
-
constructor(sh, log, fs) {
|
24
|
+
let ResticClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _B2CredentialsProvider.B2CredentialsProvider === "undefined" ? Object : _B2CredentialsProvider.B2CredentialsProvider]), _dec(_class = _dec2(_class = _dec3(_class = class ResticClientFactory {
|
25
|
+
constructor(sh, log, fs, b2) {
|
42
26
|
this.sh = sh;
|
43
27
|
this.log = log;
|
44
28
|
this.fs = fs;
|
29
|
+
this.b2 = b2;
|
45
30
|
|
46
31
|
_defineProperty(this, "create", cfg => {
|
47
32
|
const password = this.fs.readFile(cfg.passwordFile).trim();
|
@@ -51,22 +36,13 @@ let ResticClientFactory = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.
|
|
51
36
|
url: cfg.repo
|
52
37
|
}
|
53
38
|
};
|
39
|
+
const creds = cfg.credentialsFile && this.b2.fromFile(cfg.credentialsFile);
|
54
40
|
|
55
|
-
if (cfg.
|
56
|
-
if (!
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if (validationErr) {
|
62
|
-
throw new Error(`Invalid Restic credential in ${cfg.credentialsFile}: ${validationErr}`);
|
63
|
-
}
|
64
|
-
|
65
|
-
const creds = credJson;
|
66
|
-
props.backblaze = {
|
67
|
-
accountId: creds.keyID,
|
68
|
-
accountKey: creds.applicationKey
|
69
|
-
};
|
41
|
+
if (cfg.repo.startsWith('b2:')) {
|
42
|
+
if (!creds) throw new Error(`Credentials must be provided for b2 repo in '${cfg.name}'`);
|
43
|
+
props.backblaze = creds;
|
44
|
+
} else {
|
45
|
+
if (creds) throw new Error('Credentials can be supported only for the B2 restic backend');
|
70
46
|
}
|
71
47
|
|
72
48
|
return new _ResticClient.ResticClient(props, this.sh, this.log);
|
@@ -9,7 +9,7 @@ var _inversify = require("inversify");
|
|
9
9
|
|
10
10
|
var _ContextSymbols = require("../../ctx/ContextSymbols");
|
11
11
|
|
12
|
-
var
|
12
|
+
var _config = require("../../config");
|
13
13
|
|
14
14
|
var _ResticClientFactory = require("./ResticClientFactory");
|
15
15
|
|
@@ -21,7 +21,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
21
21
|
|
22
22
|
let ResticController = (_dec = (0, _inversify.injectable)(), _dec2 = function (target, key) {
|
23
23
|
return (0, _inversify.inject)(_ContextSymbols.AppConfig_)(target, undefined, 2);
|
24
|
-
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof
|
24
|
+
}, _dec3 = Reflect.metadata("design:type", Function), _dec4 = Reflect.metadata("design:paramtypes", [typeof _ResticClientFactory.ResticClientFactory === "undefined" ? Object : _ResticClientFactory.ResticClientFactory, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _config.Config === "undefined" ? Object : _config.Config]), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = class ResticController {
|
25
25
|
constructor(restFact, log, cfg) {
|
26
26
|
this.restFact = restFact;
|
27
27
|
this.log = log;
|
package/lib/tools/gpg/Gpg.js
CHANGED
@@ -17,8 +17,15 @@ let Gpg = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design
|
|
17
17
|
constructor(sh) {
|
18
18
|
this.sh = sh;
|
19
19
|
|
20
|
+
_defineProperty(this, "importKey", key => {
|
21
|
+
this.sh.execWithStdIn({
|
22
|
+
cmd: `gpg --import`,
|
23
|
+
stdin: key
|
24
|
+
});
|
25
|
+
});
|
26
|
+
|
20
27
|
_defineProperty(this, "exportKey", id => {
|
21
|
-
const res = this.sh.execAndReturnVal(`gpg --export-secret-key --armor ${id}`);
|
28
|
+
const res = this.sh.execAndReturnVal(`gpg --batch --pinentry-mode=loopback --pinentry-mode=loopback --yes --passphrase foo123 --export-secret-key --armor ${id}`);
|
22
29
|
if (!res) throw new Error(`Key '${id}' not in keyring`);
|
23
30
|
return res;
|
24
31
|
});
|
@@ -6,9 +6,20 @@ var _Gpg = require("./Gpg");
|
|
6
6
|
|
7
7
|
var _Shell = require("../shell/Shell");
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
var _test = require("../../../test");
|
10
|
+
|
11
|
+
var _fs = _interopRequireDefault(require("fs"));
|
12
|
+
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
|
+
|
15
|
+
it('works', () => {
|
11
16
|
const sut = new _Gpg.Gpg(new _Shell.Shell(new _AppLogger.AppLogger()));
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
const key = _fs.default.readFileSync((0, _test.testDir)('gpg/john.doe@foo.com.key.asc')).toString();
|
19
|
+
|
20
|
+
sut.importKey(key);
|
21
|
+
const exportedKey = sut.exportKey('john.doe@foo.com');
|
22
|
+
expect(exportedKey).toStartWith('-----BEGIN PGP PRIVATE KEY BLOCK-----');
|
23
|
+
expect(exportedKey).toEndWith('-----END PGP PRIVATE KEY BLOCK-----'); // Wont' work
|
24
|
+
// expect(key).toBe(exportedKey)
|
14
25
|
});
|
package/lib/tools/shell/Shell.js
CHANGED
@@ -32,7 +32,7 @@ let Shell = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("desi
|
|
32
32
|
stdin,
|
33
33
|
opts = {}
|
34
34
|
}) => {
|
35
|
-
this.log.debug(
|
35
|
+
this.log.debug(`<stdin> > ${cmd}`);
|
36
36
|
(0, _shellCmd.shellCmd)(cmd, { ...opts,
|
37
37
|
stdin,
|
38
38
|
returnStdout: false
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ps-aux/nodebup",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "",
|
5
5
|
"module": "lib/index.js",
|
6
6
|
"main": "lib/index.js",
|
7
7
|
"scripts": {
|
8
|
-
"build": "rm -rf build && babel --extensions '.ts,.js' src -d lib src",
|
8
|
+
"build": "rm -rf build && babel --extensions '.ts,.js,.md' src -d lib src",
|
9
9
|
"pub": "npm publish --access public",
|
10
10
|
"test": "jest",
|
11
11
|
"tc": "tsc --noEmit",
|
@@ -76,6 +76,7 @@
|
|
76
76
|
"@types/hapi__joi": "^17.1.8",
|
77
77
|
"axios": "^0.24.0",
|
78
78
|
"handlebars": "^4.7.7",
|
79
|
+
"ini": "^2.0.0",
|
79
80
|
"inversify": "^6.0.1",
|
80
81
|
"js-yaml": "^4.1.0",
|
81
82
|
"pino": "^7.6.2",
|