This article talks about how to create database backups and check in SQL-DMO.
============================================================================================================================================================================================================= ==========
Overview SQL Distributed Management Objects (SQL-DMO) provides developers with a method of performing normal tasks using programs and scripting languages, thereby expanding SQL Server features. This article talks about how to create database backups and check in SQL-DMO.
Prerequisites you need to have relevant knowledge of SQL Server database backup. Also add references to the SQL-DMO library in the global.asa file. The following is a reference to SQL Server 2000:
This example code applies to SQL 7.0, MSDE, and SQL Server 2000.
Hi and worry use SQL-DMO objects and worry. It provides a very rich function that I don't know how to use it. This article only discusses the object properties and methods involved in the example. You can find a lot of information in SQL Server online teaching. This article can be downloaded at the end of this paper.
SqldMo.sqlserver code looks very familiar. It is used to connect SQL Server databases: <% DIM SRV SET SRV = Server.createObject ("SqldMo.sqlServer") srv.logintimeout = 15 srv.connect "Servername", "UserName", "Password"%>
Here, connect the SQL Server database by giving the username and password. If you want to use NT authentication, set its loginsecure property to true (TRUE), ignore the amount of username and password, and use NT's registration information.
SqldMo.database lists the databases in the server. In this example, the listed database is backed up. The following code lists the database in the server to the drop-down menu: <% DIM SRV DIM OBJDB SET SRV = Server.createObject ("SqldMo.sql Server") srv.logintimeout = 15 srv.connect "ServerName", "UserName", "Password "Set objdb = server.createObject (" sqldmo.database ")%>
<% For each objdb.systemObject = false then%>
SqldMo.Backup This is the backup core object we have to use. It has many properties that let us make a backup of the same level as the Enterprise SQL Manager. First discuss the properties used in this article.
BackupsetName - Backup file name. Database - the database to be backed up. Action - all or incremental backups. There are other options, but only these two are used in the example. BackupsetDescription - Backup Description. FILES - File Backup Options. To indicate the path and name of the backup file, such as: C: /Pubs.bak. When using a file backup, the following backup device name is set to be empty. DEVICES - Backup device on the server. If you use a backup device, the above file backup option is set to be empty. TruncateLog - Backup Log Options. The options are: NOLOG - does not back up the transaction log. NOTRUNCATE - Backup trading log. Time markers are available in the log. Truncate - Backup transaction log, but does not retain the transaction record. Initialize - If true (TRUE), the backup device will replace other backup media to be preferred.
The following is a Backup.asp file in the example:
<% @Language = VBScript%>
<% DIM OBJBACKUP 'Creating Backup Object Set Obckupup = Server.CreateObject ( "SQLDMO.Backup") 'set properties objBackup.BackupSetName = Request ( "fname") objBackup.Database = Request ( "fdatabase") objBackup.Action = Request ( "fAction") objBackup.BackupSetDescription = Request ( "fdescription") objBackup.Files = Request ( "fbackupfile") objBackup.Devices = Request ( "fdevice") objBackup.TruncateLog = Request ( "flog") objBackup.Initialize = Request ( "finit") 'backup database objBackup.SQLBackup SRV 'Disconnects with the server SRV.Disconnect' Release SET SRV = Nothing set objBackup = Noth%>The backup WAS Started, use the the Verify Option TO See if it completed successful. click here to return. p> body> html> Backup check If you can use VB or C , you can use events. Try to check the backup process, but not in the ASP. We confirm that the backup is successful with the ReadBackupHeader method of the SqldMo.backupDevice object. Below is a Verify.asp file code, which lists the backup device name and provides information about the most recent backed up.
<% @Language = VBScript%>
<% DIM ObjDevice Dim Objresults Dim iCount Dim xcount 'Creating a backup device object set objDevice = server.createObject ("SqldMo.backupDevice")' Cycle until the matching device for Each ObjDevice in srv.backupdevices if ObjDevice.Name = Request ("fname") TEN 'found matching device, start reading result Set objResults = objDevice.ReadBackupHeader For iCount = 1 To objResults.Rows For xCount = 1 To objResults.Columns%> <% = objResults.ColumnName (xcount)%> B>: <% = objResults .Getcolumnstring (iCount, Xcount)%>
<% next%>
<% next%> <% end if%> <% next%> <% srv.disconnect set srv = Nothing set objDevice = Nothing set Objresults = NOTHING%> body> html> ReadbackupHeader method Returns the QueryResults object. Use their ROWS attribute to get a record number of backups. Then search for each line record.
Other features SQL-DMO also provide remote backup and recovery. This article does not involve database recovery, but SQL-DMO has a strong recovery function.
Annex:
Http://www.chinaok.net/down/200204250401420.zip