Restoring a database in Azure - sql-server

I did a database restore in Azure and now have 2 databases. The original and the restored one with a suffix added to the name.
How do I copy the restored one over the original one?
I do not want to update the connection string in my application.

If you know for sure,both have same data..try below steps
1.Rename old database to some other name
2.Rename restored database name to desired one as per config
3.drop or archive for some days the currently renamed database
You can do the renaming part through SSMS.

Related

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.

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.

Analysis Services .abf file database restore

I am really really new to SQL Server, I know how to do a query and other simple stuff and recently my company was bought by another one, we had a Cube Server which was accessed by a excel file via olap using the analysis services from sql server 2008 it was updated by an .abf file, first day after the sale the former server was retired, and everything I have access to is this .abf file used to update the cube, I installed sql server 2008 enterprise edition and I'm trying to restore the file to a new database via the analysis services since the only instructions I received from the old IT department is that is needed to be restored via analysis services. I searched online for some solutions and came across several articles and none of the steps worked for me because they required a already configured database and they were only restoring a backup. I'm thinking I need the .mdf file first so I can recreate the database as is and then I can update it via the .abf file, can someone point me in the right direction?
Since you have the .ABF file, there are a couple options to restore this as a new database. You can either create a new database with the same name, then restore this database from the .ABF file with the AllowOverwrite option set to true. You can also restore directly to a new database by right-clicking the SSAS instance and selecting Restore... From here, specify the backup file name and just enter the name of the database and this will be created as a new cube. This name must be a new database name, as if an existing cube is specified it will be overwritten. Either approach can be done through an XMLA command in SSMS and an example of this is below.
<Restore xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<File>C:\YourFilePath\YourCubeBackupFile.abf</File>
<DatabaseName>TargetOrNewDatabaseName</DatabaseName>
<AllowOverwrite>true</AllowOverwrite>
</Restore>
Try attaching the database with the mdf file in the sql server 2008.

how to copy a database in SQL server management studios

I have a database in SQL server management studio named wardobsliveisle. I want to create another database in SQL server management studio that is the exact same copy of wardobsliveisle but I want to call it demosql. How do I do this?
You have database wardobsliveisle in SSMS and now you want to create an other database demosql from wardobsliveisle. The process given below creates a copy of wardobsliveisle with new name demosql. This new database has now separate .ldf and .mdf files and it is absolutely a separate copy of your original database.
Follow the steps
Right click on Databases in your Object Explorer in SSMS.
Select Restore Files and Filegroups..., a wizard opens
Type a new database name demosql in To Database box and select source
database (Not a backup file) from From Database dropdown.
Click OK button
It will take a few minutes or less.
Taken from MSDN:
General Steps for Using Backup and Restore to Copy a Database
When you use backup and restore to copy a database to another instance of SQL Server, the source and destination computers can be any platform on which SQL Server runs.
The general steps are:
Back up the source database, which can reside on an instance of SQL Server 2005 or later. The computer on which this instance of SQL Server is running is the source computer.
On the computer to which you want to copy the database (the destination computer), connect to the instance of SQL Server on which you plan to restore the database. If needed, on the destination server instance, create the same backup devices as used to the backup of the source databases.
Restore the backup of the source database on the destination computer. Restoring the database automatically creates all of the database files.
The following topics address additional considerations that may affect this process.
Before You Restore Database Files
Restoring a database automatically creates the database files that are needed by the restoring database. By default, the files that are created by SQL Server during the restoration process use the same names and paths as the backup files from the original database on the source computer.
Optionally, when restoring the database, you can specify the device mapping, file names, or path for the restoring database. This might be necessary in the following situations:
The directory structure or drive mapping used by the database on the original computer not exist on the other computer. For example, perhaps the backup contains a file that would be restored to drive E by default, but the destination computer lacks a drive E.
The target location might have insufficient space.
You are reusing a database name that exists on the restore destination and any of its files is named the same as a database file in the backup set, one of the following occurs:
If the existing database file can be overwritten, it will be overwritten (this would not affect a file that belongs to a different database name).
If the existing file cannot be overwritten, a restore error would occur.
To avoid errors and unintended consequences, before the restore operation, you can use the backupfile history table to find out the database and log files in the backup you plan to restore.
Moving the Database Files
If the files within the database backup cannot be restored onto the destination computer because of the reasons mentioned earlier, it is necessary to move the files to a new location while they are being restored. For example:
You want to restore a database from backups created in the default location of the earlier version.
It may be necessary to restore some of the database files in the backup to a different drive because of capacity considerations. This is likely to be a common occurrence because most computers within an organization do not have the same number and size of disk drives or identical software configurations.
It may be necessary to create a copy of an existing database on the same computer for testing purposes. In this case, the database files for the original database already exist, so different file names need to be specified when the database copy is created during the restore operation.
For more information, see "To restore files and filegroups to a new location," later in this topic.
Changing the Database Name
The name of the database can be changed as it is restored to the destination computer, without having to restore the database first and then change the name manually. For example, it may be necessary to change the database name from Sales to SalesCopy to indicate that this is a copy of a database.
The database name that is explicitly supplied when you restore a database is used automatically as the new database name. Because the database name does not already exist, a new one is created by using the files in the backup.

what and where can I find the database/table files for sql server 2005?

In my sql server 2005 I have a database named movies . In this database I have a table named list. I wanted to test my application on some another machine. Is there any way I can take with me that database or tables so that there is no need to create them again there. What type of files are they if there is a way out other than creating a new database and tables again
One thing you can do is to take a local backup of the database (if you you want all the transactions as well include the transaction log file). Then put that .BAK file on a thumb drive and go to the other machine. Once at the other machine you can "Restore" the .BAK as the database on this new machine.
Here is a screen shot of the "Back Up..." and restore options:
You'll want to 1st back it up to either a network location or even onto say the desktop of the first machine. You can keep most of the defaults when you do a backup and I would recommend a "FULL BACKUP". Once you click ok, it will generate a Database.BAK file. Then you can take this file to be used when you do a "Restore" on the other machine. The restore can have the same database name or a different one on this 2nd machine.

Resources