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 all DBs to the different server

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2006-10-19 : 11:19:48
How can i back up all the DBs in one server to another server?

I have DBs in test and I would like to back up all of DBs in the Test server to another server ( \\ test1\E$\Backup)?

can you show me how to do this thru EM or a script ?



jung1975
Aged Yak Warrior

503 Posts

Posted - 2006-10-19 : 11:20:15
I am using SQL Server 2005


Go to Top of Page

dewacorp.alliances

452 Posts

Posted - 2006-10-19 : 11:38:39
Can you just do the database shipping each individual database by going to full backup, copy files to different servers and restore?

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-19 : 13:21:40
In the FROM DISK portion of the BACKUP DATABASE command, you can use a UNC path. You could also do as valdyv says but it would require more steps.

Tara Kizer
Go to Top of Page

TonyTheDBA
Posting Yak Master

121 Posts

Posted - 2006-10-20 : 06:11:34
I have a couple of stored procedures (only on SQL 2K here so not looked at the alternativesin SQL2K5) that copy the backup files (Database and tran logs) to the other server. Basically they use the xp_cmdShell extended SP, and as the format of the files are known you can do a DIR for them, if they are there, then you copy them . . . . I also delete the old ones from teh destination server as well :)

Another method I use with a Smaller DB is to have a scheduled job that detach the DB on each server, and copy the mdf file from the source server (again using xp_cmdshell) to the destination servers. then attach the DB on all the relevant servers. I then drop and grant the requisite permissions on the database on each of the destination Servers.

I must admit though using the UNC path in the command such as
BACKUP DATABASE Pubs TO DISK = '\\BACKUPSERVER\BACKUPSHARE$\Pubs_db_YYYYMMDDHHNN.BAK' WITH INIT
Is a very neat and simple way of doing it


--
Regards
Tony The DBA
Go to Top of Page

jung1975
Aged Yak Warrior

503 Posts

Posted - 2006-10-20 : 11:18:07
quote:
Originally posted by TonyTheDBA

I have a couple of stored procedures (only on SQL 2K here so not looked at the alternativesin SQL2K5) that copy the backup files (Database and tran logs) to the other server. [/code]Is a very neat and simple way of doing it

Regards
Tony The DBA



Can you show me your stored procedure?

thansk


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-20 : 12:40:50

http://www.mindsdoor.net/SQLAdmin/BackupAllDatabases.html

Madhivanan

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

TonyTheDBA
Posting Yak Master

121 Posts

Posted - 2006-10-23 : 07:44:06
USE BBCAdmin
GO

IF EXISTS(SELECT 1 FROM sysobjects WHERE name = 'sys_CopyBackupFile')
DROP PROCEDURE dbo.sys_CopyBackupFile
go

CREATE PROCEDURE dbo.sys_CopyBackupFile ( @Time DateTime
, @BackupDirectory Varchar(255)
, @BackupFileName Varchar(255)
, @DestinationDir Varchar(255)
, @Debug tinyint = 0 ) AS
BEGIN

/****************************************************************************
Procedure Name : sys_CopyBackupFile
Procedure Desc : Copies Backup File to another Location even to another
: Server using the UNC naming Convention
Parameters : @Time - Time Backup Was Taken Needed for filename
: @BackupDirectory - Where You Copy the File From
: @BackupFileName - The Bit before the dateTime probably Db
: name + '_db_'
: @DestinationDir - Where it needs to go
: @debug - display debug info
Returns : 0 If Execution Completed Without Errors
: 1 If Execution Failed Due To Errors
Date Created : DD-MMM-2005
Author : <Your Name Here> - BBC
Last Amended : DD-MMM-CCYY : :
****************************************************************************/

DECLARE @ProcName varchar(32)
DECLARE @UserId varchar(32)
Declare @BackupFile Varchar(255)
, @Cmd Varchar(1024)
, @Result Integer

SET NOCOUNT ON

SELECT @ProcName = 'sys_CopyBackupFile'
IF @UserId = Null SELECT @UserId = SUSER_SNAME ( SUSER_SID ( ) )

select @UserId = system_User

If @Debug = 1 Print @ProcName + ' is Executing as User : ' + SUSER_SNAME()
+ ' On ' + Convert(Varchar(11), @Time , 106)
+ ' At ' + Convert(Varchar(13), @Time , 114)
If @Debug = 1 Print ''

-- The Backup File Has the format Of FileRoot + Year + Month + Day + Hour + Min Of Backup

SELECT @BackupFile = @BackupFileName
+ Convert ( Varchar(4) , year ( @Time ) )
+ RIGHT ( '00' + Convert ( Varchar(2) , Month ( @Time ) ) , 2 )
+ RIGHT ( '00' + Convert ( Varchar(2) , Day ( @Time ) ) , 2 )
+ RIGHT ( '00' + Convert ( Varchar(2) , DatePart (hh , @Time ) ) , 2 )
+ '*.BAK'

SELECT @Cmd = 'XCOPY ' + @BackupDirectory + @BackupFile + ' ' + @DestinationDir

Print 'Backup File Name : ' + @BackupFile
Print 'Command To Execute : ' + @Cmd
Print ''

EXECUTE @Result = master.dbo.xp_cmdshell @Cmd , no_output

If @Result != 0 RETURN @Result

-- Well Thats Copied The file Now delete the file from The Backup
-- Directory From Yesterday at the same time

SELECT @Time = DateAdd ( dd , -1 , @Time )

SELECT @BackupFile = @BackupFileName
+ Convert ( Varchar(4) , year ( @Time ) )
+ RIGHT ( '00' + Convert ( Varchar(2) , Month ( @Time ) ) , 2 )
+ RIGHT ( '00' + Convert ( Varchar(2) , Day ( @Time ) ) , 2 )
+ RIGHT ( '00' + Convert ( Varchar(2) , DatePart (hh , @Time ) ) , 2 )
+ '*.BAK'

SELECT @Cmd = 'DEL ' + @DestinationDir + @BackupFile

If @Debug = 1 Print 'Command To Execute : ' + @Cmd
If @Debug = 1 Print ''

EXECUTE @Result = master.dbo.xp_cmdshell @Cmd , no_output

IF @Result = 0 RETURN 0 ELSE RETURN 1

END /******* END OF PROCEDURE sys_CopyBackupFile ***************/

GO

IF EXISTS ( SELECT 1 FROM sysobjects WHERE name = 'sys_CopyBackupFile')
GRANT EXECUTE ON dbo.sys_CopyBackupFile TO <user_role , ,sysadmin>
go
Now its clear that the error checking here isn't sufficient but it should be obvious what its doing. I call this from a job step which has the following
Declare @BackupDate DateTime
Declare @BackupName Varchar (512)

Set @BackupDate = GetDate ( )
SET @BackupName = 'T:\Backups\Pubs' + '_db_'
+ CONVERT ( Varchar (8) , @BackupTime , 112)
+ RIGHT ( '00' + CONVERT ( Varchar (2) , DatePart ( hour , @BackupTime ) ) , 2 )
+ RIGHT ( '00' + CONVERT ( Varchar (2) , DatePart ( minute , @BackupTime ) ) , 2 )
+ '.BAK'

BACKUP DATABASE Pubs TO DISK = @BackupName WITH INIT
Execute BBCAdmin.dbo.sys_CopyBackupFile @BackupDate , 'T:\Backups' , 'Pubs_db_' , '\\test1\E$\Backup'


Note that I don't actually do it quite this way as I took over from some suppliers who had set up some DB maintenance plans hence the reason for using the File names format. Although it is a relativly good format and for my Backup SP's elswhere I have used the same convention.

Hope this helps

--
Regards
Tony The DBA
Go to Top of Page
   

- Advertisement -