SQL server backup restore issue - sql

Asking this question for a friend of mine.
My client had send me a Back up file of a database in SQL Server 2008.
I installed SQL Server 2008 Express Edition.
Then i tried to Restore the given Back file with this but unfortunately its throwing an error
"The media family on device is incorrectly formed . SQL Server can not process this media family.RESTORE HEADER ONLY is terminating abnormally .(Microsoft SQL Server, Error 3241)"
I searched for this error and evry where they says may be the back up might be corrupted.
But my client is able to restore the same at their end.
Any idea?

Have you applied the latest service packs to your copy of SQL Server 2008? Try that, and then do a RESTORE HEADERONLY command in Sql Enterprise manager. That will give you the properties of the file you're trying to backup. Is your client using Express Edition as well?

It is possible that the backup file became corrupt during transit.
I would suggest that the client either:
re-send the database backup file
or create another one.
It may also be pertinent to suggest to the client that when creating the Database Backup they use the CHECKSUM option to validate the contents of the backup file that is produced.
CHECKSUM
Enables backup checksums, so that BACKUP can do the following:
Prior to writing a page to the
backup media, BACKUP verifies the
page (page checksum or torn page),
if this information is present on
the page.
Regardless of whether page checksums
are present, BACKUP generates a
separate backup checksum for the
backup streams. Restore operations
can optionally use the backup
checksum to validate that the backup
is not corrupted. The backup
checksum is stored on the backup
media, not on the database pages.
The backup checksum can optionally
be used at restore time.
References
SQL Server Books Online - Backup Database

Related

TDE on Azure SQL Managed Instance

TDE is not enabled on MI by default. I had manually enabled TDE by setting the encryption to true in the db properties. Encryption of the DB took around 20 mins and below is the output from the sys.dm_database_encryption_keys table.
How do we verify if TDE is enabled in Managed instance or not? As neither Azure provides access to automated backups of MI nor i can manually take the backup when the TDE is turned on in MI.
Would like to access the automated backups (7day backup feature) and verify the files can be restored or not. Provide the procedure.
Hoping the backups are encrypted as TDE is enabled on my DB, so how can these be decrypted as Azure is not providing any keys to decrypt.
Use the following query to find encrypted database:
select name, is_encrypted from sys.databases
You cannot directly access backup files; however, you can run point-in-time restore to verify that any previous backup can be restored as a new database (you have restore button on the portal for each database or you can use PowerShell see - https://blogs.msdn.microsoft.com/sqlserverstorageengine/2018/06/28/point-in-time-restore-of-a-database-on-azure-sql-managed-instance-using-azurerm-sql-powershell-library/)
Point-in-time restore is the only way to restore encrypted automatic backups and Azure automatically de-crypts the backup on restore. You cannot restore backup from MI on SQL Server because MI is always higher version than SQL server. Therefore, even if you de-crpt the backup file you cannot use it on SQL Server, and if you want to restore it on Managed Instance, MI will find the key.

Azure Bacpac file Restore Error

I do the daily bacpac file backup from Azure database using RedGate Azure Backup tool.
Until 31st of May, All my Bacpac files can restore to Local SQL2008R2 database using DAC Client Tool.
Starting from 1st of June, I got error like:
Failure Creating schema objects in database
'XXXXX' System.Data.SqlClient.SqlException (0x80131904): Cannot
find the object "dbo.XXXX" because it does not exist or you do not have per
missions.
When I check it table still exist in DB.Also No idea for this.
Is there anyone face that kind of missing table, invalid Column.. etc
RedGate Azure Backup is deprecated now. The DAC Client Tool (DacCli.exe) has been integrated into SSMS 2012 and SSDT. You could try updating your DAC Client Tool to the latest version (1.6 from 1.2)
SSMS 2012 Data Tools now allow you to Import Data-tier Applications. Take a look at the Data-Tier Application Framework Feature in SQL 2012 downloads. View this MSDN article for reference.
I use the free utility SQL Backup and FTP to backup Azure SQL Databases to a local .bacpac file. The free version allows you to backup up to 2 different databases and then the paid versions are very reasonable (i.e. Professional version is $70 or so).
http://sqlbackupandftp.com/
It actually runs on a schedule for me, automatically emails me the results of the backup and stores it on my Google Drive (even with the free version - I just have it store the timestamped backups in the file folder of my Google drive).
The procedure I use to restore it to a local database is:
Back up SQL Azure to .bacpac file
Login to local database server as sa
Right-click Databases
Click Import Data-Tier Application
Select .bacpac file either from Azure or local disk
Enter the name and the locations to store the data and log files
If necessary, set the original database to single user mode and delete it
If necessary, rename restored database to original database name
Note: Must use SQL Server 2012 (or later) management tools

Why cant I create a database with mdf file?

I have a feature in visual studio which I have never really understood.
I am able to 'right-click' on the App_Data folder and then I am able to select 'Sql Server Database'. I dont really understand how I can create a db using just an mdf file? I thought the sql service was responsible for manipulating these files? And that you have to create the db using the 'sql management studio' interface?
Im confised as to how we can essentially just have a lone file and run a db from it for a website?
You're application is still connecting through the SQL Server service but it can instruct the service to attach to a specific mdf file at runtime through a connection string. e.g.:
"Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;"
All SQL Server databases are represented as one (or more) .mdf files and usually .ldf files as well (ldf is the log file, mdf is the data file.) An .mdf file is a file but it is highly structured and maintained by SQL Server. The way SQL Server uses this file is very different from serving up CSV data, as a simple example. SQL Server breaks the file into pages and serves the requests for reads and writes via this paging system. It is indeed like a file system within a file system. If you think about it it does all make sense. The data has to get persisted to disk and that disk persistence has to come in the form of a file or files.
When you installed Visual Studio you also installed SQL Server Express. This gives you the ability to create and use SQL Server databases.
If you were to deploy your application you would then also need to have a SQL Server (Express) install on the web-server you were using (at least because you don't want to use your development database server in production).

Restore DB from one server to another by sql-script

Are there any way to restore db from one server to another, if I know other server IP address?
Can I do it by sql-script or some wizard?
I use MS Sql Server Managment Studio 2008
TSQL script as
USE DATABASE -- TO TAKE BACKUP
GO
BACKUP DATABASE XXX -- XXX is database backup name
TO DISK = '\\\YYYY\XXX.BAK' -- YYYY is the shared folder to your backup and restore. Servers need access permissions on the folder as shared to available for both servers.
GO
USE MASTER
RESTORE DATABASE XXX
FROM DISK = '\\\YYYY\XXX.BAK'
GO
thanks
prav
As far as I know, you must do this in a two step process: create a backup file from the source database server, use the backup file to restore onto the target server. You can script the backup and restore presuming that one server can talk to the other, the destination server could (assuming the appropriate permissions), fire off a backup to an accessible location and then restore from that file.
you can restore your database from one server to another server by executing below script
RESTORE DATABASE mydb
FROM DISK='d:\mydb.bak'
WITH
MOVE 'mydb' TO 'D:\TSQL\mydb.mdf',
MOVE 'mydb_log' TO 'D:\TSQL\mydb_log.ldf'

SQL Server 2008 Version Problem [duplicate]

I am getting following error.
Restore failed for Server
I have recently upgraded SQL Server 2005 Express to SQL Server 2008 Express.
I have taken a Backup on Production Server, having SQL Server 2008
Backup was good and I tried restoring Backup on Production Server, that works great.
Than I downloaded that backup file in .Zip format with FileZila Software (And that is good too).
But when I tried to restore that file I am getting following error.
Restore failed for Server
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------ ADDITIONAL INFORMATION:
The media family on device 'C:\go4sharepoint_1384_8481.bak' is incorrectly formed. SQL Server cannot process this media family. RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.4053&EvtSrc=MSSQLServer&EvtID=3241&LinkId=20476
Things I tried which didn't worked
Attempt 1
Try to take backup using following command
BACKUP DATABASE go4sharepoint_1384_8481
TO DISK='C:\HostingSpaces\dbname_jun14_2010_new.bak' with FORMAT
And tried restore that file.
Attempt 2
Somebody wrote to test Version of my SQL Server.
When I tried to run following command in SQL Server 2008
Select ##Version
It is giving following output
Microsoft SQL Server 2005 - 9.00.4053.00 (Intel X86) May 26 2009 14:24:20 Copyright (c) 1988-2005 Microsoft Corporation Express Edition on Windows NT 6.0 (Build 6002: Service Pack 2)
My Production Database is in SQL Server 2008, and I am trying to restore DB in SQL Server 2008 but above version is showing as if i am using SQL Server 2005.
Any idea how can I restore SQL Server 2008 DB.
Many Thanks.
Is it possible that, instead of upgrading your 2005 instance to 2008, you instead installed 2008 side-by-side with 2005, and you're connecting to your existing 2005 instance? Look for other instances on your machine.
You cannot restore a backup from a higher SQL Server version on a lower version - this has never been able in SQL Server.
If you have a SQL Server 2008 backup, you can only restore that on a SQL Server 2008 (or later) machine - but not on a 2005 box. No trick, no workaround, no way to do it.
You have 2 options here.
Use WITH REPLACE while using the RESTORE command. This will overwrite the existing database and restore the database state represented by the backup files.
Delete the database to which you are trying to restore to and restore again using RESTORE command. This will create a new database with the state represented by the backup files.
Please note that in both these options you will lose the existing data of the database you are trying to restore to.
Make sure it is installed correctly - in your program files\microsoft sql server directory there whould be a 100/150 folder. Check out the install log in setup bootstrap\log.
As described above the reason for this behaviour is that by default SQL Server doesn't allow restoring a database backup to an older version of SQL Server, regardless of the compatibility level of the database the backup was taken from.
You can try to:
Start SQL Server Management Studio and connect to the instance where the database resides
In the database context menu navigate to Tasks | Generate Scripts…. This will invoke the Generate and Publish Scripts wizard
In the Introduction step of the wizard click Next
In the Choose Objects step of the wizard make sure that the Script entire database and all database objects option is selected and click Next
In the Set Scripting options step of the wizard:
Select the Save scripts to a specific location option
Specify whether the database objects and data will be scripted to a single file multiple files, as well as the path and encoding of the generated scripts
Click Advanced
In the Advanced Scripting Options dialog that will appear:
Specify the version of the SQL Server you need the database restored to in the Script for Server Version option
In the Script for Server Version option specify Schema and data
Set the following options to True:
Script Logins
Script Full-Text Indexes
Script Triggers
Click OK
Click Next
In the Summary step of the wizard click Next
In the Save or Publish Scripts step of the wizard click Finish
Execute the generated SQL script(s) against the older SQL instance
Although the procedure listed above should work:
1. It doesn’t migrate all of the database objects (e.g. sequences or queues)
2. It might fail if your database contains dependencies which SQL Server fails to recognize (e.g. dependencies to databases residing on linked servers)
You can take a look at the rest of the article on Solution center. There is also third party tools you can take in consideration.