
04-07-2007, 14:28
|
|
|
|
חבר מתאריך: 17.05.05
הודעות: 7,321
|
|
אני לא מבין הרבה ב- SQL SERVER או בכלל בהעתקה מהירה של מידע במסדי נתונים, אבל אולי הטיפים הבאים יעזרו:
http://www.databasejournal.com/feat...cle.php/3095511
עריכה:
אולי גם השאילתה הבאה תעזור לך:
קוד:
create proc usp_copy_db_backup_files
@copyd varchar(200)= null
as
/************************************************** ********************
Author: Gregory A. Larsen Date: 08/27/2003
Description: This stored procedure will copy database backups to
a secondary location for disaster recovery purpose. When
the proc runs it will copy any database backup that has
been created in the last 72 hours, provided the backup
does not already exist in the alternative directory.
************************************************** *********************/
set nocount on
declare @tmp varchar(200)
declare @cmd varchar(2000)
declare @oldcmd varchar(2000)
if @copyd is null
begin
raiserror('No copy directory provided',16,1)
Print 'Usage:usp_copy_db_backup_files @copyd=<directory for backup files>'
return
end
-- create tables to hold file lists
create table #filelist1 (output varchar(250))
create table #filelist2 (output varchar(250))
-- create temp table to hold commands to execute
create table #commands (cmd varchar(2000))
set nocount on
-- get a list of the physical device name for all backups that where
-- created in the last 72 hours.
insert into #filelist1 select physical_device_name from msdb.dbo.backupmediafamily
join msdb.dbo.backupset
on msdb.dbo.backupmediafamily.media_set_id =
msdb.dbo.backupset.media_set_id
where backup_start_date > dateadd(hour,-72,getdate())
--build dir command
set @tmp = 'dir /b ' + rtrim(@copyd) + '\*.*'
--get a list of the backup file that exist at alternative location
insert into #filelist2 exec master.dbo.xp_cmdshell @tmp
-- generate a copy command for all backup
-- files that have yet to be copied.
insert into #commands select
'copy "' + rtrim(#filelist1.output) + '" ' + rtrim(@copyd)
from #filelist1 left join #filelist2
on
reverse(substring(reverse(#filelist1.output),1,
charindex('\',reverse(#filelist1.output))-1))
=
#filelist2.output
where #filelist2.output is null
--are there backups that need to be copied
if (select count(*) from #commands) > 0
begin
-- loop throught the commands and copy one file a time.
set @oldcmd = ''
select top 1 @cmd = cmd from #commands order by cmd
while @cmd <> @oldcmd
begin
-- copy backup to other location
print @cmd
exec master.dbo.xp_cmdshell @cmd
set @oldcmd=@cmd
-- get next command to process
select top 1 @cmd = cmd from #commands where @oldcmd < cmd order by cmd
end
end
-- remove temporary files used.
drop table #filelist1, #filelist2, #commands
היא נלקחה מהעמוד:
http://www.databasejournal.com/feat...cle.php/3628501
נערך לאחרונה ע"י DCD בתאריך 04-07-2007 בשעה 14:37.
|