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
 General SQL Server Forums
 New to SQL Server Programming
 Database backup from a remote server

Author  Topic 

vivekjain43
Starting Member

8 Posts

Posted - 2006-11-06 : 09:01:51
Hi,
I have a database on a remote server, and want to take a back up of that to my local system. My objective is to take the back up of the db, and then restore it to another SQL Server. Can anyone please help me with this.

Thanks

Vivek

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-06 : 09:28:13
Look for "Backup / Restore / Replication / Jobs / Houskeeping" in this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210


KH

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-11-06 : 09:29:28
You should start by reading about Backup and Restore in SQL Server Books Online.





CODO ERGO SUM
Go to Top of Page

vivekjain43
Starting Member

8 Posts

Posted - 2006-11-06 : 10:01:19
Thanks for your replies.
I am in a great hurry to fix this up, can you please guide me with this.

I did look into the links, but not getting the answers.

THanks
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-11-06 : 10:32:34
I dont know it can be taken via EM but try out this command.

Backup database DatabaseName
To Disk = '\\YourComputer\Shared\DatabaseName.Bak'
With Init




Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-11-06 : 10:39:17
Have a look at this sp

Use Pubs

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Backup_Database]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Backup_Database]
GO



/*
Procedure Name : Backup_Database
Parameters : 1) @dbName varchar(100) Database name for which the backup has to be done.
: 2) @Path Path where the file database backup has to be stored.

Functonality : Take the backup of the specified database at the specified location.

*/

Create Procedure Backup_Database
(
@dbName varchar(100) = '',
@Path varchar(200) = '' OUTPUT
)
As
Begin
Declare @Now varchar(100),
@DefaultPath Varchar(100),
@Qry Varchar(100)

-- if no database name is specified then take the backup of the current database
if Isnull(@dbName,'') = ''
Select @dbName = db_Name()
Else If Not Exists (Select * From Master..Sysdatabases Where [name] = @dbName)
Begin
RaisError('Could Not located Specified Database in Sysdatabases, Please Check the Database Name!!',16,1)
return
End
-- if the path is null or blank then create the dir called backups where the mdf files exists and
-- make the backup over there :-)
if isnull(@path,'') = ''
Begin
Select @DefaultPath = Left(FileName,len(FileName) - CharIndex('\',reverse(FileName))) + '\Backups'
From Master..SysDatabases Where [Name] = @dbName
Set @Qry = 'mkdir "' + @DefaultPath + '"'
Exec master..xp_cmdshell @Qry ,no_output
set @path = @DefaultPath
End
-- Make the filename
SELECT @Now = REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(50), GETDATE(), 120), '-', ''), ' ', ''), ':', '')
Select @path = + @Path + '\' + @dbName + '_' + @Now + '.Bak'
print @path
-- Take the backup of the database at the specified folder
Backup Database @dbName
To Disk = @Path
With Init
if @@Error <> 0
Begin
RaisError('Error Occurred while taking the Backup, Please check Error Log for Details',16,1)
return
End

Print 'Backup Taken Successfully at ' + @path
End

GO
Backup_database "Pubs","\\YourComputer\Shared"



Chirag

http://chirikworld.blogspot.com/
Go to Top of Page
   

- Advertisement -