Hi everyone
I have a server sql 2008 r2 std in which there are two databases: 006 for production and 007 for testing, what I need to do is update the test base daily and automatically with the information of the production database, every day a maintenance plan is executed that makes a backup of the production bd, my question is if I can make another maintenance plan that restores the bd 007 with this backup file
is this possible?
This is what I use in my case
I have a table that defines the databases I want to restore
CREATE TABLE [dbo].[DatabaseRestore](
[id] [int] IDENTITY(1,1) NOT NULL,
[DatabaseName] [varchar](50) NOT NULL,
[ActiveFlag] [bit] NOT NULL
) ON [PRIMARY]
GO
ALTER proc [dbo].[restoredatabase_sp]
as
begin
--database_you_want_to_restore
if exists (select 1 from dbo.DatabaseRestore where databasename = 'database_you_want_to_restore' and activeFlag = 1)
begin
EXEC DBAdmin.dbo.vrKillSPIDS 'database_you_want_to_restore';
alter database database_you_want_to_restore set RESTRICTED_USER with rollback immediate;
RESTORE DATABASE database_you_want_to_restore FROM DISK = N'D:\RestoreDB\PRODBACKUPS\database_you_want_to_restore.bak' WITH FILE = 1,
MOVE N'database_you_want_to_restore' TO N'D:\DATA\database_you_want_to_restore.mdf',
MOVE N'database_you_want_to_restore_log' TO N'D:\LOGS\database_you_want_to_restore.ldf', NOUNLOAD, REPLACE, STATS = 10
alter database database_you_want_to_restore set multi_user with rollback immediate;
end
and then add this to a SQL Job and schedule it. There could be other better ways but this is what I do.