Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const exec = require('child_process').exec;
- const fs = require('fs');
- const now = Date.now();
- const interval = 24 * 60 * 60 * 1000;
- const day_passed = Date.now() % interval;
- const diff = interval - day_passed;
- function backup_in(time = interval) {
- setTimeout(() => {
- // keep past 2 days
- exec(`mkdir -p backup`);
- fs.readdirSync('backup')
- .sort().slice(0, -2)
- .forEach(file => exec(`rm backup/${file}`));
- // zip and backup
- exec(`tar cfz backup/${Date.now()}-${new Date().toLocaleDateString().replace(/\//g, '-')}.tgz Dawn/config/*`);
- // call itself again in preset interval
- backup_in(interval);
- }, time);
- }
- backup_in(diff);
Advertisement
Add Comment
Please, Sign In to add comment