💾 Archived View for iich.space › src › db › backup.ts captured on 2021-12-03 at 14:04:38.

View Raw

More Information

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

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);
};