Good day,
first of all, I'm still doing my first steps on Scripting and for this reason I apologize for any basic question.
I have the following script to Backup some SQL Databases. As I'm going to use this script in several computers I need to change that
3 first variables depending on which computer I will execute it.
The first 2 Variables are running nice but the third one is generating errors. I have already tried to use "" but nothing helped me.
Thank you in advance for you cooperation.
serverName = "SERVER\NTSQL2014"
backupDirectory = "D:\NTBckps\DBS\"
[highlight #EF2929]excludeDBS[/highlight] = rs("name") <> "tempdb" and rs("name") <> "NDatabase15"
Set objShell = wscript.createObject("wscript.shell")
if serverName = "" then wscript.quit
if backupdirectory = "" then wscript.quit
if not mid(backupDirectory,len(backupDirectory),1)="\" then
backupDirectory = backupDirectory & "\"
end if
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
set rs = createobject("ADODB.RecordSet")
cn.open "Provider=SQLOLEDB.1;Data Source=" & serverName & ";Integrated Security=SSPI;Initial Catalog=Master"
cmd.activeconnection = cn
cmd.commandtext = "exec sp_helpdb"
set rs = cmd.execute
while rs.eof <> true and rs.bof <> true
if rs("name") <> "tempdb" and rs("name") <> "NDatabase15" Then
'---> I would like to replace with someting like this: If excludeDBS Then <---'
backupDatabase rs("name")
end
if rs.movenext
wend
cn.close
wscript.echo "Backup Complete"
sub backupDatabase(byval databaseName)
fileName = backupDirectory & "NT_" & replace(replace(now,"/","_"),":","_") & "_" & databaseName & ".bak"
set cmdbackup = createobject("ADODB.Command")
cmdbackup.activeconnection = cn
cmdbackup.commandtext = "backup database " & databaseName & " to disk='" & fileName & "'"
cmdbackup.execute
end sub
Thank you in advance for your cooperation
first of all, I'm still doing my first steps on Scripting and for this reason I apologize for any basic question.
I have the following script to Backup some SQL Databases. As I'm going to use this script in several computers I need to change that
3 first variables depending on which computer I will execute it.
The first 2 Variables are running nice but the third one is generating errors. I have already tried to use "" but nothing helped me.
Thank you in advance for you cooperation.
serverName = "SERVER\NTSQL2014"
backupDirectory = "D:\NTBckps\DBS\"
[highlight #EF2929]excludeDBS[/highlight] = rs("name") <> "tempdb" and rs("name") <> "NDatabase15"
Set objShell = wscript.createObject("wscript.shell")
if serverName = "" then wscript.quit
if backupdirectory = "" then wscript.quit
if not mid(backupDirectory,len(backupDirectory),1)="\" then
backupDirectory = backupDirectory & "\"
end if
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
set rs = createobject("ADODB.RecordSet")
cn.open "Provider=SQLOLEDB.1;Data Source=" & serverName & ";Integrated Security=SSPI;Initial Catalog=Master"
cmd.activeconnection = cn
cmd.commandtext = "exec sp_helpdb"
set rs = cmd.execute
while rs.eof <> true and rs.bof <> true
if rs("name") <> "tempdb" and rs("name") <> "NDatabase15" Then
'---> I would like to replace with someting like this: If excludeDBS Then <---'
backupDatabase rs("name")
end
if rs.movenext
wend
cn.close
wscript.echo "Backup Complete"
sub backupDatabase(byval databaseName)
fileName = backupDirectory & "NT_" & replace(replace(now,"/","_"),":","_") & "_" & databaseName & ".bak"
set cmdbackup = createobject("ADODB.Command")
cmdbackup.activeconnection = cn
cmdbackup.commandtext = "backup database " & databaseName & " to disk='" & fileName & "'"
cmdbackup.execute
end sub
Thank you in advance for your cooperation