Hero Bg Gradient
February 24th, 2025

How to Automate Google Drive File Backups with Apps Script

Set up an automatic Google Drive backup in minutes. Learn how to copy files between Drive folders using a simple Apps Script.

Client Image

Patrick Flanagan

February 24th, 2025

Blog Details Image

Worried about losing important documents stored in Google Drive? A simple backup strategy can give you peace of mind—especially if you handle invoices, legal forms, or other critical files. In this tutorial, we’ll show you how to automate backups from one Drive folder to another using a quick Google Apps Script snippet.

Step 1: Identify Your Source and Destination Folders

  1. In Google Drive, navigate to the folder you want to back up. Copy its folder ID from the URL (it’s the long string after folders/).
  2. Create or locate your backup folder and copy its folder ID in the same way.

Example: If the URL is https://drive.google.com/drive/folders/1-AbCdEfGhI, then 1-AbCdEfGhI is your folder ID.

Step 2: Open the Script Editor

  1. In a new or existing Google Sheet, click Extensions in the top menu.
  2. Select Apps Script to open the Script Editor.

Tip: You can also go to script.google.com and create a new script directly.

Step 3: Add the Backup Code

Paste the following code into the Script Editor, making sure to replace the sourceFolderId and backupFolderId with your actual folder IDs:

function backupDriveFiles() {
  // Replace these with your folder IDs
  var sourceFolderId = "SOURCE_FOLDER_ID_HERE";
  var backupFolderId = "BACKUP_FOLDER_ID_HERE";
  
  var sourceFolder = DriveApp.getFolderById(sourceFolderId);
  var backupFolder = DriveApp.getFolderById(backupFolderId);
  
  // Get all files in the source folder
  var files = sourceFolder.getFiles();
  
  while (files.hasNext()) {
    var file = files.next();
    // Make a copy of each file in the backup folder
    file.makeCopy(file.getName(), backupFolder);
  }
  
  Logger.log("Backup complete!");
}

How It Works

  • DriveApp.getFolderById: Fetches the folder objects by their unique IDs.
  • getFiles(): Retrieves all files in the source folder.
  • makeCopy: Creates a duplicate of each file in the backup folder, preserving the original file name.

Step 4: Schedule Your Backup (Optional)

You can run this script manually or set it to run automatically on a daily/weekly basis:

  1. Click the Triggers icon (clock symbol) in the left sidebar of the Apps Script Editor.
  2. Add a new trigger.
  3. Choose backupDriveFiles as the function.
  4. Set an appropriate time-driven schedule (e.g., daily at 2 AM).
  5. Save and authorize the script if prompted.

Conclusion

That’s it! You now have a simple backup solution for your Google Drive files using Apps Script. Scheduled backups help ensure you always have extra copies of important documents in case of accidental deletions or overwrites.

Looking for more automation ideas? Get in touch for custom workflows tailored to your business. You’ll free up time and rest easy knowing your files—and your processes—are fully protected.

Ready to Transform Your Business?