-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.gs
More file actions
41 lines (35 loc) · 1.58 KB
/
code.gs
File metadata and controls
41 lines (35 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Details of Mime types: https://developers.google.com/drive/api/guides/mime-types
// Note Google Script uses the older Drive v2 API's: https://stackoverflow.com/questions/52100052/folder-searchfiles-method-raises-invalid-argument-q-error
const DATE = Utilities.formatDate(new Date(), "GMT+10", "dd/MM/yyyy HH:mm")
//Replace the below ID with the desired location. Can grab this from the URL when browsing Google Drive
const DESTINATION = DriveApp.getFolderById("FOLDERIDHERE").createFolder(DATE).getId(); // Created a sub folder with date/time
function backupForms(){
var files = DriveApp.searchFiles('not title contains "Backup of -" and mimeType = "application/vnd.google-apps.form"');
let counter = 0;
while (files.hasNext()) {
var file = files.next();
// console.log(file.getName());
var id = DriveApp.getFileById(file.getId());
id.makeCopy("Backup of - " + file.getName(), DriveApp.getFolderById(DESTINATION));
counter++
}
console.log("Forms backed up: " + counter)
}
function backupSites(){
var files = DriveApp.searchFiles('not title contains "Backup of -" and mimeType = "application/vnd.google-apps.site"');
let counter = 0;
while (files.hasNext()) {
var file = files.next();
// console.log(file.getName());
var id = DriveApp.getFileById(file.getId());
id.makeCopy("Backup of - " + file.getName(), DriveApp.getFolderById(DESTINATION));
counter++
}
console.log("Sites backed up: " + counter)
}
function backupFormsAndSites(){
console.log("Backup has started")
backupForms();
backupSites();
console.log("Backup has completed")
}