create encrypted database backup (1 Viewer)

aman

Registered User.
Local time
Yesterday, 17:14
Joined
Oct 16, 2008
Messages
1,250
Hi Guys

I am using the following script to create encrypted database backups in SQL Server but I am getting an error message

"Msg 3032, Level 16, State 2, Line 1
One or more of the options (mediapassword) are not supported for this statement. Review the documentation for supported options."


Code:
BACKUP DATABASE AdventureWorks
TO DISK='C:\AdventureWorks.BAK'
WITH MEDIAPASSWORD='C0mplexP@ssW0rd'
GO

Any help will be much appreciated.
 

isladogs

MVP / VIP
Local time
Today, 01:14
Joined
Jan 14, 2017
Messages
18,209
Just a guess but the issue may be nothing to do with encryption.
Try changing the destination path so it's not pointing to the root C drive
 

aman

Registered User.
Local time
Yesterday, 17:14
Joined
Oct 16, 2008
Messages
1,250
This is m exact code but it gives me the same error message :
Code:
BACKUP DATABASE Test_Aman
TO DISK='\\Corpfiler1\Data\Access Databases\Group Manufacturing\Test_Aman.BAK'
WITH MEDIAPASSWORD='C0mplexP@ssW0rd'
GO
 

isladogs

MVP / VIP
Local time
Today, 01:14
Joined
Jan 14, 2017
Messages
18,209
It would have helped if you had posted that originally as the original was misleading....;)

I've not used MEDIAPASSWORD in my backups and according to this link, it is no longer supported:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2737fefd-1060-4424-8174-a1c5bd075b5a/sql-server-2014-set-password-for-backup-file?forum=sqlkjmanageability

FWIW, I use connection strings including SQL passwords with passthrough queries for the purpose. Example of my code:
Code:
  qdfPassThrough.SQL = "BACKUP DATABASE [" & GetSchConstantsValue("strSQLDatabase") & "]" & _
                                " TO DISK = N'" & CurrentDBDir & "SDABE_FullDBBackup_" & _
                                    strBackupDateTime & ".BAK'" & _
                                " WITH NOFORMAT," & _
                                " NOINIT," & _
                                " NAME = N'" & GetSchConstantsValue("strSQLDatabase") & "-Full Database Backup'," & _
                                " SKIP," & _
                                " NOREWIND," & _
                                " NOUNLOAD," & _
                                " STATS = 1;"
                                
                strBackupName = "SDABE_FullDBBackup_"

See if this link helps you find a solution:
https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/create-an-encrypted-backup?view=sql-server-2017
 
Last edited:

Minty

AWF VIP
Local time
Today, 01:14
Joined
Jul 26, 2013
Messages
10,366
Depending on youtr SQL version From Microsoft ;
Beginning with SQL Server 2012 (11.x), the PASSWORD and MEDIAPASSWORD options are discontinued for creating backups. It is still possible to restore backups created with passwords.

Even if that doesn't apply I don't think you can specify a mediapassword on a non media set - you would have to set the destination as a media set.

Have a good read here https://docs.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql?view=sql-server-2017

Edit : Dam Ridders faster fingers....
 

Albert Dicosta

Registered User.
Local time
Yesterday, 17:14
Joined
Sep 7, 2018
Messages
16
Try this way:
BACKUP LOG [db name] WITH NO_LOG
DBCC SHRINKFILE ([log file logical name], [new size in Mb])
 

Users who are viewing this thread

Top Bottom