text 使用Google Apps脚本创建Google表格的自动计划备份副本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 使用Google Apps脚本创建Google表格的自动计划备份副本相关的知识,希望对你有一定的参考价值。

# How to "Schedule Automatic Backups" of your Google Sheets

**This tutorial demonstrates how to use Google Apps Script to:**

* Create copies of the Google Sheet in the desired destination folder automatically at set intervals.
  
* Append the time stamp with each backup file's name.

* Adjust time trigger for backing up every day/hour/minute.
1. Open your Google Drive and create a new folder right where your Google Sheet is. You may name it anything you like.
![step 1](http://i.imgur.com/TVNhCs3.jpg)  

2. Open the folder you just created. You will be able to see its ID in the URL displayed in your browser's address bar. We will need this later.
![step 2](http://i.imgur.com/pfH12nu.jpg)

3. Open your Google Sheet and select menu item "Tools" --> "Script Editor"
![step 3](http://i.imgur.com/mmrC8GZ.jpg)

4. Once the script editor opens, copy and paste the code from the **2-MakeCopy.gs** file (see file below) into the "Code.gs" file, replacing the code that's already included.
![step 4](http://i.imgur.com/utYab6J.jpg)

5. Copy the ID of the folder you created earlier and paste in place of the xxxxxxxxxxxxxxxxxxxxxxx in the code.
![step 5](http://i.imgur.com/2l9ifuy.jpg)

6. Go to menu "File" --> "Save".
![step 6](http://i.imgur.com/KEMEIcQ.jpg)

7. Click on the clocked shaped "Trigger" button.
![step 7](http://i.imgur.com/njRxIaZ.jpg)

8. Click on the blue link to add a trigger.
![step 8](http://i.imgur.com/TOY4zbM.jpg)

9. Select the time interval as per your desire.
![step 9](http://i.imgur.com/0yL6Mx5.jpg)

10. Click on "Continue" to authorize running the script you just made.
![step 10](http://i.imgur.com/z5xdpan.jpg)

11. Click on "Allow" to let the script run on your Google Sheet.
![step 11](http://i.imgur.com/9aIvvlJ.jpg)

12. After the set interval(which was every minute in my case), you can see the automatic scheduled backup copies of your Google Sheet saved in the folder you created.
![step 12](http://i.imgur.com/f41X6ef.jpg)
// Abhijeet Chopra
// 26 February 2016
// Google Apps Script to make copies of Google Sheet in specified destination folder

function makeCopy() {

// generates the timestamp and stores in variable formattedDate as year-month-date hour-minute-second
var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss");

// gets the name of the original file and appends the word "copy" followed by the timestamp stored in formattedDate
var name = SpreadsheetApp.getActiveSpreadsheet().getName() + " Copy " + formattedDate;

// gets the destination folder by their ID. REPLACE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your folder's ID that you can get by opening the folder in Google Drive and checking the URL in the browser's address bar
var destination = DriveApp.getFolderById("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

// gets the current Google Sheet file
var file = DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId())

// makes copy of "file" with "name" at the "destination"
file.makeCopy(name, destination);
}

以上是关于text 使用Google Apps脚本创建Google表格的自动计划备份副本的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Google Apps 脚本执行 API + Java 创建 Google 表单?

如何使用 Google Apps 脚本创建/更改具有给定 Meet URL 的 Google 日历活动?

使用 Google Apps 脚本创建 Etag 字符串

使用 Google Apps 脚本创建 Strava Webhook 订阅时出现问题

使用 Google Apps 脚本在 Google 表格中创建新表格

在 Google Apps 脚本中使用高级 Gmail 服务创建与表情符号兼容的 Gmail 草稿