Scripting and Automating Backups on Windows
Part One: Hardware
Examples of external hard drives.
An external hard drive is not the only option for this. You could add another hard drive inside your computer if your computer has the space for it. If you have a server or NAS available you can set them up as a mapped drive to utilize the storage on those devices. You could also use a flash drive if you had to but I would not personally recommend that. For the purpose of keeping this as simple as possible I will assume you are doing this on an external hard drive but the steps won’t change much if you choose another method.
Part Two: Scripting with Batch Files
You will want to open your notepad app to create a text file but we will be saving it as a batch file which uses a .bat extension. Simply click on the start menu and type “notepad” to search for the Notepad app. Click on Notepad to open it.
Once open, let's immediately save a file. Click “File” > “Save As…” to bring up the “Save As” window. For my example I am going to save this directly in my user folder “C:\Users\InfosecMiles” as “backup-demo.bat”. Name your batch file whatever you feel is appropriate. Make sure you change the “Save as type:” from “Text Documents (*.txt)” to “All Files (*.*)” because Notepad will add a .txt to the end of your file name and it will not work properly. Click the “Save” button to finish saving this file.
You now have a blank file saved under the name you gave it. Mine is “backup-demo.bat”. The first thing you will add is
Part Three: Automation with Task Scheduler
For this final part you will need to open the Task Scheduler. To get to this you will click on the Start button and type "Control Panel" and select the Control Panel from the menu. Inside the Control Panel look for the "View by:" option and change it from "Category" to "Small icons". Then click on "Administrative Tools" and then double-click on "Task Scheduler". The Task Scheduler window will be open now. On the right side click "Create Basic Task..." under Actions.
In the "Create Basic Task" window you will be asked for a Name and Description. You may put whatever you feel is appropriate here. I am just naming mine "backup-demo". Click "Next".
You will then be asked how frequently you want this script to be run. Make whatever decision is appropriate for you. I am leaving mine set to "Daily". Click "Next".
On this screen it wants to know when you want to start this task and how often it will recur. I'll set the date and time for 5 a.m. the next day since I'm typically not using my computer at this time. I am also leaving the Recur setting at "1". Click "Next".
The next screen is asking for the action this task will perform. Select "Start a program" and click "Next".
Now you will need to add the batch script. Select the Browse button and navigate to where you have saved the batch script. Click on the file and then click "Open". You can leave the rest of the options blank. Click "Next".
On the final screen, select the "Open the Properties dialog for this task when I click Finish" and click "Finish".
The Properties dialog will now be open. Select "Run with highest privileges". This will make sure the script is run as an administrator. There are a lot of other options in the Properties dialog window. Feel free to explore them, research them and make appropriate changes if you feel they make sense for you. I personally have not made any further changes than what I have already described. Click "OK" when you are done making changes.
All you can do now is wait for the next day to verify that it worked. If that worked then congrats on making it all the way through this.
Microsoft Doc for the echo command