Create backup files by time in Javascript

0

I have a JSON file in which I want to create a series of backups in a period of 5 minutes, at this moment, I have a program running with NodeJS that reads and writes a file defined by:

let points = JSON.parse(fs.readFileSync('./points.json', 'utf8'));

But I have noticed that when my program gets an unexpected error and it closes suddenly, it leaves the file "open" and all the content is deleted. What I would like to do is a function in which each period, save all the contents of the file ./ points.json and that after having written and saved it, that closes it (so if the program "crashe ", the content is not deleted) and the next autosave, create another new file.

Preferably, backup copies should be "points" + timestamp.

Thanks in advance.

    
asked by Antonio Roman 21.12.2016 в 12:35
source

1 answer

1

fs is the one who makes the process of saving files, unrelated to the time it is done, having the same problem either in the usual process in which the process is being performed or at the time the backup is made,

I would suggest that you use something like redis

link

link

This will allow you to save data in memory outside the program, which if the program closes, can go when the program opens again at any time to retrieve the information, the most important thing is to try to control the exceptions of the program yours to prevent it from closing

    
answered by 21.12.2016 / 14:46
source