Java Developer

Windows backup solution that you already have

There are three kinds of people. Ones that backup their data before first data crash, after or never. In which group you are?

Why you need to backup?

If your hard drive is corrupted then you need to pick another one and set up the entire environment from scratch. When you delete something permanently, it would be good to get it back easily. Heavy virus infection is also a good reason cleanup system, move few days back in time but have all elements operational without the risk of losing more.

What you need to backup?

Entire program files or system directory is something that do not need the backup for sure. Most applications need full installation procedure anyway. When we narrow down what kind of data we want to secure it is easier to pick right back up option. What I backup:

How you are going to backup your files?

Full disk image clone is problematic and you will not be able to easily look for something in that backup. I remember my friend did a full disk image and burn it on 12 DVDs. Recovering procedure was so time-consuming that he decided is not worth recovering. Some backups are not recoverable at all because software expired or image has been corrupted during creation. I thought I need very specialized software or RAID 0 to have reliable and easy to use backup solution. Thankfully, I was wrong :).

Do the robot

Ok, so where is the silver bullet? Since Windows 7 there is built-in command line tool called robocopy. It is doing what needs to be done. It is part of the a system so there is no UI overhead (which I found problematic in some solutions). I created simple bat file to do all the work for me. Once a week I’m plug in HDD drive and execute the backup operation. Simple.

rem Robocopy parameters
rem /MIR - Mirror mode; copies subdirectories; deletes destination files and directories that no longer exist in the source.
rem /R:1 - Fail after one retry.
rem /V - Verbose mode.
set args=/MIR /R:1 /V

rem Target backup drive
set backup=O:\backup

rem Mirrors configuration
rem Here you can configure a list of directories
robocopy D:\arch %backup%\ssd %args%
robocopy E:\arch %backup%\hdd %args%
robocopy W:\work %backup%\work %args%

Be aware that robocopy might require admin privileges on your computer. To ensure and fail fast when executed without privileges. I am using guard at the beginning of file:

rem DETECT ADMIN PRIVILEGES, IF NOT QUIT
rem source: http://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
NET SESSION >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
    echo Administrator privileges Detected! 
) ELSE (
    echo ######## ########  ########   #######  ########  
    echo ##       ##     ## ##     ## ##     ## ##     ## 
    echo ##       ##     ## ##     ## ##     ## ##     ## 
    echo ######   ########  ########  ##     ## ########  
    echo ##       ##   ##   ##   ##   ##     ## ##   ##   
    echo ##       ##    ##  ##    ##  ##     ## ##    ##  
    echo ######## ##     ## ##     ##  #######  ##     ## 
    echo.
    echo.
    echo ####### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED #########
    echo This script must be run as administrator to work properly!  
    echo ##########################################################
    echo.
    PAUSE
    EXIT /B 1
)

Enjoy. Have better alternative? Feel free to comment!


Like it? Share it on , , ,

About the author

Grzegorz Gajos, Software Architect with international consulting and programming background. Co-founder of Open Tangerine Software House. Quality evangelist. An experienced entrepreneur, out of the box thinker and problem solver.