初始化 M0:Astro SSR + node:sqlite 脚手架与只读页面
This commit is contained in:
1 parent
97440b4120
commit
8430e5304d
39 files changed
+6398
-1
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { cpSync, existsSync, mkdirSync } from 'node:fs';
|
||||
|
||||
const DB_PATH = process.env.DB_PATH ?? 'data/app.db';
|
||||
const UPLOADS = process.env.UPLOADS_DIR ?? 'data/uploads';
|
||||
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||
const dir = `backups/${stamp}`;
|
||||
mkdirSync(dir, { recursive: true });
|
||||
|
||||
// VACUUM INTO 产出一致性快照,比直接拷贝 db 文件安全(WAL 模式下也有效)
|
||||
const db = new DatabaseSync(DB_PATH);
|
||||
db.exec(`VACUUM INTO '${dir}/app.db'`);
|
||||
db.close();
|
||||
|
||||
if (existsSync(UPLOADS)) {
|
||||
cpSync(UPLOADS, `${dir}/uploads`, { recursive: true });
|
||||
console.log(`已复制 uploads -> ${dir}/uploads`);
|
||||
}
|
||||
|
||||
console.log(`备份完成:${dir}`);
|
||||
Reference in new issue
Block a user