public ArrayList GetBackupSetPhysicalSources(int backupsetId) { SqlExecutionModes executionMode = this.sqlConnection.SqlExecutionModes; this.sqlConnection.SqlExecutionModes = SqlExecutionModes.ExecuteSql; ArrayList sources = new ArrayList(); DataSet backupSet = GetBackupSetById(backupsetId); if (backupSet.Tables[0].Rows.Count == 1) { string mediaSetID = Convert.ToString(backupSet.Tables[0].Rows[0]["MediaSetId"], System.Globalization.CultureInfo.InvariantCulture); Enumerator en = new Enumerator(); Request req = new Request(); DataSet mediafamily = new DataSet(); mediafamily.Locale = System.Globalization.CultureInfo.InvariantCulture; req.Urn = "Server/BackupMediaSet[@ID='" + Urn.EscapeString(mediaSetID) + "']/MediaFamily"; mediafamily = en.Process(this.sqlConnection, req); if (mediafamily.Tables[0].Rows.Count > 0) { for (int j = 0; j < mediafamily.Tables[0].Rows.Count; j++) { RestoreItemSource itemSource = new RestoreItemSource(); itemSource.RestoreItemLocation = Convert.ToString(mediafamily.Tables[0].Rows[j]["PhysicalDeviceName"], System.Globalization.CultureInfo.InvariantCulture); BackupDeviceType backupDeviceType = (BackupDeviceType)Enum.Parse(typeof(BackupDeviceType), mediafamily.Tables[0].Rows[j]["BackupDeviceType"].ToString()); if (BackupDeviceType.Disk == backupDeviceType) { itemSource.RestoreItemDeviceType = DeviceType.File; } else if (BackupDeviceType.Url == backupDeviceType) { itemSource.RestoreItemDeviceType = DeviceType.Url; } else { itemSource.RestoreItemDeviceType = DeviceType.Tape; } sources.Add(itemSource); } } } this.sqlConnection.SqlExecutionModes = executionMode; return(sources); }
public List <RestoreItemSource> GetLatestBackupLocations(string databaseName) { List <RestoreItemSource> latestLocations = new List <RestoreItemSource>(); Enumerator en = null; DataSet ds = new DataSet(); ds.Locale = System.Globalization.CultureInfo.InvariantCulture; Request req = new Request(); en = new Enumerator(); req.Urn = "Server/BackupSet[@DatabaseName='" + Urn.EscapeString(databaseName) + "']"; req.OrderByList = new OrderBy[1]; req.OrderByList[0] = new OrderBy(); req.OrderByList[0].Field = "BackupFinishDate"; req.OrderByList[0].Dir = OrderBy.Direction.Desc; try { ds = en.Process(this.sqlConnection, req); if (ds.Tables[0].Rows.Count > 0) { string mediaSetID = Convert.ToString(ds.Tables[0].Rows[0]["MediaSetId"], System.Globalization.CultureInfo.InvariantCulture); ds.Clear(); req = new Request(); req.Urn = "Server/BackupMediaSet[@ID='" + Urn.EscapeString(mediaSetID) + "']/MediaFamily"; ds = en.Process(this.sqlConnection, req); int count = ds.Tables[0].Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { RestoreItemSource restoreItemSource = new RestoreItemSource(); DeviceType deviceType = (DeviceType)(Convert.ToInt16(ds.Tables[0].Rows[i]["BackupDeviceType"], System.Globalization.CultureInfo.InvariantCulture)); string location = Convert.ToString(ds.Tables[0].Rows[i]["LogicalDeviceName"], System.Globalization.CultureInfo.InvariantCulture); bool isLogical = (location.Length > 0); if (false == isLogical) { location = Convert.ToString(ds.Tables[0].Rows[i]["PhysicalDeviceName"], System.Globalization.CultureInfo.InvariantCulture); } else { // We might receive the logical name as "logicaldevicename(physicalpath)" // We try to get the device name out of it int pos = location.IndexOf('('); if (pos > 0) { location = location.Substring(0, pos); } } restoreItemSource.RestoreItemDeviceType = deviceType; restoreItemSource.RestoreItemLocation = location; restoreItemSource.IsLogicalDevice = isLogical; latestLocations.Add(restoreItemSource); } } } } /// LPU doesn't have rights to enumerate msdb.backupset catch (Exception) { } return(latestLocations); }