2021-09-01 05:32:08 +00:00
// Init function export mongodb
2021-09-14 13:31:06 +00:00
const shell = require ( 'shelljs' )
const Constants = require ( './constants' )
2021-09-01 05:32:08 +00:00
function export _database ( ) {
console . log ( 'export_database ....' )
2021-09-14 13:31:06 +00:00
shell . mkdir ( '-p' , [ Constants . BACKUP _PATH ] ) ;
const cmd = ` mongodump --uri=' ${ process . env . APPSMITH _MONGODB _URI } ' --archive=' ${ Constants . BACKUP _PATH } / ${ Constants . DUMP _FILE _NAME } ' --gzip `
2021-09-01 05:32:08 +00:00
shell . exec ( cmd )
console . log ( 'export_database done' )
}
function stop _application ( ) {
console . log ( 'stop_application ....' )
shell . exec ( '/usr/bin/supervisorctl stop backend rts' )
console . log ( 'stop_application done' )
}
function start _application ( ) {
console . log ( 'start_application ....' )
shell . exec ( '/usr/bin/supervisorctl start backend rts' )
console . log ( 'start_application done' )
}
// Main application workflow
function main ( ) {
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' )
}
} )
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 ) ;
}
}
module . exports = {
runExportDatabase : main
2021-09-14 13:31:06 +00:00
} ;