Automatically Backup a Spreadsheet File or Tab
Learn how to automatically back up your spreadsheet or specific tabs using Google Apps Script, ensuring your data is safely stored weekly without manual intervention.
Let's say we fill out this kind of sales document every single week and we want to make a copy of this or rather back it up. Uh, if we want to back up this kind of sales document every week, how do we do that automatically? Well, the first thing is that there's sort of two ideas here. One, we can duplicate this and rename it as the day of the week or like Monday. Or, We could do that automatically, or we could make a file, make a copy of the entire sheet, and save that as a backup. Um, either way, I'm going to show you both ways here. So, in our Apps Script , we go to Extensions, Apps Script , I've presented and created two so far. So, one is called Create Backup Tab, and one is Create Backup File. Depending on which one you want to use, um, we're going to automate Automatically Backup a Spreadsheet Automatic Weekly Backup of Google Sheets Back up Spreadsheet Tab How to Automatically Copy Tab Every Week
these Pretty much the same way. So let me walk through the script first and then I'll show you how to automate it. First, we have create backup tab. We're just duplicating the tab and then we're going to rename it to this new date, uh, which is the date that we're backing it up. Uh, we can see here that this runs totally fine. Uh, we go over here and we see backup and the date. Now, for creating a backup file, we're taking the entire spreadsheet , making a copy of it, and we're going to call this backup, um, of the name of the sheet, plus we can also use this same date, uh, to have a date for the, uh, backup. Automatically Backup a Spreadsheet Automatic Weekly Backup of Google Sheets Back up Spreadsheet Tab How to Prevent Delete Tab
This is just to keep files sort of straight. So let's save that and let's run this one. We're logging the URL of the copy just so we have a copy of it so we don't have to search through our, uh, drive to find it. So we'll run it and we'll see in the log here once it copies. We'll see a URL and we'll go, we'll go check it and see if it's correct. Here's the URL of the new document, and we'll look at it and see, yes, it's backup, and it has the name of the sheet and the date of the backup, right, the moment that we do it. It also still has this backup tab in here, but So maybe you want to do one or the other, probably not both. You probably don't want to create a new tab and create a new spreadsheet file at the same time. So, um, you're probably picking one or the other. So how do we automate this? Meaning, how does this happen every single week without us having to come Automatically Backup a Spreadsheet Automatic Weekly Backup of Google Sheets Back up Spreadsheet Tab How to Prevent Delete Tab
into this sheet and run this file or, uh, even doing this ourselves, file, make a copy, rename it. How does this work, right? What we're going to do is create a trigger over on the left side. Once we have this. These scripts create a trigger . Click on triggers on the bottom, right? We'll click add trigger and whichever one you want to choose to do, choose that from the functions to run. So we'll choose tab and run. Select event source is going to be time driven. In this case, we want a weekly backup, or you may want a daily backup or a monthly backup. Either one, you'll use time driven. And for a weekly, we use week timer. We're going to do it at the end of the week, probably on a Friday Automatically Backup a Spreadsheet Automatic Weekly Backup of Google Sheets Back up Spreadsheet Tab How to Prevent Delete Tab
night, uh, Friday around 6 to 7 PM. Give people a little bit chance to stay late a little, enter their numbers in. Sometimes you may want to do this even on a Tuesday or a Wednesday. If people are. Definitely adding their numbers from the last week at the beginning of the week. Totally up to you and whatever your business operates in. So we're going to save this Friday 6 PM and that is it. Now we are automatically backing up this spreadsheet every single week. Again, we've chose the function backup tab, so it'll create a new tab, but if we want a new spreadsheet file completely, we can go and edit this, uh, trigger and we can choose create backup file. So as long as it runs fine. By your testing, you'll be able to run this trigger totally fine. Automatically Backup a Spreadsheet Automatic Weekly Backup of Google Sheets Back up Spreadsheet Tab How to Prevent Delete Tab
It's running as you, um, we can also delete the trigger . If you click on this three buttons over here, just in case you're like, Hey, we're, we're inundated or it has some errors. We're getting an error . Maybe it's too many tabs or too many spreadsheet files. We're doing it every hour or something. If you do mess up in that way, or you get to some time when you're like, Hey, I don't need to back this up anymore. You can always go over here and delete trigger in this three buttons over to the right. Delete that. So that's how you can automatically back up a spreadsheet , uh, and I think it's really cool and really useful for those who are, um, trying to keep track of something in a sheet, and you know, ah, I want to keep, Backlogs of this information. And I want to keep it in either a separate file or a separate tab, but Automatically Backup a Spreadsheet Automatic Weekly Backup of Google Sheets Automatically Backup a Spreadsheet How to Prevent Delete Tab
I want to have a one place where I enter the data each and every time. So that's really cool. And I hope this was super fast and easy for you. Again, better sheet members. If you're watching this on better sheets down below, click the link to the sheet. Copy the sheet, get the app script totally free. If you're watching this somewhere else, become a better sheets member today and get every spreadsheet you see in these tutorials, absolutely free. Once you become a lifetime member. Spreadsheet Automation for Beginners Create a ChatGPT Cheat Sheet Spreadsheet Advanced Coding in Google Sheets for Programmers OnlySheets