Brian Petro
Brian Petro

Reputation: 1567

How do I backup Google Drive (Google Spreadsheets) file on regular basis using Google Apps Script?

I have a critical business spreadsheet. I need to save copies regularly in case I need to see how the spreadsheet looked at a previous time.

I want this to happen automatically using Google Apps Script.

Upvotes: 0

Views: 791

Answers (1)

Brian Petro
Brian Petro

Reputation: 1567

Use the time driven triggers to run this code:

function backupSheet() {
  var file = DriveApp.getFileById(FILE_ID);
  var destination = DriveApp.getFolderById(FOLDER_ID); // backups folder
  var date = new Date();
  var ts = date.toISOString().slice(0,10).replace(/-/g,"");
  file.makeCopy(ts+':'+file.getName(), destination);
}

Upvotes: 1

Related Questions