Backing Up A Database
Create a stored procedure mydbackup as
BACKUP mydb to DISK='c:\mtdb.bak'
In SQLDMO, an example:
Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.Connect "servername", "username", "password"
Set bak = Server.CreateObject("SQLDMO.Backup")
bak.Database="Northwind"
bak.Devices=Files
bak.Files="e:\nwind.bak"
bak.SQLBackup srv
Response.write "DONE!"
Restoring A Database
In a stored procedure:
RESTORE DATABASE Northwind FROM DISK='c:\nwind.bak' [WITH ]
In SQLDMO you use the restore object (check BOL for full syntax):
Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.Connect "servername", "username", "password"
Set rest=Server.CreateObject("SQLDMO.Restore")
rest.Action=0 ' full db restore
rest.Database="Northwind"
rest.Devices=Files
rest.Files="c:\nwind.bak"
rest.ReplaceDatabase=True 'Force restore over existing database
rest.SQLRestore srv
response.write "Done!"
set rest=nothing
set srv=nothing
More details can be found in BOL (has the SQLDMO object model) and there's an
article here http://www.asp101.com/articles/carvin/sqldmobackup/default.asp.
Submitted by Jasper Smith on the ASP e-mail discussion list.