Build a version-snapshot system for key files
Keep dated copies of Northwind's critical Sheets before risky edits.
Published Sep 22, 2025
A handful of files run Northwind: the invoices sheet, the contracts log, the sales pipeline. Google’s own revision history covers a lot, but it is awkward to browse, easy to overrun on a busy day, and useless if a file is deleted outright. When someone pastes over the wrong range, you want a clean copy from this morning — not a scroll through three hundred autosaves.
This script makes a dated copy of each key file into a snapshots folder. Run it on a daily trigger and you build up a shelf of restore points; run it by hand before a risky bulk edit and you have an instant undo. The copies are ordinary files, so recovering one is just a matter of opening it.
What you’ll need
- The IDs of the files you want to snapshot — the string after
/d/in each file’s URL. - A dedicated folder to hold the snapshots, and its folder ID.
- Edit access to every key file and the snapshots folder.
- An eye on storage. Each run adds one copy per file; see “Watch out for”.
The script
// The files to snapshot on every run. Add or remove IDs as needed.
const KEY_FILE_IDS = ['1abcInvoicesId', '1abcContractsId', '1abcPipelineId'];
// The folder that collects the dated copies.
const SNAPSHOT_FOLDER_ID = '1abcSnapshotsFolderId';
// Timestamp format for the copy name. Minutes are included so two runs
// on the same day never collide.
const STAMP_FORMAT = 'yyyy-MM-dd-HHmm';
/**
* Makes a dated copy of every key file into the snapshots folder.
* Designed to run on a daily trigger, but safe to run by hand too.
*/
function snapshotKeyFiles() {
// 1. Resolve the snapshots folder. Bail out if the ID is wrong.
let folder;
try {
folder = DriveApp.getFolderById(SNAPSHOT_FOLDER_ID);
} catch (err) {
Logger.log('Could not open the snapshots folder — check SNAPSHOT_FOLDER_ID.');
return;
}
// 2. Bail out if there is nothing configured to snapshot.
if (!KEY_FILE_IDS.length) {
Logger.log('No key files configured — nothing to snapshot.');
return;
}
// 3. Build one timestamp for the whole run so every copy shares it.
const stamp = Utilities.formatDate(new Date(), 'GMT', STAMP_FORMAT);
// 4. Copy each file in turn, skipping any that cannot be opened.
let copied = 0;
for (const id of KEY_FILE_IDS) {
try {
const file = DriveApp.getFileById(id);
file.makeCopy(`${file.getName()} ${stamp}`, folder);
copied++;
} catch (err) {
Logger.log(`Skipped ${id} — could not copy it: ${err.message}`);
}
}
Logger.log(`Snapshot complete: copied ${copied} of ${KEY_FILE_IDS.length} file(s).`);
}
How it works
snapshotKeyFilesresolvesSNAPSHOT_FOLDER_IDinside atry/catch. If the folder cannot be opened, it logs a clear message and stops before touching anything.- It checks that
KEY_FILE_IDSis not empty — an empty list is a misconfigured script, not a reason to run silently. - It builds a single timestamp with
STAMP_FORMATat the start of the run, so every copy from that run carries the same stamp and sorts together. - It loops over the file IDs, opening each one and calling
makeCopywith a name of<original name> <stamp>into the snapshots folder. Each copy is wrapped in its owntry/catch, so one missing file does not stop the rest. - It logs how many files were copied versus how many were configured, which makes a partial failure obvious in the trigger’s execution history.
Example run
Say the three key files are named Invoices, Contracts, and Pipeline, and
the script runs at 06:00 on 22 September 2025. The snapshots folder gains three
new files:
| New copy in the snapshots folder |
|---|
Invoices 2025-09-22-0600 |
Contracts 2025-09-22-0600 |
Pipeline 2025-09-22-0600 |
The next day’s run adds another three with a 2025-09-23-0600 stamp. Because
the timestamp leads the sort within each name, the snapshots line up
chronologically in the folder.
Trigger it
Run this daily so a restore point always exists from earlier in the day:
- In the Apps Script editor, open Triggers (the clock icon).
- Click Add Trigger.
- Choose
snapshotKeyFiles, event source Time-driven, type Day timer, and a quiet hour such as midnight to 1am. - Save. Before any risky bulk edit, also run
snapshotKeyFilesby hand for an immediate restore point.
Watch out for
- Snapshots accumulate. A daily run on three files adds roughly ninety copies a month. Pair this with a cleanup that deletes copies older than a set age, or the snapshots folder will balloon and eat into Drive storage.
- The minute is part of the name for a reason. If you trim
STAMP_FORMATdown to the day only, two runs on the same day produce two files with identical names — Drive allows that, but it makes the right one hard to pick. makeCopyduplicates the file as it stands at run time. It does not capture Google’s revision history, so a restored snapshot starts its own fresh history.- Copying is per-file and not atomic. If the script fails midway, you may have snapshotted some files and not others — the run log shows exactly which, so check it after a failed run.
Related
Archive a project folder when it's marked done
Zip and shelve completed Northwind work — keep active folders focused on in-flight projects.
Updated Dec 11, 2025
Build a shared-drive migration helper
Move Northwind files between drives with structure intact — from My Drive to a Shared Drive.
Updated Oct 8, 2025
Bulk-restore accidentally trashed files
Recover everything trashed in a date range — Northwind's emergency-undo button.
Updated Sep 14, 2025
Pre-create dated archive folders
Generate per-month folders ahead of time so nothing lands in `misc/`.
Updated Sep 2, 2025
Move stale files to cold storage
Archive Northwind Drive files untouched for a year into a `cold storage` folder.
Updated Aug 1, 2025