create and restore backups

This commit is contained in:
Julian Krauser 2025-01-29 16:49:34 +01:00
parent 6ae463a784
commit f78097b616
16 changed files with 696 additions and 21 deletions

View file

@ -1,7 +1,7 @@
import "dotenv/config";
import express from "express";
import { configCheck, SERVER_PORT } from "./env.defaults";
import { BACKUP_AUTO_RESTORE, configCheck, SERVER_PORT } from "./env.defaults";
configCheck();
import { PermissionObject } from "./type/permissionTypes";
@ -19,18 +19,25 @@ declare global {
}
import { dataSource } from "./data-source";
dataSource.initialize();
import BackupHelper from "./helpers/backupHelper";
dataSource.initialize().then(async () => {
if ((BACKUP_AUTO_RESTORE as "true" | "false") == "true") {
await BackupHelper.autoRestoreBackup().catch((err) => {
console.log(`${new Date().toISOString()}: failed auto-restoring database`);
});
}
});
const app = express();
import router from "./routes/index";
router(app);
app.listen(process.env.NODE_ENV ? SERVER_PORT : 5000, () => {
console.log(`listening on *:${process.env.NODE_ENV ? SERVER_PORT : 5000}`);
console.log(`${new Date().toISOString()}: listening on port ${process.env.NODE_ENV ? SERVER_PORT : 5000}`);
});
import schedule from "node-schedule";
import RefreshCommandHandler from "./command/refreshCommandHandler";
const job = schedule.scheduleJob("0 0 * * *", async () => {
console.log(`running Cron at ${new Date()}`);
console.log(`${new Date().toISOString()}: running Cron`);
await RefreshCommandHandler.deleteExpired();
});