Add automatic database backups
This commit is contained in:
parent
76790e2621
commit
30eb685676
|
@ -1,4 +1,5 @@
|
|||
node_modules
|
||||
.env
|
||||
config.json
|
||||
*.sqlite
|
||||
*.sqlite
|
||||
backups
|
|
@ -1,4 +1,5 @@
|
|||
const { Users, Games, BeatenGames } = require ('./dbObjects.js');
|
||||
const fs = require('fs');
|
||||
|
||||
async function checkUserRegistration(user) {
|
||||
|
||||
|
@ -183,6 +184,17 @@ async function getGames(id) {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function backupDatabase() {
|
||||
const date = new Date().toJSON().slice(0, 10);
|
||||
|
||||
if (fs.existsSync('./database.sqlite')) {
|
||||
// I know that this is probably not the best way to do this but for now it is fine.
|
||||
fs.copyFile('./database.sqlite', String.prototype.concat('./backups/database-', date, '.sqlite'), (err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkUserRegistration,
|
||||
getUserRegistration,
|
||||
|
@ -195,4 +207,5 @@ module.exports = {
|
|||
getLeaderboardEntries,
|
||||
getRecentGameEntry,
|
||||
getGames,
|
||||
backupDatabase,
|
||||
};
|
15
index.js
15
index.js
|
@ -7,6 +7,7 @@ const { config } = require('dotenv');
|
|||
config();
|
||||
|
||||
const { igdb } = require('./igdb.js');
|
||||
const { backupDatabase } = require('./databaseHelperFunctions.js');
|
||||
new igdb();
|
||||
|
||||
// Create a new client instance
|
||||
|
@ -55,4 +56,16 @@ client.once(Events.ClientReady, () => {
|
|||
});
|
||||
|
||||
require('sequelize');
|
||||
require('./dbObjects.js');
|
||||
require('./dbObjects.js');
|
||||
|
||||
if (!fs.existsSync('./backups')) {
|
||||
fs.mkdir('./backups', (err) => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
backupDatabase();
|
||||
}, 86000000);
|
||||
|
||||
backupDatabase();
|
Loading…
Reference in New Issue