Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 March SQL Server: MEDIAPASSWORD – password to your Database Backup file

SQL Server: MEDIAPASSWORD – password to your Database Backup file

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am showing MEDIAPASSWORD option to set a password to your database backup file in SQL Server.
We should not take a risk with our backup media file, especially when we are taking backup of sensitive data like the banking system.

You can set a password using MEDIAPASSWORD option while taking a backup, and you cannot restore that backup file without specifying a password.

You can set MEDIAPASSWORD in plain text, so again you have to take care of your backup/restore scripts. So again you have to take care of your backup/restore scripts.

SQL Server Database Backup Password

Once you set a password, it applies to all types of restore option like RESTORE FILELISTONLY, RESTORE HEADERONLY, RESTORE LABELONLY, RESTORE VERIFYONLY, and you must require a password for all these options.

Beginning with SQL Server 2012 the PASSWORD and MEDIAPASSWORD options are discontinued for creating backups. It is still possible to restore backups created with passwords.

Let me demonstrate this,

T-SQL Script to take a backup with MEDIAPASSWORD:
I set password ‘dbrnd.com’ for my dbrnd database backup.

1
2
3
4
5
BACKUP DATABASE dbrnd
TO DISK = 'C:\MyBackups\dbrnd.bak'
WITH COMPRESSION,
MEDIAPASSWORD='dbrnd.com'
GO
Try to restore this backup without giving a password:
1
2
3
RESTORE DATABASE dbrnd
FROM DISK = 'C:\MyBackups\dbrnd.bak'
GO
You can get a below error:
1
2
3
4
Msg 3279, Level 16, State 6, Line 1
Access is denied due to a password failure
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Try to restore with RESTORE HEADERONLY Command:
1
2
RESTORE HEADERONLY
FROM DISK = 'C:\MyBackups\dbrnd.bak'
You can get a below error:
1
2
3
4
Msg 3279, Level 16, State 6, Line 1
Access is denied due to a password failure
Msg 3013, Level 16, State 1, Line 1
RESTORE HEADERONLY is terminating abnormally.
T-SQL Script to restore with password:
1
2
3
4
5
RESTORE DATABASE dbrnd
FROM DISK = 'C:\MyBackups\dbrnd.bak'
MEDIAPASSWORD = 'dbrnd.com',
RECOVERY
GO
Mar 22, 2017Anvesh Patel
SQL Server: Change the default path of Backup directory and Log filesSQL Server: xp_cmdshell and BCP to export table data in a Text File
Comments: 2
  1. pasquale
    March 23, 2017 at 10:18 am

    Hi Anvesh, but beginning with SQL Server 2012, the PASSWORD and MEDIAPASSWORD options are discontinued for creating backups. It is still possible to restore backups created with passwords. So, is it valid until SQL Server 2008R2?

    • Anvesh Patel
      Anvesh Patel
      March 23, 2017 at 6:27 pm

      Yes true, Thank you for adding this. I forgot to add this detail, I am going to update this article by adding that line…

Anvesh Patel
Anvesh Patel

Database Engineer

March 22, 2017 SQL ServerAnvesh Patel, database, database research and development, dbrnd, MEDIAPASSWORD, Password, Protect Database Backup, SQL Query, SQL Server, SQL Server Administrator, SQL Server Error, SQL Server Monitoring, SQL Server Performance Tuning, SQL Server Programming, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....