I am not able to restore backup file in mssql - sql-server

I have a .sql database which is from a different computer to ms-sql 2012 version.
When I try restoring it, it says: "no backup selected to be restored". I tried setting the permissions, tried restoring using restore tsql statement, but nothing seems to be working. Both are the same version, 2012.
restore database tables from disk='E:\tables\Tables.bak'

Related

Sql User recovery

i have an problem with sql Oracle, basically I restored my pc and all the files had to be uninstalled, I recovered the oracle folder with the database saves, however now I can't log in on the user I was using before I restored my pc, how could I do to fix it?

Restoring a running database in a different name in same server in SQL Server 2012 using Management Studio

I have SQL Server 2012 (64-bit) (MSSQL11)
running on Windows 2012 R2 (64-bit) (NT 6.3)
with .NET framework 4.0.
It has a database called db_X and since this is a live production database it is always running and stopping it is not an option.
This is the only SQL Server database server that I practically have.
I want to take a backup (i.e. a full backup) of db_X (which I know how to do) and restore that backup (that .bak file) under a different name (say db_Y) in the same SQL Server database server.
I created a new database called db_Y, then right clicked db_Y then went to Tasks --> Restore --> Database...
Then I gave the path to that .bak file (as source) and tried to restore it by giving db_Y as destination (with the option - overwrite the existing database i.e. WITH REPLACE)
But this is not working. It is giving an error.
It says restore of database db_Y failed. System.Data.SqlClient.SqlError: The file C:...\db_X1.mdf cannot be overwritten. It is being used by database db_X. Microsoft.SqlServer.SmoExtended.
But I still believe that this can be done using the Management Studio. Or at least using a script. (as this is a common requirement.)
Why is it trying to restore on db_X, when I have clearly given db_Y as my destination? Isn't this a bit scary as db_X is my live database (because I might lose some data)?
How is it possible to (have a copy of an existing and running database under a different name in SQL Server or in other words) restore a backup of an existing and running database with a different name in SQL Server 2012?
I am grateful if someone could kindly explain how this can be done using the Management Studio or at least using a script.
When you are restoring the database, you need to rename the database to something other than the name of the original:
And then click the Files section and makes sure the file names are different than the original database:

DBeaver restore SQL Server .bak file

I am just trying to restore a SQL Server .bak file in my DBeaver UI. But I have no idea how to do this - can someone help please?
I created a database, but when I right click on it, there are no restore options.
I do not see that option either in my version of DBeaver (6.1.3 - community). What you could do is initiate a restore with TSQL (by clicking on SQL Editor while you are connected to your database). Then in the Script area, use the below, modified for your own environment/database name.
USE [master] RESTORE DATABASE [DatabaseName] FROM
DISK = N'C:\FolderName\BackupName.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10
For full Tsql options to restore a database, see this: RESTORE Statements (Transact-SQL)
In my case the database migration was done on windows environment so there was some issue restoring backup in Ubuntu 18.04 which was fixed from below command.
backup file path: /var/opt/mssql/data/
move file path: /var/opt/mssql/data/
Restoring database backup in Ubuntu using DBeaver
RESTORE DATABASE MYDB_API FROM DISK = N'/var/opt/mssql/data/mydb.bak'
WITH MOVE 'MYDB_API' TO '/var/opt/mssql/data/mydb.mdf'
, MOVE 'MYDB_API_log' TO '/var/opt/mssql/data/mydb_log.ldf'
REPLACE
Note: if above does not work for you then remove REPLACE from above and make sure MYDB_API does not exist on SQL Server.
It looks like you are using a macOS which is a system not supported by SQL Server Management Studio (SSMS).
So I assume you need to restore SQL Server database with .bak file under macOS GUI.
There is no GUI option to retore .bak file with DBeaver.
If you want absolutely a restoration with GUI and not TSQL, an alternative on macOS is Azure Data Studio (from Microsoft) which is an open source data management tool that runs on Windows, macOS, and Linux.
You can easily restore a bak file in GUI with Azure Data Studio.
Here is the tutorial:
https://learn.microsoft.com/en-us/sql/azure-data-studio/tutorial-backup-restore-sql-server
Restore a database from a backup file (With Azure Data Studio)
Open the SERVERS sidebar (CTRL+G), right-click your server, and select Manage.
Open the Restore database dialog (click Restore on the Tasks widget).
Select Backup file in the Restore from field.
Click the ellipses (...) in the Backup file path field, and select the latest backup file for TutorialDB.
Type TutorialDB_Restored in the Target database field in the Destination section to restore the backup file to a new database.
Click Restore
To view the status of the restore operation, press CTRL+T to open
the Task History sidebar.

SQL Server restoring to a different destination puts source DB into restoring state

I'm using a backup file to restore a database to a different database. The source database is the only one in the backup file and is selected as source.
A different database is the destination.
The restore option is overwrite the existing database (with replace). The restore as files are renamed to the destination database's files.
Other than the selected database's name in the file, the source is not involved at all in the restore.
After the restore the source database immediately goes into recovery and I have to restore it to get it out.
Even though it is not being touched.
Can anyone tell me how to stop this?
The server and studio versions are below.
Very much appreciated.
SQL Server 2008 (Version 10.0.2757.0)
SQL Server Management Studio 2012 (Version 11.0.6020.0)
(I have searched for this issue but found nothing fitting this description.)

SQL Server database restore error: specified cast is not valid. (SqlManagerUI)

I am using SQL Server 2008 R2 Standard (version 10.50.1600.1) for my production website and
SQL Server Express edition with Advanced Services (v10.50.1600.1) for my localhost as a database.
Few days back my SQL Server crashed and I had to install a new 2008 R2 Express version on my localhost. It worked fine when I restored some older versions taken from Express edition but when I try to restore database from .bak file which is taken from production server it is causing the following error:
Error: Specified cast is not valid. (SqlManagerUI)
and when I try to restore the database using command
Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications.bak'
WITH MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'AlPublications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
It generates a different error
Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing 'Publications' database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
I have cross checked the versions. They all seem matching to me as shown in the image below
Previously I was able to restore a database from standard version to express edition but now it fails. I deleted the database and tried to recreate it. That fails, too.
I am not sure what I am doing wrong. I would appreciate help in this regarding
Issue was resolved as it seems .bak file was corrupt. When I tried it with a different file it worked.
Could be because of restoring SQL Server 2012 version backup file into SQL Server 2008 R2 or even less.
The GUI can be fickle at times. The error you got when using T-SQL is because you're trying to overwrite an existing database, but did not specify to overwrite/replace the existing database. The following might work:
Use Master
Go
RESTORE DATABASE Publications
FROM DISK = 'C:\Publications_backup_2012_10_15_010004_5648316.bak'
WITH
MOVE 'Publications' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.mdf',--adjust path
MOVE 'Publications_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS2008R2\MSSQL\DATA\Publications.ldf'
, REPLACE -- Add REPLACE to specify the existing database which should be overwritten.
Finally got this error to go away on a restore. I moved to SQL2012 out of frustration, but I guess this would probably still work on 2008R2. I had to use the logical names:
RESTORE FILELISTONLY
FROM DISK = ‘location of your.bak file’
And from there I ran a restore statement with MOVE using logical names.
RESTORE DATABASE database1
FROM DISK = '\\database path\database.bak'
WITH
MOVE 'File_Data' TO 'E:\location\database.mdf',
MOVE 'File_DOCS' TO 'E:\location\database_1.ndf',
MOVE 'file' TO 'E:\location\database_2.ndf',
MOVE 'file' TO 'E:\location\database_3.ndf',
MOVE 'file_Log' TO 'E:\location\database.ldf'
When it was done restoring, I almost wept with joy.
Good luck!
Below can be 2 reasons for this issue:
Backup taken on SQL 2012 and Restore Headeronly was done in SQL 2008 R2
Backup media is corrupted.
If we run below command, we can find actual error always:
restore headeronly
from disk = 'C:\Users\Public\Database.bak'
Give complete location of your database file in the quot
Hope it helps

Resources