create and restore backups
This commit is contained in:
parent
6ae463a784
commit
f78097b616
16 changed files with 696 additions and 21 deletions
15
src/index.ts
15
src/index.ts
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue