core/source/helpers/borg.ts

121 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-09-24 12:39:22 +02:00
/*
This file is part of »mimir«.
Copyright 2025 kcf <fenris@folksprak.org>
»mimir« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»mimir« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »mimir«. If not, see <http://www.gnu.org/licenses/>.
*/
2025-03-24 22:47:55 +01:00
/**
* @todo consider to outsource to plankton
*/
namespace _mimir.helpers.borg
{
/**
*/
export function init(
repository_directory : string,
{
"encryption": encryption = "none",
} : {
encryption ?: string;
} = {
}
) : string
{
return lib_plankton.string.coin(
"borg init --encryption={{encryption}} {{repository_directory}}",
{
"repository_directory": repository_directory,
"encryption": encryption,
}
);
}
/**
*/
export function create(
repository_directory : string,
archive_name : string,
directories : Array<string>,
{
"compression": compression = "none",
} : {
compression ?: string;
} = {
}
) : string
{
return lib_plankton.string.coin(
"borg create --compression={{compression}} {{repository_directory}}::{{archive_name}} {{directories}}",
{
"repository_directory": repository_directory,
"archive_name": archive_name,
"compression": compression,
"directories": directories.join(" "),
}
)
}
/**
*/
export function prune(
repository_directory : string,
age : string,
{
"keep_weekly": keep_weekly = null,
"keep_yearly": keep_yearly = null,
} : {
keep_weekly ?: (null | int);
keep_yearly ?: (null | int);
} = {
}
) : string
{
return lib_plankton.string.coin(
"borg prune --keep-within=2w{{macro_keep_weekly}}{{macro_keep_yearly}} {{repository_directory}}",
{
"repository_directory": repository_directory,
"keep_within": age,
"macro_keep_weekly": (
(keep_weekly === null)
?
""
:
lib_plankton.string.coin(
" --keep-weekly={{x}}",
{"x": keep_weekly.toFixed(0)}
)
),
"macro_keep_yearly": (
(keep_yearly === null)
?
""
:
lib_plankton.string.coin(
" --keep-yearly={{x}}",
{"x": keep_yearly.toFixed(0)}
)
),
}
)
}
}