2021-09-01 05:32:08 +00:00
// Init function export mongodb
2021-12-17 05:09:20 +00:00
const shell = require ( 'shelljs' ) ;
const Constants = require ( './constants' ) ;
2021-09-01 05:32:08 +00:00
function export _database ( ) {
2021-12-17 05:09:20 +00:00
console . log ( 'export_database ....' ) ;
shell . mkdir ( '-p' , [ Constants . BACKUP _PATH ] ) ;
const cmd = ` mongodump --uri=' ${ process . env . APPSMITH _MONGODB _URI } ' --archive=' ${ Constants . BACKUP _PATH } / ${ Constants . DUMP _FILE _NAME } ' --gzip ` ;
shell . exec ( cmd ) ;
console . log ( 'export_database done' ) ;
2021-09-01 05:32:08 +00:00
}
function stop _application ( ) {
2021-12-17 05:09:20 +00:00
console . log ( 'stop_application ....' ) ;
shell . exec ( '/usr/bin/supervisorctl stop backend rts' ) ;
console . log ( 'stop_application done' ) ;
2021-09-01 05:32:08 +00:00
}
function start _application ( ) {
2021-12-17 05:09:20 +00:00
console . log ( 'start_application ....' ) ;
shell . exec ( '/usr/bin/supervisorctl start backend rts' ) ;
console . log ( 'start_application done' ) ;
2021-09-01 05:32:08 +00:00
}
// Main application workflow
function main ( ) {
2021-12-17 05:09:20 +00:00
let errorCode = 0 ;
try {
check _supervisord _status _cmd = '/usr/bin/supervisorctl >/dev/null 2>&1 ' ;
shell . exec ( check _supervisord _status _cmd , function ( code ) {
if ( code > 0 ) {
shell . echo ( 'application is not running, starting supervisord' ) ;
shell . exec ( '/usr/bin/supervisord' ) ;
}
} ) ;
2021-09-01 05:32:08 +00:00
2021-12-17 05:09:20 +00:00
shell . echo ( 'stop backend & rts application before export database' ) ;
stop _application ( ) ;
export _database ( ) ;
shell . echo ( 'start backend & rts application after export database' ) ;
shell . echo ( ) ;
shell . echo ( '\033[0;33m++++++++++++++++++++ NOTE ++++++++++++++++++++' ) ;
shell . echo ( ) ;
shell . echo (
'Please remember to also copy APPSMITH_ENCRYPTION_SALT and APPSMITH_ENCRYPTION_PASSWORD variables from the docker.env file to the target instance where you intend to import this database dump.' ,
) ;
shell . echo ( ) ;
shell . echo ( '++++++++++++++++++++++++++++++++++++++++++++++\033[0m' ) ;
shell . echo ( ) ;
} catch ( err ) {
shell . echo ( err ) ;
errorCode = 1 ;
} finally {
start _application ( ) ;
process . exit ( errorCode ) ;
}
2021-09-01 05:32:08 +00:00
}
module . exports = {
2021-12-17 05:09:20 +00:00
runExportDatabase : main ,
exportDatabase : export _database ,
stopApplication : stop _application ,
startApplication : start _application ,
2021-09-14 13:31:06 +00:00
} ;