Securing your online backups
One of the concerns of many people who consider performing online backups is the matter of security. You are uploading sensitive stuff to a foreign site. Can anyone from within read this stuff? And what if the site is hacked and white collar thieves living in some foreign country get hold of the data? What would happen?
One solution is to protect each and every document using a password. Many programs have such a capability built in. For many one, two or three person organisations this solution could work; the people would password protect every file using a phrase that is shared amongst colleagues. As the number of employees increase, guaranteeing that everyone is obeying the rules makes this solution one that is too problematic. Besides certain file types cannot be password protected.
The script I am sharing is one that addresses this problem. It makes use of the commercial product WinRar to archive an entire directory (including subdirectories) into a RAR file. The RAR file name is user definable and is placed in a folder under C:\RSB. The RAR archive is password protected using a password passed to the script. The script is called rsb.cmd.
The example below would archive everything starting from D:\Personal Docs\Articles to an archive called C:\RSB\Documents. The password used to encrypt the archive is 123456.
rsb Documents "D:\Personal Docs\Articles" 123456
If you have another folder you would like to archive, simply call the command above with a different archive name and a different directory. Using a different password is up to you.
Below is the script to perform this task:
@echo off
:: This script archives a directory and all its contents with a
:: password for storage in online backup service. It adds
:: recovery information to the archive thereby increasing the
:: chance of it being opened up if the archive is damaged.
:: This script compresses files thereby reducing the storage
:: requirements as well as upload times.
:: Written by Alan C. Bonnici (email chribonn@gmail.com) 2010/05
set r_Version=1.0
rem This script takes three parameters:
rem 1. The name of the archive
rem 2. The directory (and its sub-directories) that are to be archived
rem 3. The archive password
rem The archive will be placed into a directory called RSB. Your
rem online backup program should backup all files in this
rem directory
rem All 3 parameters are mandatory
if [%1]==[] GOTO :Error
if [%2]==[] GOTO :Error
if [%3]==[] GOTO :Error
set r_Archive=%1
call :DeQuote r_Archive
set r_Dir=%2
call :DeQuote r_Dir
if EXIST C:\RSB\NUL GOTO :DirExists
md C:\RSB
:DirExists
echo The contents of this archive are intended only for the person or entity to whom they belong and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. > "%TEMP%\comment.rsb"
if EXIST "%TEMP%\output.rsb" del /q "%TEMP%\output.rsb" > NUL
"%PROGRAMFILES%\winrar\winrar.exe" u -as -av -cfg- -ow -r -rr10p -inul -ilog"%TEMP%\output.rsb" -t -hp%3 -z"%TEMP%\comment.rsb" -- "C:\RSB\%r_Archive%" "%r_Dir%"
set r_Err=%ERRORLEVEL%
if %r_Err%==0 GOTO :EndCmd
rem An error occurred. Dump the file if it exists
if EXIST "%TEMP%\output.rsb" type "%TEMP%\output.rsb"
echo.
if %r_Err%==1 echo Warning. Non fatal error(s) occurred.
if %r_Err%==1 GOTO :EndCmd
if %r_Err%==2 echo Error. A fatal error occurred.
if %r_Err%==2 GOTO :EndCmd
if %r_Err%==3 echo Error. CRC error occurred when unpacking.
if %r_Err%==3 GOTO :EndCmd
if %r_Err%==4 echo Error. Attempt to modify a locked archive.
if %r_Err%==4 GOTO :EndCmd
if %r_Err%==5 echo Error. Write error.
if %r_Err%==5 GOTO :EndCmd
if %r_Err%==6 echo Error. File open error.
if %r_Err%==6 GOTO :EndCmd
if %r_Err%==7 echo Error. Wrong command line option.
if %r_Err%==7 GOTO :EndCmd
if %r_Err%==8 echo Error. Not enough memory.
if %r_Err%==8 GOTO :EndCmd
if %r_Err%==9 echo Error. File create error.
if %r_Err%==9 GOTO :EndCmd
if %r_Err%==255 echo Error. You aborted the process
if %r_Err%==255 GOTO :EndCmd
rem Undefined error.
echo Error. Undefined error %r_Err%
goto :EndCmd
:EndCmd
rem Clean up
if EXIST "%TEMP%\comment.rsb" del /q "%TEMP%\comment.rsb" > NUL
if EXIST "%TEMP%\output.rsb" del /q "%TEMP%\output.rsb" > NUL
set r_Archive=
set r_Dir=
set r_Err=
GOTO :EOF
:Error
echo This script takes three values:
echo 1. The name of the archive
echo 2. The directory (and its sub directories) that are to be archived
echo 3. The archive password
echo The archive will be placed into a directory called RSB (it will be created if it does not exist).
echo Your online backup program should backup all files in this directory.
echo RSB Documents "C:\Users\ACBonnici\Documents" Pa$$w0rd
goto :EOF
:: Removes the outer set of double quotes from a variable.
:: Written by Frank P. Westlake, 2001.09.22, 2001.09.24
:: Modified by Simon Sheppard 2002.06.09
:: Usage as a function within a script:
:: CALL :DeQuote VariableName
::
:: Calling as a function from another batch file:
:: CALL DeQuote.cmd VariableName
::
:: If the first and last characters of the variable contents are double
:: quotes then they will be removed. This function preserves cases such as
:: Set Height=5'6" and Set Symbols="!@#
::
:: If a variable is quoted twice and has delimiters then you will
:: need to run the function twice to remove both sets.
:: Set var=""Two Quotes;And,Delimiters=Fails""
::
:: If the variable name itself contains spaces the routine will fail
:: e.g. %v_my_variable% rather than %my variable%
:DeQuote
SET DeQuote.Variable=%1
CALL Set DeQuote.Contents=%%%DeQuote.Variable%%%
Echo.%DeQuote.Contents%|FindStr/brv ""^">NUL:&&Goto :EOF
Echo.%DeQuote.Contents%|FindStr/erv ""^">NUL:&&Goto :EOF
Set DeQuote.Contents=####%DeQuote.Contents%####
Set DeQuote.Contents=%DeQuote.Contents:####"=%
Set DeQuote.Contents=%DeQuote.Contents:"####=%
Set %DeQuote.Variable%=%DeQuote.Contents%
Set DeQuote.Variable=
Set DeQuote.Contents=
Goto :EOF
If you would like to download this script rather than copy and paste it from this article point your browser to http://www.RemoteStorageBackup.com/downloads/RSBArticleCode.rar. What remains is to set your online backup program to backup everything in the c:\RSB directory. Don’t forget to periodically test that everything is working well.
Next time I’ll delve into the code and explain what it does and how it works. This will allow you to customise it to your needs.
If you have any observations or questions send an email to chribonn@gmail.com.








