Compare commits

..

5 commits

10 changed files with 260 additions and 19 deletions

View file

@ -7,6 +7,12 @@
"parameters": {
"repository": "ssh://backup.example.org///repos/example",
"compression": "lz4",
"encryption": {
"kind": "repokey",
"data": {
"passphrase": "top_secret"
}
},
"pruning": {
"keep_weekly": 1,
"keep_yearly": 2

View file

@ -101,10 +101,76 @@ namespace _mimir.conf
],
"default": "lz4"
},
"encryption": {
"anyOf": [
{
"nullable": false,
"type": "object",
"properties": {
"kind": {
"type": "string",
"enum": ["none"]
},
"data": {
"nullable": true,
"type": "object",
"properties": {
},
"additionalProperties": false,
"required": [
],
"default": {}
},
},
"additionalProperties": false,
"required": [
"kind"
],
},
{
"nullable": false,
"type": "object",
"properties": {
"kind": {
"type": "string",
"enum": ["repokey"]
},
"data": {
"nullable": true,
"type": "object",
"properties": {
"passphrase": {
"nullable": false,
"type": "string"
},
},
"additionalProperties": false,
"required": [
"passphrase"
]
},
},
"additionalProperties": false,
"required": [
"kind",
"data"
]
}
],
"default": {
"kind": "none",
"data": null
}
},
"pruning": {
"nullable": false,
"type": "object",
"properties": {
"keep_within": {
"nullable": false,
"type": "string",
"default": "2w"
},
"keep_weekly": {
"nullable": false,
"type": "integer",
@ -282,14 +348,7 @@ namespace _mimir.conf
/**
*/
type type_target_parameters_borg = {
repository : string;
compression : string;
pruning : {
keep_weekly : int;
keep_yearly : int;
}
};
type type_target_parameters_borg = _mimir.transfer.borg.type_parameters;
/**

View file

@ -30,15 +30,29 @@ namespace _mimir.helpers.borg
repository_directory : string,
{
"encryption": encryption = "none",
"passphrase": passphrase = null,
} : {
encryption ?: string;
passphrase ?: (null | string);
} = {
}
) : string
{
return lib_plankton.string.coin(
"borg init --encryption={{encryption}} {{repository_directory}}",
"{{macro_env_passphrase}}borg init --encryption={{encryption}} {{repository_directory}}",
{
"macro_env_passphrase": (
(passphrase === null)
?
""
:
lib_plankton.string.coin(
"BORG_PASSPHRASE='{{passphrase}}' BORG_DISPLAY_PASSPHRASE=n ",
{
"passphrase": passphrase,
}
)
),
"repository_directory": repository_directory,
"encryption": encryption,
}
@ -54,15 +68,29 @@ namespace _mimir.helpers.borg
directories : Array<string>,
{
"compression": compression = "none",
"passphrase": passphrase = null,
} : {
compression ?: string;
passphrase ?: (null | string);
} = {
}
) : string
{
return lib_plankton.string.coin(
"borg create --compression={{compression}} {{repository_directory}}::{{archive_name}} {{directories}}",
"{{macro_env_passphrase}}borg create --compression={{compression}} {{repository_directory}}::{{archive_name}} {{directories}}",
{
"macro_env_passphrase": (
(passphrase === null)
?
""
:
lib_plankton.string.coin(
"BORG_PASSPHRASE='{{passphrase}}' ",
{
"passphrase": passphrase,
}
)
),
"repository_directory": repository_directory,
"archive_name": archive_name,
"compression": compression,
@ -80,16 +108,30 @@ namespace _mimir.helpers.borg
{
"keep_weekly": keep_weekly = null,
"keep_yearly": keep_yearly = null,
"passphrase": passphrase = null,
} : {
keep_weekly ?: (null | int);
keep_yearly ?: (null | int);
passphrase ?: (null | string);
} = {
}
) : string
{
return lib_plankton.string.coin(
"borg prune --keep-within=2w{{macro_keep_weekly}}{{macro_keep_yearly}} {{repository_directory}}",
"{{macro_env_passphrase}}borg prune --keep-within={{keep_within}}{{macro_keep_weekly}}{{macro_keep_yearly}} {{repository_directory}}",
{
"macro_env_passphrase": (
(passphrase === null)
?
""
:
lib_plankton.string.coin(
"BORG_PASSPHRASE='{{passphrase}}' ",
{
"passphrase": passphrase,
}
)
),
"repository_directory": repository_directory,
"keep_within": age,
"macro_keep_weekly": (

View file

@ -23,6 +23,12 @@ namespace _mimir.transfer
/**
*/
export type type_logic = {
init : (
(
)
=>
Array<string>
);
execute : (
(
name : string,

View file

@ -48,6 +48,7 @@ namespace _mimir.transfer
{
"repository": target.parameters.repository,
"compression": target.parameters.compression,
"encryption": target.parameters.encryption,
"pruning": target.parameters.pruning,
}
);

View file

@ -20,18 +20,114 @@ along with »mimir«. If not, see <http://www.gnu.org/licenses/>.
namespace _mimir.transfer.borg
{
/**
*/
export type type_encryption = (
{
kind : "none";
data : {
};
}
|
{
kind : "repokey";
data : {
passphrase : string;
};
}
/*
|
{
kind : "keyfile";
data : {
path : string;
passphrase : string;
};
}
*/
);
/**
*/
export type type_parameters = {
repository : string;
compression : string;
encryption : type_encryption;
pruning : {
keep_within : string;
keep_weekly : int;
keep_yearly : int;
}
};
/**
*/
function get_passphrase(
parameters : type_parameters
) : (null | string)
{
switch (parameters.encryption.kind)
{
case "none":
{
return null;
break;
}
case "repokey":
{
return parameters.encryption.data.passphrase;
break;
}
default:
{
throw (new Error("unhandled encryption kind"));
break;
}
}
}
/**
*/
export function init(
parameters : type_parameters,
) : Array<string>
{
const result : Array<string> = [];
result.push(
_mimir.helpers.borg.init(
parameters.repository,
{
"encryption": ((encryption : type_encryption) => {
switch (encryption.kind)
{
case "none":
{
return "none";
break;
}
case "repokey":
{
return "repokey";
break;
}
default:
{
throw (new Error("unhandled encryption kind"));
break;
}
}
}) (parameters.encryption),
"passphrase": get_passphrase(parameters),
}
)
);
return result;
}
/**
*/
export function execute(
@ -54,6 +150,7 @@ namespace _mimir.transfer.borg
),
[directory],
{
"passphrase": get_passphrase(parameters),
"compression": parameters.compression,
}
)
@ -61,7 +158,7 @@ namespace _mimir.transfer.borg
result.push(
_mimir.helpers.borg.prune(
parameters.repository,
"2w",
parameters.pruning.keep_within,
{
"keep_weekly": parameters.pruning.keep_weekly,
"keep_yearly": parameters.pruning.keep_yearly,
@ -79,6 +176,7 @@ namespace _mimir.transfer.borg
) : _mimir.transfer.type_logic
{
return {
"init": () => init(parameters),
"execute": (name, stamp, directory) => execute(parameters, name, stamp, directory),
};
}

View file

@ -73,6 +73,10 @@ namespace _mimir.transfer.local
) : _mimir.transfer.type_logic
{
return {
/**
* @todo?
*/
"init": () => [],
"execute": (name, stamp, directory) => execute(parameters, name, stamp, directory),
};
}

View file

@ -168,10 +168,27 @@ namespace _mimir
}
case "init":
{
/**
* @todo implement
*/
return Promise.reject(new Error("not implemented"));
const conf : _mimir.conf.type_conf = await _mimir.conf.get(args["conf_path"]);
let commands : Array<string> = [];
const commands_add : ((command : string) => void) = (command) => {
commands.push(command);
};
const commands_apply : (() => void) = () => {
process.stdout.write(commands.join("\n") + "\n");
};
// transfer
{
const target_logic : _mimir.transfer.type_logic = _mimir.transfer.get_logic(conf.target);
commands = commands.concat(
target_logic.init(
)
);
}
commands_apply();
break;
}
case "run":

View file

@ -28,7 +28,7 @@ def main():
"--build-directory",
type = str,
dest = "build_directory",
default = "build",
default = "/tmp/mimir",
metavar = "<build-directory>",
help = "directory to where the build was put",
)
@ -45,7 +45,7 @@ def main():
"--recursive",
"--update",
"--verbose",
"--exclude='conf.json'",
"--exclude='*mmr.json'",
("%s/" % args.build_directory),
(
("%s" % args.target_directory)

View file

@ -2,7 +2,7 @@
## consts
dir=lib/plankton
dir=$(pwd)/lib/plankton
modules=""
modules="${modules} base"
@ -17,6 +17,14 @@ modules="${modules} log"
## exec
mkdir -p ${dir}
mkdir /tmp/sandbox -p
cd /tmp/sandbox
ptk fetch node ${modules}
schwamm --include=/tmp/sandbox/plankton.swm.json --output=dump:logic-decl > ${dir}/plankton.d.ts
schwamm --include=/tmp/sandbox/plankton.swm.json --output=dump:logic-impl > ${dir}/plankton.js
exit
mkdir -p ${dir}
cd ${dir}
ptk bundle node ${modules}