Google Apps Script that exports all your Google Docs/Sheets/Slides into docx/xlsx/pptx files and PDFs in a folder in your Google Drive.
I originally posted this as a gist. I've made several variations on it in response to requests by others, as well as changes in my own needs. Using a regular repo makes these variants easier to keep track of. If this version doesn't exactly match your needs, see the the list of branches to see some of the ways the script can be adjusted.
As always, this code may have defects that prevent it from working properly. Use at your own risk and remember to periodically verify that your backups are actually working as expected.
For each file, both an Office file (docx/xlsx/pptx) and a PDF are generated.
All the Office files and PDFs are combined into a single zip file that's placed in the backup folder.
The zip file will be given a name such as GoogleDocs-2020-04-01TT031532Z.zip
.
The script does not delete old zip files. You'll need to take care of that yourself if you don't want the number of zips to grow forever.
Only files that you own (as opposed to files others have shared with you) will be backed up.
Remove the file.getOwner()
check from the backupAll
method if you want to change that.
Google's export API has a file size limit of 10MB. If the exported form of a particular document is larger than that, this script will not be able to back it up.
-
Create a new Google Apps Script project and copy the GoogleDocsBackup.gs script file into it.
-
In the script, replace INSERT_FOLDER_ID_HERE with the ID of the folder you want backups to be placed in.
-
Run the
backupAll
function. You'll probably want to create a trigger to run it on a schedule (e.g. nightly).
If you'd like step-by-step setup instructions, see this post: http://brokensandals.net/google-docs-backup