@@ -3,7 +3,7 @@ const fs = require("fs");
33const path = require ( "path" ) ;
44const configClass = require ( "./config" ) ;
55
6- const moment = require ( "moment " ) ;
6+ const dayjs = require ( "dayjs " ) ;
77const Logging = require ( "./logging" ) ;
88
99const taskstate = require ( "../logging/taskstate" ) ;
@@ -34,7 +34,7 @@ async function backup(refLog) {
3434 if ( config . error ) {
3535 refLog . logData . push ( { color : "red" , Message : "Backup Failed: Failed to get config" } ) ;
3636 refLog . logData . push ( { color : "red" , Message : "Backup Failed with errors" } ) ;
37- Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
37+ await Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
3838 return ;
3939 }
4040
@@ -50,7 +50,7 @@ async function backup(refLog) {
5050 // Get data from each table and append it to the backup file
5151
5252 try {
53- let now = moment ( ) ;
53+ let now = dayjs ( ) ;
5454 const backuppath = "./" + backupfolder ;
5555
5656 if ( ! fs . existsSync ( backuppath ) ) {
@@ -61,7 +61,7 @@ async function backup(refLog) {
6161 console . error ( "No write permissions for the folder:" , backuppath ) ;
6262 refLog . logData . push ( { color : "red" , Message : "Backup Failed: No write permissions for the folder: " + backuppath } ) ;
6363 refLog . logData . push ( { color : "red" , Message : "Backup Failed with errors" } ) ;
64- Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
64+ await Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
6565 await pool . end ( ) ;
6666 return ;
6767 }
@@ -73,18 +73,18 @@ async function backup(refLog) {
7373 if ( filteredTables . length === 0 ) {
7474 refLog . logData . push ( { color : "red" , Message : "Backup Failed: No tables to backup" } ) ;
7575 refLog . logData . push ( { color : "red" , Message : "Backup Failed with errors" } ) ;
76- Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
76+ await Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
7777 await pool . end ( ) ;
7878 return ;
7979 }
8080
81- // const backupPath = `../backup-data/backup_${now.format('yyyy -MM-DD HH-mm-ss')}.json`;
82- const directoryPath = path . join ( __dirname , ".." , backupfolder , `backup_${ now . format ( "yyyy -MM-DD HH-mm-ss" ) } .json` ) ;
81+ // const backupPath = `../backup-data/backup_${now.format('YYYY -MM-DD HH-mm-ss')}.json`;
82+ const directoryPath = path . join ( __dirname , ".." , backupfolder , `backup_${ now . format ( "YYYY -MM-DD HH-mm-ss" ) } .json` ) ;
8383 refLog . logData . push ( { color : "yellow" , Message : "Begin Backup " + directoryPath } ) ;
8484 const stream = fs . createWriteStream ( directoryPath , { flags : "a" } ) ;
85- stream . on ( "error" , ( error ) => {
85+ stream . on ( "error" , async ( error ) => {
8686 refLog . logData . push ( { color : "red" , Message : "Backup Failed: " + error } ) ;
87- Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
87+ await Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
8888 return ;
8989 } ) ;
9090 const backup_data = [ ] ;
@@ -152,7 +152,7 @@ async function backup(refLog) {
152152 } catch ( error ) {
153153 console . log ( error ) ;
154154 refLog . logData . push ( { color : "red" , Message : "Backup Failed: " + error } ) ;
155- Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
155+ await Logging . updateLog ( refLog . uuid , refLog . logData , taskstate . FAILED ) ;
156156 }
157157
158158 await pool . end ( ) ;
0 commit comments