FaizBlog LogoFaizBlog
Back to all articles
Google Apps ScriptBackupGoogle DriveOtomatisasiData Recovery

Cara Backup Spreadsheet Otomatis ke Google Drive dengan Apps Script

Panduan lengkap backup Google Sheets otomatis tiap hari ke folder Drive, dengan auto-rotate 30 hari, notifikasi email, dan export ke .xlsx. Anti kehilangan data selamanya.

AI Insights

Generate a summary and suggested tags for this post.

Meski Google Sheets jauh lebih aman dari Excel di komputer lokal, bukan berarti file kamu kebal dari kehilangan data. Sudah banyak cerita "kolaborator tidak sengaja hapus 500 baris", "rumus VLOOKUP tiba-tiba jadi #REF!", atau bahkan file dihapus permanen dari Trash setelah 30 hari.

Solusinya: backup otomatis — copy spreadsheet ke folder Drive tiap hari, tanpa harus buka file.

3 alasan wajib backup Sheets

Kenapa Backup Otomatis Wajib?

RisikoBackup Bantu Karena
File terhapus dari Trash > 30 hariPunya salinan di folder khusus
Rumus rusak karena edit sembaranganBisa pulihkan versi hari kemarin
Kolaborator overwrite baris pentingBandingkan dengan backup terakhir
Serangan phishing / akun dibajakBackup di folder terpisah bisa direstore
Migrasi Sheets ke Excel offlineFile .xlsx sudah ada di Drive

Langkah 1: Buat Folder Backup Khusus

Di Google Drive, buat folder baru bernama "Backup Otomatis". Catat ID folder dari URL: drive.google.com/drive/folders/**ID_FOLDER**

Langkah 2: Tulis Script Backup

Buka file Sheets yang mau di-backup → Extensions → Apps Script → paste:

const FOLDER_BACKUP = "ID_FOLDER_DRIVE";        // ganti dengan ID folder kamu
const MAX_HARI      = 30;                       // simpan max 30 hari terakhir

function backupSheets() {
  const source = SpreadsheetApp.getActiveSpreadsheet();
  const folder = DriveApp.getFolderById(FOLDER_BACKUP);
  const today  = Utilities.formatDate(new Date(), "GMT+7", "yyyy-MM-dd");
  const name   = `Backup-${source.getName()}-${today}`;

  // Copy file ke folder backup
  DriveApp.getFileById(source.getId()).makeCopy(name, folder);

  // Hapus backup yang lebih tua dari 30 hari
  const files = folder.getFiles();
  const batas = new Date();
  batas.setDate(batas.getDate() - MAX_HARI);
  while (files.hasNext()) {
    const f = files.next();
    if (f.getDateCreated() < batas) f.setTrashed(true);
  }
}

Klik Save → Run. Setujui akses Drive. Selesai — 1 copy file muncul di folder backup dengan format: Backup-NamaFile-2025-05-20

Langkah 3: Pasang Trigger Harian

Folder backup di Drive

Supaya backup jalan otomatis setiap malam:

  1. Editor Apps Script → ikon ⏰ TriggersAdd Trigger.
  2. Function: backupSheets.
  3. Event source: Time-driven → Day timer → 11pm-12am.
  4. Save.

Selesai. Tiap malam sebelum tengah malam, script otomatis:

  • Copy spreadsheet ke folder backup dengan nama bertanggal.
  • Hapus backup yang lebih tua dari 30 hari (biar tidak boros storage).

Strategi Backup: Pilih yang Sesuai

Strategi backup harian mingguan bulanan

StrategiFrekuensiRetensiCocok Untuk
HarianSetiap hari 23:0030 fileData transaksi harian, absensi
MingguanSenin 08:0012 file (3 bulan)Laporan kerja, database klien
BulananTanggal 1 pagi12 file (1 tahun)Arsip finance, laporan tahunan
HybridKombinasi ketiganya54 file totalData super-kritis (< 100MB)

Backup dalam Format Excel (.xlsx)

Kalau butuh file offline (contoh: audit, dikirim ke auditor eksternal), export ke .xlsx:

function backupSheetsAsXlsx() {
  const source = SpreadsheetApp.getActiveSpreadsheet();
  const folder = DriveApp.getFolderById(FOLDER_BACKUP);
  const today  = Utilities.formatDate(new Date(), "GMT+7", "yyyy-MM-dd");

  const url = `https://docs.google.com/spreadsheets/d/${source.getId()}/export?format=xlsx`;
  const blob = UrlFetchApp.fetch(url, {
    headers: { Authorization: "Bearer " + ScriptApp.getOAuthToken() }
  }).getBlob().setName(`Backup-${today}.xlsx`);

  folder.createFile(blob);
}

Notifikasi Backup Sukses / Gagal

Untuk memastikan backup benar-benar jalan, tambah email konfirmasi:

function backupWithNotif() {
  try {
    backupSheets();
    GmailApp.sendEmail("admin@perusahaan.com",
      "✅ Backup Sukses", `Backup harian selesai jam ${new Date()}`);
  } catch (err) {
    GmailApp.sendEmail("admin@perusahaan.com",
      "❌ Backup GAGAL", `Error: ${err.message}`);
  }
}

Tips Penting

  • Jangan backup ke folder yang sama dengan file asli — kalau folder utama di-share dan di-hapus, backup ikut hilang.
  • Batas storage Drive gratis: 15 GB — kalau file besar, jangan simpan 100 backup.
  • Pertimbangkan external backup — sync folder backup ke Dropbox/OneDrive untuk redundansi.
  • Test restore sesekali — backup yang tidak pernah dites bisa corrupt tanpa disadari.

Kesimpulan

Sekali setup 15 menit, kamu punya sistem backup otomatis dengan level enterprise:

  • ✅ Copy harian ke folder khusus
  • ✅ Auto-rotate (hapus file > 30 hari)
  • ✅ Notifikasi email sukses/gagal
  • ✅ Fleksibel: harian, mingguan, atau bulanan
  • ✅ Bisa export ke .xlsx untuk offline

Data kantor sepenting jantung bisnis — jangan sampai kolaborator ceroboh atau bug tidak sengaja bikin kamu kehilangan berbulan-bulan data. 🛡️