Gadget
Gadget

Reputation: 71

How to backup bound Google Apps Script

I have looked fairly extensively on this site and on the web and cannot find any posts on how to backup bound Google Apps Scripts. Is there a way to do this and how? I use a backup solution for anything in Google Drive, although when restoring any file the bound scripts/projects are not part thereof.

Any help would be welcome, thanks beforehand

Upvotes: 5

Views: 1908

Answers (2)

gilles bousquet
gilles bousquet

Reputation: 31

with the latest version of google scripts just use "id of script" instead of project key (deprecated).

Upvotes: 0

Alan Wells
Alan Wells

Reputation: 31300

This is not a perfect solution, but it does provide a way to extract content from a bound project.

In the the bound script project, that you want to get the .gs functions out of, click the "file" menu, and choose "Manage Versions".

Manage Versions

Enter a description, and click "Save New Version"

In the the bound script project that you want to get the .gs functions out of, click the "file" menu, and choose "Project Properties".

Project Properties

Copy the Project Key.

How to Use the Project Key to link to a library

The "library" is just the bound project that you want to back up.

In a different Apps Script file, add the Project Key as the library.

  • Resources
  • Libraries

Add a Library

In the "Find a Library" box, paste in the Project Key of the project that you want to back up.

Choose the latest version, and make a note of the "Identifier".

Add this code to the Apps Script file that you just added the library to:

function backUpAllFunctions() {
  var fileName = "backUp",
      allServerFunctions = "",
      fncName;

  for (fncName in TestStuff) {
    //Logger.log(fncName)
    allServerFunctions += TestStuff[fncName];
  };

  DriveApp.createFile(fileName, allServerFunctions, MimeType.PLAIN_TEXT);
};

Run the above code, and look in your Google Drive. There will be a new text file which whose contents will be all of the functions in the bound project.

If you have HTML files that you want to back up, that can also be done, but that takes a different strategy. HTML Service needs to be used.

Upvotes: 2

Related Questions