Solved

Make copy SQL database on same server

Posted on 2014-12-16
5
346 Views
Last Modified: 2014-12-16
I have a SQL 2014 instance containing a database with the following properties:

SQL Host:  sqlprod
DB:  ecm
DB User:  ecmuser

I have a production web app that connects to the db with the properties above.

I'm trying to stand up a test instance of the web app.  Can I copy (backup/restore) the ecm db on the same SQL host?  ....Essentially creating a new db with the name ecmtest, and restoring a backup of ecm to ecmtest.

Would this work?  Or do I need a new SQL instance?

Thanks in advance.
0
Comment
Question by:bmsande
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40502831
You can do this. But keep in mind, that this requires resources (CPU, RAM, DISK) from the production system..

Thus its better to :
1. Install it on a separate test server.
2. Install it in a test instance.

You need also to consider interactions: Do you use xp_cmdshell or work with jobs? These may affect production resources like files or web services.
0
 

Author Comment

by:bmsande
ID: 40502888
Thanks for your response.  System resources are not a concern, but good point.  I'm pretty certain xp_cmdshell is not used.  Could you be more specific on 'jobs'?   This is mostly tables and views, and a couple stored procedures.

When looking at my db in SQL, I expand tables and see the following:

ecmuser.table1
ecmuser.table2
etc, etc

How would I handle the user during this process, on the same SQL instance?  The same user can be mapped to both db's, right?  I would prefer to use a different user, for isolation purposes.  

I'm in a situation where a test environment is needed, but the customer only has one SQL 2014 instance.  They have SQL 2012 and 2008 R2 on the network, but I was afraid I can't take a SQL 2014 db backup and restore (downgrade) on a different SQL version.  If this is possible, then I would prefer this process for test-prod isolation.
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40502908
Well, consider a stored procedure interacting with SQL Server Agent.

You need to remove them manually in your restored database and create the appropriate user/logins. When you already use roles assign permissions to users then this is easy. Otherwise you need to assign the permissions also.

When there exists a test server, then install an express instance on it.
0
 
LVL 49

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 250 total points
ID: 40502928
Yes, you can do it pretty easy. You just need a backup from emc database and then run the following restore command:
RESTORE DATABASE emctest
   FROM DISK='K:\Backups\EMC.bak'
   MOVE 'EMC_Data' TO 'N:\Data\EMCtest_Data.mdf', 
   MOVE 'EMC_Log' TO 'N:\Log\EMCtest_Log.ldf'

Open in new window

K;\Backups is only an example. You should replace it with the current path to the backup file.
N:\Data and N:\Log are also an example. You should replace both with the new location for the files of the new database (emctes).

NOTE: Since you are copying to the same instance there's no need to recreate the users since they will automatically matched with the respective logins.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 40502943
You can create the test db using a standard SQL RESTORE including the necessary WITH clauses to assign new physical file names:
RESTORE DATABASE ecmtest
FROM DISK = 'x:\full\path\to\backup\file\ecm.bak'
WITH MOVE 'logical_file_name_1' TO 'd:\full\path\to\new\data\file\ecmtest.mdf',
    MOVE 'logical_file_name_2' TO 'l:\full\path\to\new\log\file\ecmtest_log.ldf'

Then change the existing user name to your test user name:
USE ecmtest;
ALTER USER ecmuser WITH NAME = ecmtestuser;
ALTER USER ecmtestuser WITH DEFAULT_SCHEMA = ecmuser;

IMO, the test user name should never appear in the production db, and the prod user name should never appear in the test db, to help prevent accidentally being in the wrong environment.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Select Query help 1 38
T-SQL Query - Group By Year 3 32
ODBC settings not showng in FileMaker External Data Sources 6 23
Need to replicate a Log table 4 10
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question