Restore from .bak only imports system tables - sql-server

I was given a .bak from a MS SQL database and am needing to import the database onto a different workstation. I created a blank database in SQL Management Studio and attempted to restore from the .bak. The restore lists as successful, but only system tables appear in the restored database.
Am I missing a step?

Per the conversation in the comments, you had a backup of msdb rather than the database you wanted. You can do a restore with headeronly from disk = 'name of file here' to see what database is contained in the backup.

Related

How can I backup and then restore SQL Server DBs to different names without overwriting existing DBs?

I'm working on a small project to backup and restore databases to different name(s), and I can't seem to figure it out.
I'm using SSMS v18.11.1 with SQL Server 2016, and I have seven databases, let's call them DBCompanyA_1 ... DBCompanyA_7. Their .mdf and .ldf files are stored in the default location of
C:\Program Files\Microsoft SQL Server/MSSQL13.MSSQLSERVER\MSSQL\DATA
I want to make a full backup of each of those 7 databases (with logs) and then restore them to a different name. Using my example above, let's say that I want to restore them to DBCompanyB_1 ... DBCompanyB_7.
The problem I keep encountering is that all attempts (using MOVE) overwrites the existing DBCompanyA_n databases, which is bad. I want to use backup and restore so that the DBs originals' permissions will carry over to the new DBs.
I don't care if the backup procedure is via UI or script, but the restore must be using T-SQL.

Restore DB using a bak file. The backup set holds a backup of a database other than the existing database

I am attempting to restore a DB for example versionB using a .bak file of version A.
It seems like that is not the right thing to do because I am getting an error:
TITLE: Microsoft SQL Server Management Studio
Restore of database 'B' failed.
(Microsoft.SqlServer.Management.RelationalEngineTasks)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than the existing 'B' database. (Microsoft.SqlServer.SmoExtended)
To overwrite a database with a backup taken from a different database you must specify the WITH REPLACE option in the RESTORE command.
REPLACE should be used rarely and only after careful consideration.
Restore normally prevents accidentally overwriting a database with a
different database. If the database specified in a RESTORE statement
already exists on the current server and the specified database family
GUID differs from the database family GUID recorded in the backup set,
the database is not restored. This is an important safeguard.

Why tables and stored procedures not stored after restore database?

I have a database in SQL Server that i create backup file from it. Now i create a new database and i try to restore backup to this new database.
I try to restore a database from a .bak file. When I restore it in SQL Server, I get a "successful" message, but all tables and stored procedures are not restored.
What is problem?
but all tables and stored procedures are not restored.
It means that you can see newly restored database in SQL server. in that case verify the .bak file to check whether it's got actually all those required Tables/Procedures part of it, or the same .bak file might have appended with empty database backup (for some reason). You can check that with following query:
RESTORE HEADERONLY FROM DISK = 'C:\Backups\AppendedBackup.bak';
I do this settings and restored currently.

Restore Azure SQL DB over an existing DB to maintain backup history

I'm setting up an Azure SQL DB for our Web App. We have enabled Point In Time Retention (PITR) and Long Term Retention (LTR). Our process is to keep backups for 1 year.
Periodically, we need to upgrade the DB by applying SQL scripts. Sometimes there is a problem with the upgrade scripts and the upgrade fails. We need to rollback the database to the previous version.
To rollback the DB I tried the restore feature. However, the restore feature seems to only create new DBs; therein lies the problem. Restoring to a new DB and removing the old one works great, but we lose all our backup history. It appears backups are tied to the DB (probably to the ResourceId).
So, how can I use Azure SQL DB and periodically restore a DB and still maintain all the back up history?
Unfortunately, restoring from a backup in Azure SQL Database always creates a new database. The secret here may be to rename the newly restored database with the name of the original database. You will even see that the restored database once renamed it then shows all the security recommendations, automatic tuning recommendations of the original database.
So delete existing database, restored the database, and rename it as the original database.
You can reference this document Recover an Azure SQL database using automated database backups , it gives the answer that all the recover are creating new database.
By default, SQL Database backups are stored in geo-replicated blob storage (RA-GRS). The following options are available for database recovery using automated database backups:
Create a new database on the same SQL Database server recovered to a specified point in time within the retention period.
Create a database on the same SQL Database server recovered to the
deletion time for a deleted database.
Create a new database on any SQL Database server in the same region
recovered to the point of the most recent backups.
Create a new database on any SQL Database server in any other region
recovered to the point of the most recent replicated backups.
If you configured backup long-term retention, you can also create a new database from any LTR backup on any SQL Database server.
improtant:
You cannot overwrite an existing database during restore.
"So, how can I use Azure SQL DB and periodically restore a DB and still maintain all the back up history?"
You can use Database replacement:
If the restored database is intended as a replacement for the original database, you should specify the original database's compute size and service tier. You can then rename the original database and give the restored database the original name using the ALTER DATABASE command in T-SQL.
Hope this helps.

Restoring database on SQL Server went wrong

Let's say I have database named db1 on SQL Server. I have daily backup, and I wanted to restore month old backup to new database, so I can recover just some info.
I created database db2, and tried to restore the db1 backup to new and empty db2 database.
I got message that backup I selected does not contain db2 backup and it started to restore db1 itself!!!
So now, for quite some time, next to db1 there is message (restoring...)
How can I stop restoring db, I didn't wanted to restore db1 at first place, and that's why I choose to restore backup to db2 destination.
Is there any chance I still have today's db, not this one month old?
I still can't open db1 to see what I have there, because it's not accessible.
Thanks.
Sorry but I am sure you are using GUI and you were not carful in that even. Please use query over GUI for max work.
Now your issue, I am not sure if you already fix but as no reply on web
Now you lost your database, its of no use. So find a latest backup and restore db1 (you can use point in time recovery if you have t-log backups)
Restore db2 with 30 days old backup by query , use move option in restore or create new empty database first and then restore same with replace option.

Resources