mirror of
https://github.com/khairul169/db-backup-tool.git
synced 2025-04-28 16:49:34 +07:00
chore: fix build
This commit is contained in:
parent
449ba1b9d0
commit
25ffaf93a2
@ -5,7 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun --watch src/main.ts",
|
"dev": "bun --watch src/main.ts",
|
||||||
"dev:compose": "cp ../bun.lockb . && docker compose -f docker-compose.dev.yml up --build",
|
"dev:compose": "cp ../bun.lockb . && docker compose -f docker-compose.dev.yml up --build",
|
||||||
"build": "bun build index.ts --outdir dist --target bun",
|
"build": "bun build src/main.ts --outdir dist --target bun",
|
||||||
"start": "bun dist/main.js",
|
"start": "bun dist/main.js",
|
||||||
"generate": "drizzle-kit generate",
|
"generate": "drizzle-kit generate",
|
||||||
"migrate": "bun src/db/migrate.ts",
|
"migrate": "bun src/db/migrate.ts",
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
type InferInsertModel,
|
type InferInsertModel,
|
||||||
type InferSelectModel,
|
type InferSelectModel,
|
||||||
} from "drizzle-orm";
|
} from "drizzle-orm";
|
||||||
import { blob, integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import type { ServerBackupSchema } from "../schemas/server.schema";
|
import type { ServerBackupSchema } from "../schemas/server.schema";
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class PostgresDbms extends BaseDbms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get dbUrl() {
|
private get dbUrl() {
|
||||||
const { user, pass, host } = this.config;
|
const { user, pass = "", host } = this.config;
|
||||||
const port = this.config.port || 5432;
|
const port = this.config.port || 5432;
|
||||||
return `postgresql://${user}:${urlencode(pass)}@${host}:${port}`;
|
return `postgresql://${user}:${urlencode(pass)}@${host}:${port}`;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import type {
|
|||||||
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
import { and, count, desc, eq, inArray } from "drizzle-orm";
|
||||||
import DatabaseService from "./database.service";
|
import DatabaseService from "./database.service";
|
||||||
import { HTTPException } from "hono/http-exception";
|
import { HTTPException } from "hono/http-exception";
|
||||||
import ServerService from "./server.service";
|
|
||||||
|
|
||||||
export default class BackupService {
|
export default class BackupService {
|
||||||
private databaseService = new DatabaseService();
|
private databaseService = new DatabaseService();
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import DatabaseUtil from "../lib/database-util";
|
|
||||||
import { DOCKER_HOST, BACKUP_DIR } from "../consts";
|
|
||||||
import { mkdir } from "../utility/utils";
|
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
const main = async () => {
|
|
||||||
try {
|
|
||||||
const db = new DatabaseUtil({
|
|
||||||
type: "postgres",
|
|
||||||
host: DOCKER_HOST,
|
|
||||||
user: "postgres",
|
|
||||||
pass: "postgres",
|
|
||||||
port: 5432,
|
|
||||||
});
|
|
||||||
|
|
||||||
const databases = await db.getDatabases();
|
|
||||||
console.log(databases);
|
|
||||||
|
|
||||||
const dbName = "test";
|
|
||||||
|
|
||||||
// Create backup
|
|
||||||
const outDir = path.join(BACKUP_DIR, db.config.host, dbName);
|
|
||||||
mkdir(outDir);
|
|
||||||
const outFile = path.join(outDir, `/${Date.now()}.tar`);
|
|
||||||
console.log(await db.dump(dbName, outFile));
|
|
||||||
console.log(outFile);
|
|
||||||
|
|
||||||
// Restore backup
|
|
||||||
console.log(await db.restore(outFile));
|
|
||||||
} catch (err) {
|
|
||||||
console.log((err as any).message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
main();
|
|
Loading…
x
Reference in New Issue
Block a user