mirror of
https://github.com/bellingcat/google-apps-script.git
synced 2026-06-07 19:08:37 +03:00
Goal
For when you need to regularly back up google docs into a google drive folder
Features:
- back up any google file
- choose a custom backup schedule per file(s)
- optionally: delete backups older than
Xdays
How
Note: to get the id of a file/folder navigate to it and copy the id from the URL, it's something like
kjhhdao87ah42hd98e9h29ud
- create a new google drive folder where you want your backups - get its id
BACKUP_FOLDER_ID - create a new google sheets document (anywhere but can be in that folder)
- open the sheet, go to "Extensions > Apps Script" and a new tab will open (if you close the sheet, the new tab closes automatically)
- look at the code.gs and adapt it to your needs, see the functions comments and code.
- the
mainfunction can be used to group files which should be backed up at the same time, you can have others likemainDailyormainWeeklyand then put the files logic there: backup + optional removal of old backups - you can save and run to see if it works as expected
- still in the "Apps Script" environment, go on the left side and switch to the "Triggers" tab
- add a new trigger and select the
mainfunction, then select the event source asTime-Drivenand add the desired interval. you can do this for multiple functions, in case you want some files backed up with different frequencies. - you can also decide to receive error notifications immediately upon failures
- optional: explore the other tabs in the "Apps Script" since they give more info on previous executions and configurations.
Result
You will get the following file structure for the example in code.gs:
- backups_folder
- MY_SHEET
- 1
yyyy-dd-mmfolder per day- original_name_timestamp
- ... other backups in that day ...
- 1
- PRESENTATION_DOC
- 1
yyyy-dd-mmfolder per day- original_name_timestamp
- ... other backups in that day ...
- 1
- WORD_DOC
- 1
yyyy-dd-mmfolder per day- original_name_timestamp
- ... other backups in that day ...
- 1
- MY_SHEET