A VBScript to generate a backup file of a MS SQL database
NOTE: By default the script uses the user executing the script to authenticate to the DB server. If you want to authenticate to the DB server using SQL Server Authentication set the options
DBUserandDBPass(Line 47 & 48)
- Edit
mssql_backup.vbs - Set the required options (Line 32-34)
const ServerName = "[name of ms sql server]\[name of sql service]"
const BackupDir = "[folder path]"
const DBName = "[db name]"- Execute
mssql_backup.vbsto generate backup
- Place the
start_backup.batfile into the same directory as themssql_backup.vbsscript - Edit
start_backup.batand make sure the filename defined is the same as the VBScript's filename (Line 2)
SET fileName= [filename]- Open Windows Task Scheduler
- Create a new task that executes the batch file with the corresponding user for the DB
NOTE: The user that executes the backup script doesn't matter if you plan to use SQL Server Authentication
- Set the
CopyOnCompleteBooltotrue(Line 36) - Set the path of the folder to copy the backup into to the variable (Line 37)
const CopyOnCompleteBool = [true|false]
const CopyOnCompleteDir = "D:\bar"- Execute
mssql_backup.vbs
- Set the
MoveOnCompleteBoolvariable totrue(Line 39) - Set the path of the folder to copy the backup into to the variable
MoveOnCompleteDir(Line 40)
const MoveOnCompleteBool = [true|false]
const MoveOnCompleteDir = "D:\bar"- Execute
mssql_backup.vbs
NOTE: If both
CopyOnCompleteBoolandMoveOnCompleteBoolare set to true, the script will make a copy of the .BAK file first and then move it to the desired location.