Last active
May 12, 2022 13:56
-
-
Save fmarais/a962a8b54ce3f53f0ed57100112b453c to your computer and use it in GitHub Desktop.
PUBLIC_google_drive_sheets_backup_files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sheet > Extensions > Apps Script | |
// Add Script | |
// Add trigger for script | |
// ------------------------------ | |
// Backup script | |
function archiveCopy() { | |
var file = DriveApp.getFileById("original_file_id_to_backup"); | |
var destination = DriveApp.getFolderById("backup_folder_name"); | |
var timeZone = Session.getScriptTimeZone(); | |
var formattedDate = Utilities.formatDate(new Date(),timeZone,"dd"); // 1 month backup, one per day | |
var name = SpreadsheetApp.getActiveSpreadsheet().getName()+"_"+formattedDate; | |
// remove old backup | |
var allFiles = destination.getFilesByName(name); | |
while (allFiles.hasNext()) { | |
var thisFile = allFiles.next(); | |
thisFile.setTrashed(true); | |
}; | |
// make new backup | |
file.makeCopy(name,destination); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment