备份应用程序制造商数据每晚



有没有办法对应用程序制造商数据库进行每晚备份?以防用户意外删除任何数据?

即使只有输出的电子表格也是可以接受的。

您可以创建一个基于时钟的可安装触发器,该触发器将在办公时间前的早晨每天执行一次。

此代码将在服务器端脚本上,看起来像这样:

function createInstallableTrigger() {
  // Runs at 5am in the timezone of the script
  ScriptApp.newTrigger("backUp")
  .timeBased()
  .atHour(5)
  .everyDays(1) // Frequency is required if you are using atHour() or nearMinute()
  .create();
}
function backUp() {
  try {
    var spreadSheet = SpreadsheetApp.openById("").getActiveSheet(),
        dataToBackUp = [],
        globalKeys = {
          model: ["first_name", "last_name", "email"],
          label: ["First Name", "Last Name", "Email"]
        },
    var records = app.models.requests.newQuery().run();
    if(records.length >= 1) {
      for (var i = 0; i < records.length; i++) {
        var newLine = [];
        for (var x = 0; x < globalKeys.model.length; x++) {
          newLine.push(records[i][globalKeys.model[x]]);
        }
        dataToBackUp.push(newLine);
        // at the end, push it all on the spreadsheet
        if(i === records.length - 1) {
          // check if there is any entry at all
          if(dataToBackUp.length >= 1) {
            // append column titles first
            spreadSheet.appendRow(globalKeys.label);
            // 
            spreadSheet.getRange(2, 1, dataToBackUp.length, globalKeys.model.length).setValues(dataToBackUp);
          }
        }
      }
    }
  } catch(e) {
    console.log(e);
  }
}

最新更新