Page 1 of 1 1
Topic Options
#111094 - 2003-12-31 03:12 PM MSSQL Database Backup Script
Chaguito Offline
Getting the hang of it

Registered: 2002-05-17
Posts: 53
Inputs are welcome....Enyoy

Code:
;*************************************************************************
; Script Name: SQL Database Backup
; Author: Antonio Santiago
; Date: 18-Dec-03
; Descritption: This script will make backups of the Delta V SQL databases
; and compress them for easy storage.
;*************************************************************************

;Declaring Variables

GLOBAL $DATABASE

DIM $SQLMAINT, $SERVER, $USERNAME, $PASSWORD, $BACKUPDIR, $BACKUPMEDIA
DIM $EXPORT, $WINRAR


;Defining Variables

$SQLMAINT="d:\mssql2k\mssql\binn\sqlmaint.exe"
$SERVER="localhost"
$USERNAME="sa"
$PASSWORD=""
$BACKUPDIR="e:\DeltaV_Backup"
$BACKUPMEDIA="DISK"


;Verify that script is executed on the $PROPLUS
:PROPLUS
IF @WKSTA=$PROPLUS or @WKSTA=$HISTORIAN
GOTO DIRECTORY
ELSE
MESSAGEBOX("Sorry, this script can only be executed in the PROPLUS or HISTORIAN computer.","Script Error!!!",16,0)
goto End
ENDIF


:DIRECTORY
;Making Backup Folder

MD $BACKUPDIR


;Exporting Database

$EXPORT=$SQLMAINT+" -S "+$SERVER+" -U "+$USERNAME+" -P "+$PASSWORD+" -D "+$DATABASE+" -BkUpDB "+$BACKUPDIR+" -BkUpMedia "+$BACKUPMEDIA

SHELL "%COMSPEC% /C "+$EXPORT


;Compresing Database - Winrar (www.rarlabs.com) required
; -m5 = High Compresion
; -df = Delete files after archiving
; -ibck = run in the background
; -r = recurse subfolders
; -x = Exclude files

$WINRAR="c:\progra~1\winrar\winrar a -m5 -r -df -ibck -x*.zip"

SHELL "%COMSPEC% /C "+$WINRAR+" "+$BACKUPDIR+"\"+$DATABASE+"_"+@MDAYNO+@MONTH+@YEAR+".zip"+" "+$BACKUPDIR+"\*.bak"


:END
;END OF SCRIPT

_________________________
Chaguito, MCP

Top
#111095 - 2004-01-02 02:53 AM Re: MSSQL Database Backup Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Never, ever use GOTOs in scripts.

An 'sa' admin account with empty password is a huge security risk!

Why not run the backups directly from within SQL Server Enterprise Manager as a scheduled maintenance task?
_________________________
There are two types of vessels, submarines and targets.

Top
#111096 - 2004-01-02 03:07 PM Re: MSSQL Database Backup Script
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I agree with Jens..

If we go over to SQLTeam.. We see a pretty good script example -
Database Backup Script

Also - here is the search string too:
http://www.sqlteam.com/searchresults.asp?SearchTerms=backup

HTH,

Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#111097 - 2004-01-07 06:08 PM Re: MSSQL Database Backup Script
Chaguito Offline
Getting the hang of it

Registered: 2002-05-17
Posts: 53
Quote:

Never, ever use GOTOs in scripts.

An 'sa' admin account with empty password is a huge security risk!

Why not run the backups directly from within SQL Server Enterprise Manager as a scheduled maintenance task?




I used the GOTO command to filter by wksta but the condition can be eliminated.

And YES the 'SA' has a password(it's not typed in)

I didn't use the enterprise manager to do the backups because it's only a part of a multilevel script, and at the end it compresses the database using winrar (just saving some tape space).


Thanks for the advice...


Edited by Chaguito (2004-01-07 06:14 PM)
_________________________
Chaguito, MCP

Top
#111098 - 2004-01-07 06:22 PM Re: MSSQL Database Backup Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If the tape drive supports hardware compression, then you should not use software compression to reduce the initilsa filesizes as this will reduce the effectiveness of the hardware compression and most likely use even more space. See for example http://www.fujifilmmediasource.com/specs/new/misc/compression00.pdf
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.051 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org