Restore DB from one server to another by sql-script - sql

Are there any way to restore db from one server to another, if I know other server IP address?
Can I do it by sql-script or some wizard?
I use MS Sql Server Managment Studio 2008

TSQL script as
USE DATABASE -- TO TAKE BACKUP
GO
BACKUP DATABASE XXX -- XXX is database backup name
TO DISK = '\\\YYYY\XXX.BAK' -- YYYY is the shared folder to your backup and restore. Servers need access permissions on the folder as shared to available for both servers.
GO
USE MASTER
RESTORE DATABASE XXX
FROM DISK = '\\\YYYY\XXX.BAK'
GO
thanks
prav

As far as I know, you must do this in a two step process: create a backup file from the source database server, use the backup file to restore onto the target server. You can script the backup and restore presuming that one server can talk to the other, the destination server could (assuming the appropriate permissions), fire off a backup to an accessible location and then restore from that file.

you can restore your database from one server to another server by executing below script
RESTORE DATABASE mydb
FROM DISK='d:\mydb.bak'
WITH
MOVE 'mydb' TO 'D:\TSQL\mydb.mdf',
MOVE 'mydb_log' TO 'D:\TSQL\mydb_log.ldf'

Related

How to backup (automatically) an azure sql database on a local server?

I am looking for a way to backup an azure sql database to a local server. The backup should be created automatically.
How can I do that?
Thanks in advance!
You can't use BACKUP - since Azure SQL Database is always a newer version than any other version of SQL Server that you can install.
The way to do this is to extract a BACPAC and then apply that to your local server
If you want the local copy to be updated regularly - but not continuously, AND the local copy does not get updated, then consider Azure Data Sync

Invalid drive specification and how to restore with other server

I've created an agent job in SQL Server 2008 with steps:
Backup
Transfer File (to another server)
Restore (to another server)
Step 1 backup has been successful, but when process transfers the file, it fails with message
invalid drive specification
I've added IP of destination server on Windows credential, and I try to run the syntax in CMD it works:
exec xp_cmdshell 'xcopy D:\folder\file_name*.ext \\desination_IP\folder\'
When I try with SQL Server 2017, it works. Is there any difference between 2008 and 2017? Please let me know
Then go to the next step restore, what I want is to restore the database from server A to server B. Example I have 2 servers with the name A server and B server i put the job in A server and the job consists of step backup, step transfer file and step restore. I transfer db to B server then i want to restore database in B server from A server with agent.
The question is, is that possible? Can somebody help me with the query to restore a database from another server? Thanks
Check to see what user the SQL Agent service is running as, if it is Local System, you'll need to change it to an account that has access to the destination folder.

How to restore SQL server database from external drive without uploading database to local hard disk?

I am running win7 on a VM. I have Microsoft SQL Server 2014 downloaded on the VM. I have an external drive with a .bak file that I wish to restore a database with. The database is 400+ GBs. My local disk cannot support a database of this size, but my external drive can. How do I run SQL Server locally and restore from and keep the database files externally?
You can create database then configure it for files run on external drive. Then try to restore it.
Creating db on another folder example here: Create a database using T SQL on a specified location
It's possible, search for DBCC TRACEOFF(1807), e. g.:
http://sql-articles.com/articles/general/day-2trace-flag-1807attach-network-data-file/

How to copy a SQL Server 2005 database from local to the server

I want to export database from local computer to database server in SQL Server 2005.
How can I restore database without having access to file system of database server
You can use SQL Server's built-in backup and restore functions.
Make a backup of your local database, and write it on some network share (can be anywhere in the network, doesn't have to be on the database server):
BACKUP DATABASE MyDatabase TO DISK = '\\Servername\Share\MyBackup.bak'
Then, you can restore the database on the database server, reading the backup directly from the network share:
RESTORE DATABASE MyDatabase FROM DISK = '\\Servername\Share\MyBackup.bak'
Note that you have to everything in T-SQL to be able to read and write directly to network shares!
(You can also backup and restore databases from the GUI in SQL Server Management Studio, but you can only use local folders there)
Your situation is, you want to copy the database from your local to remote database server but you do have access to the remote machine thats why you cannot use a restore or attach database function.
Solution:
For me the best thing to do is generate a script that will include the schema and the data of the database. This will serve as a script backup of your local database which can be run to any sql servers that you wanted. Sql Server 2008 already have the interface for this but for Sql Server 2005 you will need to have Sql Publishing Wizard.
You can download it from here: (remove spaces)
http: //www.codeplex.com/sqlhost/Wiki /View.aspx?title=Database%20Publishing%20Wizard
To create a script you can do this:
Command to run which will create schema and database:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql”
Command to run which will create schema:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql” -schemaonly
Command to run which will create data:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks “C:\AdventureWorks.sql” -dataonly
For more details please read...(Remove Spaces)
http: //blog.sqlauthority.com/2007/11/16/ sql-server-2005-generate-script-with-data-from-database-database-publishing-wizard/
This worked for me a lot of times.
You will need access to the file system of the database server.
You have to detach the database from your local server and then copy the related .mdf and .ldf files to the target database server and then attach the files in the SQL server management studio of that database server.

Backup remote SQL Server 2005

How do I backup data from a remote MS-SQL Server DB to my local computer?
I'm having access to Management Studio 2008.
sqldumper.ruizata.com solved my problem.
You'd specify the target for the backup file to a UNC path on your local machine. When you specify to Backup you have to specify a Desination. That destination can be either a Filename locally pathed to the SQL Server instance (e.g. E:\Backups\Database.BAK) or a UNC path such as \\YOURMACHINENAME\SHAREDFOLDERONYOURMACHINE\FILENAME.BAK.
If you want to backup the remote database then you can run a query such as
BACKUP DATABASE mydb TO DISK = 'd:\whatever\location\mydb.bak'
Where the 'd:' drive will be local to the SQL Server, otherwise use the format
BACKUP DATABASE mydb TO DISK = '\\mylocalcomputer\share\mydb.bak'
to backup to your machine.