Solved

VBScript to Backup SQL

Posted on 2012-03-22
2
1,788 Views
Last Modified: 2012-03-23
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
Comment
Question by:APD_Toronto
2 Comments
 
LVL 2

Accepted Solution

by:
Kelden earned 500 total points
ID: 37755119
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
 

Author Comment

by:APD_Toronto
ID: 37755209
can you please clarify?-
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question