// script.jsimport{FolderBackup}from"easy-backups";// Specify project folder you want to backup, and path to backup storageletbackup=newFolderBackup({type: 'local','from-folder': '/path/to/project','path-to-backups': '/path/to/backups'})// Initialize file system, await requiredawaitbackup.init()awaitbackup.daily(5)// Last 5 days will be savedawaitbackup.weekly(3)// Last 3 week will be savedawaitbackup.monthly(3)// Last 3 months will be savedawaitbackup.annually(2)// Last 2 years will be saved// You can use them without "await".
Now you can add this script to your cron as cron job for every day.
node script.js
Extended options:
letbackup=newFolderBackup({type: 'local','from-folder': '/path/to/project','path-to-backups': '/path/to/backups','no-info-messages': true,// Disabling info messages from console.info'log-file': '/path/to/log-file.log',// Writing backups log})backup.today=newDate("2020-06-21");// Change backup datebackup.filter=['**',// Add all files to filter'!**/*.jar',// Exclude .jar files from filter'!**/*.bin',// Exclude .bin files from filter// It also supports patterns etc./^(?!.*\.log)/,// Exclude .log files from filter// For more info - https://www.npmjs.com/package/maximatch]awaitbackup.daily(2)// Last 2 days will be saved/* For mega integration use */// await backup.closeConnection()
import{FolderBackup}from"easy-backups";// Read config file with sensitive dataletconfig=fs.readFileSync('/path/to/config.json');config=JSON.parse(config);letbackup=newFolderBackup({type: 'mega',email: config.email,password: config.password,'from-folder': 'path/to/project','path-to-backups': 'path/to/backups'})// Initialize file system, await requiredawaitbackup.init()awaitbackup.daily(2)// await requiredawaitbackup.weekly(2)awaitbackup.monthly(2)awaitbackup.annually(2)// Necessarily close connection after backup to prevent program from not respondingawaitbackup.closeConnection()