• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1941
  • Last Modified:

VBScript to Backup SQL

Hello Experts,

Is it possible to create a VBscript to backup a SQL database?

Using the SQL backup in SQL Express 2008 R2 I was able to generate the following script and I would like to turn it into a VBS:

BACKUP DATABASE [db] TO  DISK = N'D:\db' WITH NOFORMAT, NOINIT,  NAME = N'db-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

Open in new window


As a final result I would like to add the VBS to Windows scheduler every 15 min. Is this a safe way to do it since my database is only 40mb, expecting it to grow maybe to 200 over the next year or two?

Lastly, I am wondering when the script creates this file, will I be able to just copy the backed up file and attach it to my development server without doing import/export?

Thanks
0
APD_Toronto
Asked:
APD_Toronto
1 Solution
 
KeldenCommented:
You can execute the task scheduler without a vbs. Just create a batch file and add the following:

set OSQL=%ProgramFiles%\Microsoft SQL Server\110\Tools\Binn\osql.exe
 "%OSQL%" -U "sa" -P "<password>" -S "." -d "master" -b -e -q "BACKUP DATABASE [db] TO  DISK = N'D:\db' WITH NOFORMAT, NOINIT,  NAME = N'db-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10"

Open in new window


you have to change the path to your osql.exe file.
-S is the instance name. use "." for no instance or ".\instancename" if you have one.
Use -E instead of -U and -P if you want to use a trusted connection.
0
 
APD_TorontoAuthor Commented:
can you please clarify?-
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now