Menu

#698 Auto backup in different directory

None
closed
nobody
autobackup (1)
9
2014-06-12
2014-04-26
Anonymous
No

Hello,
I have changed the standard code to make a backup periodically, but the problem is that I wanted to make make autobackups in different directory and the script does not let me do that. here is the script:

%SCRIPT
var Debug = false; //default = false
var DoSave = true; //default = true
var Interval = 10;// set the time in milliseconds. 60000=1mins

registerAsBackgroundScript("auto_save");
setTimeout(TimedFunction,Interval);

function TimedFunction() {
if (Debug) { alert('timer expired') };
SaveAllDocuments();
setTimeout(TimedFunction,Interval); //rearm the timed function
}

function SaveAllDocuments(){
if (Debug) { alert('SaveAllDocuments called') };
var NumOfDocs = documents.length;
if (Debug) { alert('NumOfDocs='+NumOfDocs) };
for (var i = 0; i < NumOfDocs; i++) {
SaveDocument(i, documents[i]);
};
};

function SaveDocument(i, Document) {
var t = new Date();
var tt=''+t.getSeconds()+''+t.getMinutes()+''+t.getHours()+''+t.getDate()+''+(t.getMonth() +1)+''+t.getFullYear()+'_';
var CurEditor = Document.editorView.editor;
var CurFileName = CurEditor.fileName();
if (Debug) { alert('i='+i+' FileName='+CurFileName) };
var newName =CurFileName.replace(/.tex$/, tt+'_bak.tex');
if (Debug) { alert('i='+i+' newName='+newName) };
if (DoSave) { writeFile(newName, CurEditor.text()); };
};

Related

Feature Requests: #1294

Discussion

  • Tim Hoffmann

    Tim Hoffmann - 2014-04-27

    Please not that this question would be better placed in Help Discussions than in a feature request.

    As of your question: What is the exact error? Maybe the target folder does not exist? It is not automatically created in the low-level saving functions.

    You may also want to use CurEditor.saveCopy(newName) in the last line instead of writeFile. The former does all the automatic things like hard-wrapping (if enabled), that happen on save.

     
  • Tim Hoffmann

    Tim Hoffmann - 2014-06-12
    • status: open --> closed
    • Group: -->
     

Anonymous
Anonymous

Add attachments
Cancel





Monday.com Logo