sparkychild

Untitled

May 30th, 2021
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. "use strict";
  2.  
  3. const exec = require('child_process').exec;
  4. const fs = require('fs');
  5.  
  6. const now = Date.now();
  7. const interval = 24 * 60 * 60 * 1000;
  8. const day_passed = Date.now() % interval;
  9. const diff = interval - day_passed;
  10.  
  11. function backup_in(time = interval) {
  12. setTimeout(() => {
  13. // keep past 2 days
  14. exec(`mkdir -p backup`);
  15. fs.readdirSync('backup')
  16. .sort().slice(0, -2)
  17. .forEach(file => exec(`rm backup/${file}`));
  18.  
  19. // zip and backup
  20. exec(`tar cfz backup/${Date.now()}-${new Date().toLocaleDateString().replace(/\//g, '-')}.tgz Dawn/config/*`);
  21.  
  22. // call itself again in preset interval
  23. backup_in(interval);
  24. }, time);
  25. }
  26. backup_in(diff);
Advertisement
Add Comment
Please, Sign In to add comment