To back up my SQL Azure database periodically I have been using the simple tSQL statement
CREATE DATABASE FiveModes10_12_12 AS COPY OF FiveModes
But for this project (analysing some experimental results) my database is a local SQL Server 2012 one and I cannot run that statement (I get the error Incorrect syntax near 'COPY'). Looking at the documentation for the CREATE DATABASE command for SQL Server 2012 there is no AS COPY OF option. What is the simplest alternative?
For long lived copies take e database backup instead:
backup database FiveModes to disk = 'path to .bak file' with init, copy_only;
You can the restore this when needed:
restore database FiveMode from disk = 'path to .bak file';
You can even restore the backup as a new database, but you'll need to move the location of the MDF/LDF files during the restore:
restore database FiveMode_12_12 from disk = 'path to .bak file'
with move 'FiveMode' to '<path to place the new copy of MDF>',
move 'FiveMode_log' to '<path to place the new copy of LDF>'
If you need only short lived copy (eg. create a copy, do some experiment, revert to the copy) you can use database snapshots, but it requires Enterprise license. See Database Snapshots:
create database FiveModes10_12_12 on
(Name = 'FiveMode', FileName = '<path to MDF snapshot file>')
as snapshot of FiveModes;
But be aware that snapshots are not at all like Azure copies, is very detrimental to keep them along for long time. For long time copies use backups.
Related
I have database backup A.bak
I want to restore that backup file, using the SQL Server Management Studio, into database B which has all the same tables/columns but just different name.
If I try to do the restore - I am getting error:
The backup set holds a backup of a database other than the existing
How can I resolve this? I tried renaming the .bak file but it didn't work
Specify the "Overwrite the existing database (WITH REPLACE)" option:
I'm using microsoft SQL server. I have a database that we can call database1 and its backup in .bak format.
I need to restore the backup to another, blank database that we can call database_temp, so both database must exist. I need to get and confirm some data from the database_temp archive and then delete it when I'll end my job.
what I did:
1) created new database "database_blank"
2) tasks - restore database. In source I choose "device" and then my .bak file, in destination I select database_temp.
3) in option I choose Overwrite the existing database with replace.
I got the error "Restore of database failed the file cannot be overwritten it is being used by database1 database"
You have to move the database files.
e.g.
RESTORE DATABASE [AdventureWorks] FROM DISK = 'c:\backup\Adv.bak'
WITH CHECKSUM,
MOVE 'AdventureWorks_Data' TO 'c:\mssql\data\AdventureWorksCopy_Data.mdf',
MOVE 'AdventureWorks_Log' TO 'c:\mssql\log\AdventureWorksCopy_Log.ldf',
RECOVERY, REPLACE, STATS = 10;
The first part of the move is the logical file name of the database file. Right click on the original database - Properties - Files to get the right names.
The full documented syntax can be found here
I'm trying to restore a DB from the class. However, when I try to restore the .bak file, it seems like SSMS doesn't recognize it.
I gave full permissions to the folder which contains the .bak file (it is the default backup folder of ms SQL studio).
Steps I've taken to restore the .bak file:
Right click on DB -> Restore DB -> From device (selected the .bak file location) -> To Database (selected the DB destination)
Like here:
C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Backup
The DB is not corrupt I checked 2 other DB same result so I have no idea what is the problem
Here images:
I can not see the DB and I have almost the latest version of MS SQL studio so I can not understand what is going on here and why I can not restore DBs
I checked here:
restore database in ssms 2017 selected bak file in device option and showing nothing in Backup sets to restore option and disable Ok button too
and here:
SQL Server Management Studio can't recognize .bak file
https://www.youtube.com/watch?v=U0FpXwQfBaU
It should be easy and simple like the video above but like I said above something is wrong here and I do not know what is it.
Image of my SQL version
Once you (i mean the service account) got full permissions on the folder where the .bak file sitting and file not corrupted you should be able to restore without any issue, but there are times things fail in GUI and work perfectly with command line. not sure the issue might be exists one of the fix of SSMS release notes
However, you probably want to try following:
Verify the backup file - it does the verification of backup file and detects any error/corruption within backup file
RESTORE VERIFYONLY FROM DISK = 'C:\YourbackupLocation\DbName.bak';
Read the header - it returns information of backup file i.e. DB Version, appended backup files, LSN info and database recovery model etc..
RESTORE HEADERONLY FROM DISK = 'C:\YourbackupLocation\DbName.bak';
Get list of file names from backup - This will be helpful if the file location is different from the source server from where the backup was created
RESTORE FILELISTONLY FROM DISK = 'C:\YourbackupLocation\DbName.bak' ;
Restore backup - actual restore via T-SQL
RESTORE Backup DBName FROM DISK = 'C:\YourbackupLocation\DbName.bak' with replace, recovery, stats;
To relocate files
RESTORE Backup DBName FROM DISK = 'C:\YourbackupLocation\DbName.bak'
with replace, recovery, stats
--- Get the logical name from the result of "RESTORE FILELISTONLY" command
move 'DBName' to 'C:\NewLocation\DBName.mdf',
move 'DBName_Log' to 'C:\NewLocation\DBName_log.ldf' ;
I am testing to see if a SQL Server server based program can also work on AWS Cloud Server with 2016 SQL Server on the Amazon server. In order for me to test it, I need to restore 2 databases.
The first one eventually restored fine once i figured it out...restoring the database from my S3 "bucket" BAK file.
So then I tried to restore the 2nd database, using the same restore stored proceudre, and get this message:
[2017-12-28 02:44:22.320] The file 'D:\rdsdbdata\DATA\smsystemdata.mdf' cannot be overwritten. It is being used by database 'amwsys'.
[2017-12-28 02:44:22.320] File 'sm_system_data' cannot be restored to 'D:\rdsdbdata\DATA\smsystemdata.mdf'. Use WITH MOVE to identify a valid location for the file.
I can't find where to use the WITH MOVE because it won't let me restore it interactively through the Management Studio restore menu; instead I have to give it a stored procedure command:
exec msdb.dbo.rds_restore_database
#restore_db_name='sample99',
#s3_arn_to_restore_from='arn:aws:s3:::lighthouse-chicago/sample999.bak';
And each time it tells me it can't restore it because it's going to overwrite the first database's files.
Much thanks
bill
I think you are stuck in RDS's restriction.
I had the similar problem as you. Multiple restore from one DB instance is impossible at RDS.
Here is RDS's restriction you may encounter.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html
You can't restore a backup file to the same DB instance that was used
to create the backup file. Instead, restore the backup file to a new
DB instance. Renaming the database is not a workaround for this
limitation.
You can't restore the same backup file to a DB instance multiple
times. That is, you can't restore a backup file to a DB instance that
already contains the database that you are restoring. Renaming the
database is not a workaround for this limitation.
If you are in this case, you can't use .BAK file. To avoid it, you should create DB instance with DML and import table data.
i am using SQL server express 2005 as an backend. I created a backup file programmatically.If i use same server , then it restore the data successfuly. however if we try to restore on different server, then it fails. and throw following message
"The Backup set Holds a backup of a database other than the existing 'DatabaseName' database. RESTORE DATABASE is terminating abnormally."
On both server, Sql server instance name and database name is same.
Please suggest how can i resolve this error
You need to RESTORE from files (which are contained in the backup set) rather than the backup set directly. The bottom example is to copy a database, but the idea is the same.:
BACKUP DATABASE AdventureWorks
TO AdventureWorksBackups ;
RESTORE FILELISTONLY
FROM AdventureWorksBackups ;
RESTORE DATABASE TestDB
FROM AdventureWorksBackups
WITH MOVE 'AdventureWorks_Data' TO 'C:\MySQLServer\testdb.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\MySQLServer\testdb.ldf';
GO