first commit
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s
This commit is contained in:
commit
6fc0a01c56
51 changed files with 11319 additions and 0 deletions
24
server/backup.js
Normal file
24
server/backup.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { DatabaseSync } from "node:sqlite";
|
||||
import { mkdirSync, existsSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
const source = resolve(process.env.DATA_DIR || "data", "calio.sqlite");
|
||||
if (!existsSync(source)) throw new Error("No Calio database found.");
|
||||
const output = resolve(
|
||||
process.argv[2] ||
|
||||
(process.env.DATA_DIR || "data") +
|
||||
"/backups/calio-" +
|
||||
new Date().toISOString().replaceAll(":", "-") +
|
||||
".sqlite",
|
||||
);
|
||||
if (output === source || existsSync(output))
|
||||
throw new Error(
|
||||
"Choose a new backup path. Existing files are never overwritten.",
|
||||
);
|
||||
mkdirSync(dirname(output), { recursive: true });
|
||||
const db = new DatabaseSync(source);
|
||||
try {
|
||||
db.prepare("VACUUM INTO ?").run(output);
|
||||
console.log(output);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue