简体   繁体   English

通过文件转换将 Google Drive 备份到 .zip 文件

[英]Backup Google Drive to .zip file with file conversion

I keep going in circles on this topic, and can't find an automated method that works for mass data on a Google Drive.我一直在这个话题上兜圈子,找不到适用于 Google Drive 上海量数据的自动化方法。 Here is the goal I'm looking to achieve:这是我希望实现的目标:

My company uses an unlimited Google Drive to store shared documents, and we are looking to backup the contents automatically.我的公司使用无限制的 Google Drive 来存储共享文档,我们希望自动备份内容。 But we can't have the data stored in a backup with google documents like ".gdoc" and ".gsheet"... we need to have the documents backed up in Microsoft/Open-Office format (".docx" and ".xlsx").但是我们不能将数据存储在带有诸如“.gdoc”和“.gsheet”之类的 Google 文档的备份中……我们需要以 Microsoft/Open-Office 格式(“.docx”和“ .xlsx”)。

We currently use Google's Takeout page to zip all the contents of the Drive and save it on our Linux server (That has redundant storage).我们目前使用谷歌的外卖页面来压缩驱动器的所有内容并将其保存在我们的 Linux 服务器上(具有冗余存储)。 And it does zip and export the files to the correct formats.它确实将文件压缩并导出为正确的格式。 Here: [https://takeout.google.com/settings/takeout][1]此处:[https://takeout.google.com/settings/takeout][1]

Now that works... but requires a bit of manual work on our part.现在这可行……但需要我们进行一些手动工作。 And babysitting the zip, download and upload processes is becoming wasteful.照看 zip、下载和上传过程变得很浪费。 I have searched and have read that the google API for Takeout is unavailable to use through gscript.我已经搜索并读到谷歌外卖 API 无法通过 gscript 使用。 So, that seems to be out of the question.所以,这似乎是不可能的。

Using Google scripts, I have been able to convert single files.... but can't, for instance, convert a folder of ".gsheet" files to ".xlsx" format.使用谷歌脚本,我已经能够转换单个文件......但不能,例如,将“.gsheet”文件的文件夹转换为“.xlsx”格式。 Maybe copying and converting all the google files into a new folder on the drive could be possible.也许可以将所有谷歌文件复制并转换到驱动器上的新文件夹中。 Having access to the drive and the converted "backup", we could then backup the collection of converted files via the server...可以访问驱动器和转换后的“备份”,然后我们可以通过服务器备份转换后的文件集合......

So here is the just of it all:所以这就是全部:

  1. Can you mass-convert all of a google drive and/or a specific folder on the drive from ".gdoc" to ".docx", and ".gsheet" to ".xlsx".您能否将所有谷歌驱动器和/或驱动器上的特定文件夹从“.gdoc”批量转换为“.docx”,并将“.gsheet”批量转换为“.xlsx”。 Can this be done with gscript?这可以用 gscript 完成吗?

  2. If not able to via the method in question one, is anyone familiar with an Linux of Mac app that could do such a directory conversion?如果无法通过问题一中的方法,是否有人熟悉可以进行此类目录转换的 Mac 应用程序的 Linux? (Don't believe it because of googles proprietary file types) (不要相信,因为谷歌的专有文件类型)

I'm stuck in a bit of a hole, and any insight to this problem could help.我陷入了困境,对此问题的任何见解都可能有所帮助。 I really wish Google would allow users to convert and export drive folders via a script selection.我真的希望 Google 允许用户通过脚本选择来转换和导出驱动器文件夹。

#1) Can you mass-convert all of a google drive and/or a specific folder on the drive from ".gdoc" to ".docx", and ".gsheet" to ".xlsx". #1) 您能否将所有谷歌驱动器和/或驱动器上的特定文件夹从“.gdoc”批量转换为“.docx”,并将“.gsheet”批量转换为“.xlsx”。 Can this be done with gscript?这可以用 gscript 完成吗?

You can try this:你可以试试这个:

How To Automaticlly Convert files in Google App Script 如何在 Google App Script 中自动转换文件

Converting file in Google App Script into blob将 Google App Script 中的文件转换为 blob

var documentId = DocumentApp.getActiveDocument().getId();        

function getBlob(documentId) {
 var file = Drive.Files.get(documentId);
 var url = file.exportLinks['application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
 var oauthToken = ScriptApp.getOAuthToken();
 var response = UrlFetchApp.fetch(url, {
   headers: {
     'Authorization': 'Bearer ' + oauthToken
   }
 });
 return response.getBlob();
}

Saving file as docx in Drive在云端硬盘中将文件另存为 docx

function saveFile(blob) {
   var file = {
    title: 'Converted_into_MS_Word.docx',
    mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  };
  file = Drive.Files.insert(file, blob);
  Logger.log('ID: %s, File size (bytes): %s', file.id, file.fileSize);
  return file;
}

Time-driven triggers 时间驱动触发器

A time-driven trigger (also called a clock trigger) is similar to a cron job in Unix.时间驱动触发器(也称为时钟触发器)类似于 Unix 中的 cron 作业。 Time-driven triggers let scripts execute at a particular time or on a recurring interval, as frequently as every minute or as infrequently as once per month.时间驱动的触发器允许脚本在特定时间或重复间隔执行,频率为每分钟一次或每月一次。 (Note that an add-on can use a time-driven trigger once per hour at most.) The time may be slightly randomized — for example, if you create a recurring 9 am trigger, Apps Script chooses a time between 9 am and 10 am, then keeps that timing consistent from day to day so that 24 hours elapse before the trigger fires again. (请注意,附加组件最多可以每小时使用一次时间驱动触发器。)时间可能会稍微随机化 - 例如,如果您创建重复的上午 9 点触发器,Apps 脚本会选择上午 9 点到 10 点之间的时间am,然后每天保持该时间一致,以便在触发器再次触发之前 24 小时过去。

function createTimeDrivenTriggers() {
  // Trigger every 6 hours.
  ScriptApp.newTrigger('myFunction')
      .timeBased()
      .everyHours(6)
      .create();

  // Trigger every Monday at 09:00.
  ScriptApp.newTrigger('myFunction')
      .timeBased()
      .onWeekDay(ScriptApp.WeekDay.MONDAY)
      .atHour(9)
      .create();
}

Process:过程:

  1. List all files id inside a folder 列出文件夹内的所有文件ID
  2. Convert Files转换文件
  3. Insert Code to a Time-driven Triggers将代码插入时间驱动触发器

2) If not able to via the method in question one, is anyone familiar with an Linux of Mac app that could do such a directory conversion? 2)如果不能通过问题一的方法,有没有人熟悉可以进行这种目录转换的Mac应用程序的Linux? (Don't believe it because of googles proprietary file types) (不要相信,因为谷歌的专有文件类型)

If you are want to save it locally try setting a cronjob and use Download Files如果您想将其保存在本地,请尝试设置 cronjob 并使用下载文件

The Drive API allows you to download files that are stored in Google Drive. Drive API 允许您下载存储在 Google Drive 中的文件。 Also, you can download exported versions of Google Documents (Documents, Spreadsheets, Presentations, etc.) in formats that your app can handle.此外,您还可以下载应用可以处理的格式的 Google 文档(文档、电子表格、演示文稿等)的导出版本。 Drive also supports providing users direct access to a file via the URL in the webViewLink property. Drive 还支持通过webViewLink属性中的 URL 为用户提供对文件的直接访问。

Depending on the type of download you'd like to perform — a file, a Google Document, or a content link — you'll use one of the following URLs:根据您要执行的下载类型(文件、Google 文档或内容链接),您将使用以下网址之一:

  1. Download a file — files.get with alt=mediafile resource下载文件 — files.get with alt=media文件资源
  2. Download and export a Google Doc — files.export下载并导出 Google Doc — files.export
  3. Link a user to a file — webContentLink from thefile resource将用户链接到文件 — 来自文件资源的webContentLink

Sample Code :示例代码:

$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$content = $driveService->files->get($fileId, array(
  'alt' => 'media' ));

Hope this helps and answered all you questions希望这对您有所帮助并回答了您的所有问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM