Infinity Forum
Christian Engineering Solutions (CES) is a Not for Profit Organization specializing in collaborative solutions development for the Church. In the Spirit of Jesus Christ, we are to spread the gospel throughout the Earth, taking care to be good examples of Christ Jesus by serving others. CES is designed to help the Church meet these goals in the most rigorous manner possible.
Our Technology is scripture based in its goals and foundations. Open-Source and Free, one may use our services to both learn and solve problems with the goals of helping others and growing closer to God.
var restore = require('mongodb-restore');
var encryptor = require('file-encryptor');
var fs = require('fs');
const { exec } = require('child_process');
require('dotenv').config({path: __dirname + '/../.env'})
var key = process.env.ENCRYPTION_KEY;
var numFiles = 0;
var filesProcessed = 0;
//first unzip
exec('unzip sasame.zip', (err, stdout, stderr) => {
// Decrypt files
//within this dir is a dir for each collection
var dir = 'sasame/';
fs.readdir(dir, (err, dirs) => {
dirs.forEach(function(sub_dir){
fs.readdir((dir + sub_dir), (err, files) => {
numFiles += files.length;
files.forEach(file => {
encryptor.decryptFile((dir + sub_dir + '/' + file), (dir + sub_dir + '/' + file.split('.')[0]+'.bson'), key, function(err) {
// Decryption complete.
console.log('Decrypted ' + file);
//delete original
fs.unlink(dir + sub_dir + '/' + file);
});
++filesProcessed;
//run on last iteration
if(filesProcessed == numFiles){
restore({
uri: process.env.MONGODB_CONNECTION_URL,
root: __dirname + '/sasame',
drop: true,
callback: function(){
console.log('Database Restored.');
//now backup the data again so it is always encrypted
//this also cleans the dir
exec('node backup.js');
}
});
}
});
});
});
});
});