Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on a script?

Status
Not open for further replies.

darkhat01

IS-IT--Management
Apr 13, 2006
144
US
Hi Everyone -

I need to perform a daily backup of 8 different databases files by copying the .mdb files from 8 different locations on the server and copying to a backup storage location (Backup Storage Location = c:\Program Files\database\BACKUPS).

Can some one help me on this?

I would like to use vbscript because it is fast and I can have the server schedule this process.

Thanks In Advance!

darkhat01
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
try creating a VBS file, like bkup.vbs and include the following:
Code:
function copyfile(xfile, yfile)

  Set fso = CreateObject("Scripting.FileSystemObject")
  fso.CopyFile xfile, yfile,TRUE
  set fso = Nothing

end function

then call it to copy the files in the main() part of your code

Alternately, do it as a CMD script:
Code:
src=%1
bkdir=c:\Program Files\database\BACKUPS
copy %src% %bkdir%
exit

I prefer to do server side scripting in BASH/GNU hybrid scripts. You have to do a lot of messing around to set variable names from STDOUT redirected output in CMD.

Something you may want to consider is how to do logging of your backups, often log files have the date information in the name.

Here is (a rather poor) example of a hybrid script to manuplate a date string, ultimately formatting it to be a DOS env variable"

Code:
date /t | cut -d' ' -f2 | cut -c 1,2,4,5,7,8,9,10 > %TMP%\x
FOR /F  %%v  IN (%TMP%\x) DO  set DATELOG=%%v
date /t | sed -e 's/ /_/g' > %TMP%\x
time /t | sed -e 's/ /_/g' > %TMP%\y 
FOR /F  %%v  IN (%TMP%\x) DO  set x=%%v
FOR /F  %%v  IN (%TMP%\y) DO  set y=%%v
set DATETIME=%x% %y%

date/for/set are CMD commands.
cut/sed are GNU commands
the FOR loops read the content of the temporary files and intantiate a variable in the DOS env.

one code then use the above DATETIME variable to construct a date based filename:

Code:
set LOG=%bkdir%\%DATETIME%.log

When you do your database file copy, you can use redirection in DOS to accomplish log entries:
Code:
echo DATABASE COPY %src% at time %DATETIME% >> %LOG%

Finally, you may want to do an MD5 checksum of the original and the copy, and also write that to the log:
Code:
echo CHECKSUM %src%  >>  %LOG%
md5sum %src% >>  %LOG%
echo CHECKSUM BACKUP %src%  >>  %LOG%
md5sum %bkdir%\%src% >>  %LOG%

that way you are more assured that you got a good copy of the file.

You could automate the validation:

Code:
md5sum %src% > %TMP%\x
md5sum %bkdir%\%src% > %TMP%\y

FOR /F  %%v  IN (%TMP%\x) DO  set SRCCKSUM=%%v
FOR /F  %%v  IN (%TMP%\y) DO  set BKCKSUM=%%v
if NOT %x%==%y% then GOTO ERROR01
...
:ERROR01
set ERRMSG="A BACKUP ERROR HAS OCCURED - CHECKSUM INVALID ON BACKUP"
goto MAILADMIN
...

upon which you use a mail client (like ChilKat) to send an email to the Admin that the backup failed.

Hope this helps.


John Lopez
Enterprise PDM Architect
john.l.lopez@goodrich.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top