💾 Archived View for iich.space › src › db › backup.ts captured on 2022-03-01 at 15:59:46.

View Raw

More Information

⬅️ Previous capture (2021-12-03)

-=-=-=-=-=-=-

import { createLogger } from '@/log';

import db from './index';

const log = createLogger();

const runBackup = () => {
  const timestamp = new Date().toISOString().slice(0, 10);

  log.info(`creating backup ${timestamp}-db.sqlite`);
  db.backup(`./database/backups/${timestamp}-db.sqlite`);
};

let interval: NodeJS.Timer;

export const startBackupJob = (): void => {
  log.info('starting job');
  interval = setInterval(runBackup, 6 * 60 * 60 * 1000);
};

export const stopBackupJob = (): void => {
  clearInterval(interval);
};