Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Backup and Restore

Author  Topic 

jpotucek
Constraint Violating Yak Guru

273 Posts

Posted - 2005-11-08 : 11:52:08

I love Tara's Stored Procedure for Backups:

http://weblogs.sqlteam.com/tarad/archive/2004/06/16/1607.aspx

I'm just trying to figure out how I could incorporate this into a DR plan.

If I copy Backups made with this SP to another Server (something like a standby Server), How would I restore these Backups to this 2nd Server given that the BACKUP NAMES ARE NEVER THE SAME??

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-08 : 12:00:38
see
http://www.mindsdoor.net/SQLAdmin/LogShipping.html
goes with
http://www.mindsdoor.net/SQLAdmin/BackupAllDatabases.html

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jpotucek
Constraint Violating Yak Guru

273 Posts

Posted - 2005-11-08 : 14:50:25
not sure if I understand. I don't have enterprise edition.. don't I need enterprise edition to do log shipping?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-11-08 : 15:19:31
I actually have a brand new restore stored procedure that I haven't yet posted to my weblog:



SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

----------------------------------------------------------------------------------------------------
-- OBJECT NAME : isp_Restore
-- AUTHOR : Tara Duggan
-- DATE : November 3, 2005
-- INPUTS : @dbName - name to use for the restored database
-- @bkpDir - full path to the directory where the BAK files exist
-- @newDataLocation - new location and file name for the MDF, can be NULL
-- @newLogLocation - new location and file name for the LDF, can be NULL
-- OUTPUTS : None
-- RETURN CODES : 0 - success
-- 1 - invalid path
-- 2 - no BAK files exist in @bkpDir
-- 3 - backup contains more than 2 D files which isn't supported by this sproc
-- 4 - restore error
-- DEPENDENCIES : None
-- DESCRIPTION : This stored procedure performs a restore of the newest BAK file in a specified directory.
-- EXAMPLES (optional) :
/*
DECLARE @rc tinyint
EXEC @rc = dbo.isp_Restore @dbName = 'SomeDB', @bkpDir = 'H:\MSSQL\BACKUP\SomeDB\, @newDataLocation = 'F:\MSSQL\DATA\SomeDB_Data.MDF', @newLogLocation = 'G:\MSSQL\DATA\SomeDB_Log.LDF'
PRINT @rc
*/
----------------------------------------------------------------------------------------------------
ALTER PROC dbo.isp_Restore
(@dbName sysname, @bkpDir nvarchar(1000), @newDataLocation nvarchar(1000), @newLogLocation nvarchar(1000))
AS

SET NOCOUNT ON

DECLARE @cmd sysname, @bkpFile nvarchar(1000), @sql nvarchar(4000), @logicalDataName nvarchar(128), @logicalLogName nvarchar(128)

-- Add a backslash to the end of the path if one doesn't exist
IF REVERSE(SUBSTRING(@bkpDir, 1, 1)) <> '\'
SET @bkpDir = @bkpDir + '\'

-- Get files sorted by date
SET @cmd = 'dir ' + @bkpDir + '*.BAK /OD'

CREATE TABLE #Dir(DirInfo VARCHAR(7000)) -- Stores the dir results
CREATE TABLE #BackupFiles(BackupDate varchar(10), BackupFileName nvarchar(1000)) -- Stores only the data we want from the dir

INSERT INTO #Dir
EXEC master.dbo.xp_cmdshell @cmd

IF EXISTS (SELECT * FROM #Dir WHERE DirInfo = 'The system cannot find the path specified.')
RETURN 1

INSERT INTO #BackupFiles
SELECT SUBSTRING(DirInfo, 1, 10), SUBSTRING(DirInfo, LEN(DirInfo) - PATINDEX('% %', REVERSE(DirInfo)) + 2, LEN(DirInfo))
FROM #Dir
WHERE ISDATE(SUBSTRING(DirInfo, 1, 10)) = 1 AND DirInfo NOT LIKE '%<DIR>%'

IF @@ROWCOUNT = 0
RETURN 2

-- Get the newest file
SELECT TOP 1 @bkpFile = BackupFileName
FROM #BackupFiles
ORDER BY BackupDate DESC

DROP TABLE #Dir, #BackupFiles

SET @cmd = @bkpDir + @bkpFile

-- Stores RESTORE FILELISTONLY result set
CREATE TABLE #RestoreFileListOnly
(
LogicalName nvarchar(128),
PhysicalName nvarchar(260),
Type char(1),
FileGroupName nvarchar(128),
[Size] numeric(20,0),
[MaxSize] numeric(20,0)
)

INSERT INTO #RestoreFileListOnly
EXEC('RESTORE FILELISTONLY FROM DISK = ''' + @cmd + '''')

IF @@ROWCOUNT <> 2
RETURN 3

SELECT @logicalDataName = LogicalName
FROM #RestoreFileListOnly
WHERE Type = 'D'

SELECT @logicalLogName = LogicalName
FROM #RestoreFileListOnly
WHERE Type = 'L'

DROP TABLE #RestoreFileListOnly

SET @sql = ''
SET @sql = @sql + 'RESTORE DATABASE ' + @dbName + CHAR(10)
SET @sql = @sql + 'FROM DISK = ''' + @cmd + '''' + CHAR(10)
SET @sql = @sql + 'WITH' + CHAR(10)
SET @sql = @sql + CHAR(9) + 'REPLACE'

IF @newDataLocation IS NOT NULL
BEGIN
SET @sql = @sql + ',' + CHAR(10)
SET @sql = @sql + CHAR(9) + 'MOVE ''' + @logicalDataName + ''' TO ''' + @newDataLocation + ''''
END

IF @newLogLocation IS NOT NULL
BEGIN
SET @sql = @sql + ',' + CHAR(10)
SET @sql = @sql + CHAR(9) + 'MOVE ''' + @logicalLogName + ''' TO ''' + @newLogLocation + ''''
END

PRINT @sql
EXEC(@sql)

IF @@ERROR <> 0
RETURN 4
ELSE
RETURN 0


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



Check out the header section for the details of it.

Tara Kizer
Go to Top of Page

jpotucek
Constraint Violating Yak Guru

273 Posts

Posted - 2005-11-08 : 15:39:43
Thanks Tara!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-11-08 : 18:35:32
My weblog has been updated:
http://weblogs.sqlteam.com/tarad/archive/2005/11/08/8262.aspx
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx

Tara Kizer
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-09 : 01:03:45
Refer this also
http://www.mindsdoor.net/SQLAdmin/s_RestoreLatestBackup.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-11-09 : 03:09:17
nice script Tara.



-ec
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-09 : 06:33:30
quote:
Originally posted by jpotucek

not sure if I understand. I don't have enterprise edition.. don't I need enterprise edition to do log shipping?



Nope - the links I gave do it all in stored procedures. Any database that can take full and log backups will work.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -