47 lines
1.9 KiB
Lua
47 lines
1.9 KiB
Lua
|
|
-- Zip all user-state JSON files into ~/Documents/jarvis-backup-<ts>.zip.
|
|||
|
|
local t = jarvis.context.time
|
|||
|
|
local stamp = string.format("%04d%02d%02d-%02d%02d%02d",
|
|||
|
|
t.year, t.month, t.day, t.hour, t.minute, t.second or 0)
|
|||
|
|
|
|||
|
|
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
|||
|
|
local out_zip = userprofile .. "\\Documents\\jarvis-backup-" .. stamp .. ".zip"
|
|||
|
|
|
|||
|
|
-- The state files live under <APP_CONFIG_DIR>. We can't easily read that path
|
|||
|
|
-- from Lua, but the user can navigate from %APPDATA%/Jarvis. So we ask
|
|||
|
|
-- PowerShell to do the discovery + zip in one shot.
|
|||
|
|
local ps = string.format([[
|
|||
|
|
$cfg = Join-Path $env:APPDATA 'Jarvis';
|
|||
|
|
if (-not (Test-Path $cfg)) { Write-Output 'NOCFG'; exit };
|
|||
|
|
$files = @();
|
|||
|
|
foreach ($n in @('long_term_memory.json','schedule.json','macros.json','active_profile.txt','llm_backend.txt','settings.json')) {
|
|||
|
|
$p = Join-Path $cfg $n;
|
|||
|
|
if (Test-Path $p) { $files += $p }
|
|||
|
|
};
|
|||
|
|
$profiles_dir = Join-Path $cfg 'profiles';
|
|||
|
|
if (Test-Path $profiles_dir) {
|
|||
|
|
$files += Get-ChildItem $profiles_dir -File | ForEach-Object { $_.FullName }
|
|||
|
|
};
|
|||
|
|
if ($files.Count -eq 0) { Write-Output 'NONE'; exit };
|
|||
|
|
Compress-Archive -Path $files -DestinationPath '%s' -Force;
|
|||
|
|
Write-Output ('OK|' + $files.Count)
|
|||
|
|
]], out_zip:gsub("'", "''"))
|
|||
|
|
|
|||
|
|
local res = jarvis.system.exec(string.format(
|
|||
|
|
'powershell -NoProfile -Command "%s"', ps:gsub('"', '\\"'):gsub("\r?\n", "; ")
|
|||
|
|
))
|
|||
|
|
if not res.success then
|
|||
|
|
return jarvis.cmd.error("Не получилось создать бекап.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local out = (res.stdout or ""):gsub("^%s+", ""):gsub("%s+$", "")
|
|||
|
|
if out == "NOCFG" then
|
|||
|
|
return jarvis.cmd.not_found("Папка настроек не найдена.")
|
|||
|
|
end
|
|||
|
|
if out == "NONE" then
|
|||
|
|
return jarvis.cmd.not_found("Нечего бекапить — нет данных.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local count = out:match("OK|(%d+)") or "?"
|
|||
|
|
jarvis.system.notify("Backup готов", out_zip)
|
|||
|
|
return jarvis.cmd.ok(string.format("Бекап сохранён, %s файлов.", count))
|