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
Solved

SQL 2012 Express, sqlcmd,  Restore Database, user tables not restored.

Posted on 2014-03-02
12
677 Views
Last Modified: 2014-03-04
I have a script running sqlcmd to restore a database. It does not restore user tables, but does not give any errors. If I restore from the Management Studio, it works. Any idea what I am doing wrong?

Below is the syntax and the message:

RESTORE DATABASE PGMS
   FROM DISK = '\\SVR04\SVR04C\Backups\SVR04Apps\SQLSVR04.bak'
   WITH
     MOVE 'master'  TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\PGMS.mdf',
     MOVE 'mastlog' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\PGMS.LDF',
     REPLACE,
     RECOVERY

Processed 424 pages for database 'PGMS', file 'master' on file 1.
Processed 3 pages for database 'PGMS', file 'mastlog' on file 1.
RESTORE DATABASE successfully processed 427 pages in 0.168 seconds (19.816 MB/sec).
0
Comment
Question by:MikeBroderick
  • 7
  • 4
12 Comments
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39898910
you are using Windows Authentication or SQL Server Authentication.

if Windows Authentication, try "Run as administrator"
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39899336
Unfortunately. you cannot restore the master database that way.  Why don't you tell us what you are really trying to do?
0
 

Author Comment

by:MikeBroderick
ID: 39899337
I am using Windows Authentication. I tried "Run as Admin", same error.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:MikeBroderick
ID: 39899338
Sorry, I'm not trying to restore the master database. I am trying to restore a production database called PGMS. Apparently its logical file names are master and mastlog.
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 500 total points
ID: 39899346
Apparently its logical file names are master and mastlog.
Are you sure?
Can you confirm by doing the following:

SELECT  name,
        physical_name
FROM    sys.master_files
WHERE   DB_NAME(database_id) = 'PGMS'

Open in new window

0
 

Author Comment

by:MikeBroderick
ID: 39899432
The logical file names before the sqlcmd restore were A and A_LOG. After the restore they are master and mastlog.
0
 

Author Comment

by:MikeBroderick
ID: 39899470
I should add that I did not originally have the MOVE TO clauses, I added them while trying to make it work. I get the same error without the MOVE TO clauses.  I just tried changing the logical file names in the MOVE TO clauses to 'A' and 'A_LOG'. I get the following:

The file "master" is selected. At the time of backup it was known by the name "A". RESTORE will continue operating upon the renamed file.
The file "mastlog" is selected. At the time of backup it was known by the name "A_log". RESTORE will continue operating upon the renamed file.
Processed 424 pages for database 'PGMS', file 'master' on file 1.
Processed 3 pages for database 'PGMS', file 'mastlog' on file 1.
RESTORE DATABASE successfully processed 427 pages in 0.208 seconds (16.005 MB/sec).

But the same problem, no user tables.

The backup file has the databases master, model, and msdb on it also. It appears the restore is trying to restore the model database's files into the PGMS database. In the old days you had to display the backup file and locate the file numbers within the file for the database you want, and specify the "file numbers" within the file on the restore script. I don't see any parms to do that now. Am I missing something?
0
 

Author Comment

by:MikeBroderick
ID: 39899474
I should add I am backing up from system 3 and restoring to system 4. Also note that the number of pages restored matches the number of pages saved on system 3.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39899501
I am totally lost as to what you are doing.  May I suggest that since you state that "If I restore from the Management Studio, it works.", that you grab the SQL Script from there, without running the restore.
0
 

Author Comment

by:MikeBroderick
ID: 39900375
I am setting up a "poor man's" replication, where each night I backup the database PGMS off of the production system SVR04 into a file on the hard disk, and restore PGMS to another system SVR03 using the file on the hard disk. I am having a problem with the restore script (see above). The problem is seeming to boil down to this: The sqlcmd RESTORE DATABASE doesn't work, or I am doing something wrong. I mention that using Management Studio works verify the backup file is not corrupt.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 39902194
I mention that using Management Studio works verify the backup file is not corrupt.
I understand.  Perhaps you are not familiar with the way you can get the SQL script that SSMS is using?  If so, do the Restore from SSMS but don't click on OK, instead click on the Script icon in the top left corner.
0
 

Author Closing Comment

by:MikeBroderick
ID: 39903437
Your questioning me on the logical file names made me suspect the first saved database in the file was being used for the restore. When I clicked the script icon, the script showed with a FILE = 4 clause. I didn't know you could do that. When I added it to my script, it worked!

Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

792 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