Not everyone schedules her backups: some people can’t be bothered to use File History or a third party application. Although this isn’t the safest method to backup data, I realize that some people may have simpler needs, and if there is an even simpler way to back up data, all the better. When someone manually backups files and folder, they normally would connect the external device and drag and drop files from their original destination to somewhere in the external device. There is, however, a way to perform a one-click backup that can be achieved by following a few simple steps. Read on to find out more.
Create a simple backup script
Command Prompt commands aren’t just things you type in a window to perform a single task: they can also be used to write a script that performs a bunch of tasks at once (well, sequentially, but they’re executed automatically rather than done by hand). Such scripts end in .bat or .cmd extensions and are known as batch scripts or batch files. These can vary wildly in complexity and mastering their language can be rather tough. However, even a very simple one can prove very useful. The following script will back up the Users folder to our USB drive:
echo Press Enter to start backing up your data or close this window to cancel.
pause > NUL
robocopy c:\users %~dp0\backup\users /e /xj /copy:dat /r:1 /w:1
Just copy and paste it into Notepad (or another text editor) and save it as backup.cmd inside your external storage device. Now, you can back up your data by simply plugging in your backup drive and double-clicking backup.cmd.
A more advanced backup script
Of course, it’s also possible to create more advanced backup scripts, depending on your batch skills. I’m not the most experienced person in the world with batch, but I managed to come up with a way to backup all users, only the current user, or only public folders with a single script. The script also checks whether the user has administrator privileges and warns her if it cannot back up other users.
Here is what it looks like:
net session > NUL
echo One-click Backup version 1.0
echo Written by Andrea Luciano Damico and released under the MIT license.
echo For more information, visit www.github.com/Tech4Freelancers
if %ERRORLEVEL% EQU 0 (
echo The program is running as administrator. You may back up all users.
) else (
echo The program is running as a normal user. You may only back up public folders and the %username% folder.
choice /C ACP /N /M "What to backup? (A)ll valid users, (C)urrent user, (P)ublic only"
if %ERRORLEVEL% EQU 1 goto allusers
if %ERRORLEVEL% EQU 2 goto currentuser
if %ERRORLEVEL% EQU 3 goto publiconly
echo Backing up all users.
robocopy c:\users\ %~dp0\backup\users /e /xj /copy:dat /r:1 /w:1 /xd appdata /xf *.log
echo Backing up %username%
robocopy "c:\users\%username%" "%~dp0\backup\users\%username%" /e /xj /copy:dat /r:1 /w:1 /xd appdata /xf *.log
echo Backing up public only
robocopy "c:\users\All users" "%~dp0\backup\users\All users" /e /xj /copy:dat /r:1 /w:1 /xd appdata /xf *.log
robocopy "c:\users\Public" "%~dp0\backup\users\Public" /e /xj /copy:dat /r:1 /w:1 /xd appdata /xf *.log
echo Process completed. Press any key to close the program.
pause > NUL
Don’t worry too much about what each section of the script does. If you’re curious, a version with comments is available on GitHub.
And of course, even this version can further be expanded, although I think that, as it is, this one is already rather good for most people.
Customizing your backup drive look and feel
This part is optional and only adds eye candy to our backup USB device. You may skip it, but following this part is advisable because it will allow you to easy tell it apart from other drives.
If you’ve ever installed software from a CD or DVD in the past, you may have noticed that it contained a file named autorun.inf that told the operating system what to do when it detected that disc in your system. The good thing is that USB thumb drives and hard drives support autorun.inf. The bad news is that you can’t make it execute commands automatically on those devices (it only works for optical discs). However, this isn’t bad news at all, because the program that executes automatically may be malicious in nature. What we can do is creating our own autorun.inf to give our external storage device a custom name and icon.
Create a new text file in the root directory of your external drive and copy and paste the following:
The icon bit is the name (with extension) of the image we want to use as our drive’s icon. It can be anything, but I personally like this one by Icons Mind. Remember to rename it Backup.ico and copy it to the root folder of your backup drive.
Now that everything’s ready, it’s time to eject our storage device and reconnect it. The result should be similar to this:
Double-click One-click Backup and run backup.cmd. And that’s it: every time you want to back up your data, just plug your external drive in your computer and double-click backup.cmd.