JTD_DESIGN

A Creative Resource

Using batch files and Windows Scheduled Tasks to create automated backups

I am currently managing a PHP based filing and tracking system on Windows Server.  It is extremely important that the files and information that are archived and tracked in these systems are backed up frequently as a precaution against data loss.  Any developer with experience in this type of thing knows the importance of a solid backup process.

There are many options these days for methods of data backup including proprietary software as well as many open source options too. The method you choose will depend on what you are trying to achieve as well as the platform(s) you are working with.  When looking at options, I had to keep in mind that with a tight budget, a full proprietary software option was out of the question.  By no means am I suggesting that this method is the best solution in every case, but it works well for me.

In the solution I chose, I found that I could make reliable backups using a combination of batch files along with the Windows Scheduled Tasks application and WinZip.  Although this process still relies on Windows for it’s Scheduled Tasks application, you can make this work on other OS’s with a similar application. Also, WinZip is not a free solution either, but I know that it’s fairly cheap, but if you don’t feel like spending a dime, I’m sure you can get your hands on an alternative file compression software if you really wanted to. With that said, I found this process to be an easy alternative to forking out the Benjamins for the proprietary stuff.

The process includes:

  • Gathering the files to be backed up into temporary directories using a copy command.
  • Creating a new folder labeled with the current date.
  • Copying the contents of each temporary directory into the newly created folder.
  • Zip the new folder.
  • Burn DVD for off-site storage.

  1. To gather the desired files, I wrote a batch file that copies the files from their current location to a temporary destination folder. I used the xcopy command which allows for a buch of options for copying. Click HERE to view a list of options. (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true)

I used the following:

::/S Copies directories and subdirectories except empty ones.

::/C Continues copying even if errors occur.

::/E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.

::/H Copies hidden and system files also.

::/I If destination does not exist and copying more than one file, assumes that destination must be a directory.

::/R Overwrites read-only files.

::/Y Suppresses prompting to confirm you want to overwrite an existing destination file.

Here is an example of how the batch file should look:

:: turn off the output display

@echo off

::set the backup command variable

set backupcmd=xcopy /s /c /d /e /h /i /r /y

::Set the folder name variable as the current date

set folder=%date:~10,4%%date:~7,2%%date:~4,2%

::create a new directory with the current date

mkdir Path_to\%folder%

::copy the directory to be backed up into the new directory

%backupcmd% “C:\pathTo\folderToBeBacked\*.*” “:\pathToBackup\%folder%”

::use winzip to zip the newly created directory

C:\progra~1\winzip\winzip32.exe -a -r C:\backupDir\%folder%.zip C:\backupDir\%folder%\*.*

posted by admin in Whats New? and have No Comments

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment