mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-24 13:39:35 +02:00
Create database backup before migrating
This commit is contained in:
parent
84bd641cf2
commit
59271d3376
3 changed files with 25 additions and 4 deletions
21
db/utils/backupDb.js
Normal file
21
db/utils/backupDb.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const backupDB = () => {
|
||||
if (!fs.existsSync('data/db_backups')) {
|
||||
fs.mkdirSync('data/db_backups');
|
||||
}
|
||||
|
||||
const version = process.env.VERSION;
|
||||
const slug = `db-${version.replace(/\./g, '')}-backup.sqlite`;
|
||||
|
||||
const srcPath = 'data/db.sqlite';
|
||||
const destPath = `data/db_backups/${slug}`;
|
||||
|
||||
if (fs.existsSync(srcPath)) {
|
||||
if (!fs.existsSync(destPath)) {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = backupDB;
|
Loading…
Add table
Add a link
Reference in a new issue