Automated Daily Spreadsheet Backup to Google Drive Archive
Creates a point-in-time timestamped backup copy of a critical production Google Sheet inside a dedicated backup folder every night.
https://www.googleapis.com/auth/drive • https://www.googleapis.com/auth/spreadsheetsfunction backupSpreadsheetDaily() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const backupFolderId = 'PASTE_BACKUP_FOLDER_ID_HERE';
const backupFolder = DriveApp.getFolderById(backupFolderId);
const timestamp = Utilities.formatDate(new Date(), 'GMT', 'yyyy-MM-dd_HHmmss');
const backupName = ss.getName() + '_Backup_' + timestamp;
DriveApp.getFileById(ss.getId()).makeCopy(backupName, backupFolder);
}Line-by-Line Code Explanation
Step-by-Step Setup & Deployment
- Create a "Sheet Backups" folder in Google Drive and paste its ID in Line 3.
- Set a time-driven trigger to run daily at 1 AM.
Best Practices for Quota & Rate Limit Management
When deploying this automation in Google Workspace, adhere to these operational principles:
- Batch Reads & Writes: Never execute
getValue()orsetValue()inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a singlesetValues()call. - Execution Timeouts: Apps Script terminates scripts exceeding 6 minutes. For multi-thousand row datasets, implement batch pagination with resume timestamps stored in
PropertiesService. - OAuth Permissions: Scope your manifest (
appsscript.json) narrowly to prevent security prompts from alarming external team members.
Frequently Asked Questions
Is Google Apps Script completely free to use?
Yes. Google Apps Script is built into all free Google accounts and Google Workspace editions. There are no server fees or subscription costs for running scripts within daily quotas.
Can I run this script on an automated schedule without keeping my computer on?
Yes. Time-driven triggers execute on Google's cloud infrastructure. Your script will run reliably even when your computer is closed or offline.
More Google Drive Automation Snippets
Auto-Organize Google Drive Uploads into Year / Month Subfolders
Scans an incoming upload folder in Google Drive, examines file creation dates, and moves files into organized subfolders formatted as YYYY/MM.
Google DriveAudit Google Drive for Files Larger than 50MB and Export to Sheet
Scans Google Drive storage, identifies massive videos, zip archives, and bloated presentations, and logs file name, owner, and size into a spreadsheet for storage cleanup.
Google DriveExport Google Sheets Range to JSON File in Google Drive
Transforms a spreadsheet table into a structured JSON array of objects (using column headers as keys) and saves the file directly to Google Drive for frontend or mobile consumption.