Sunday, March 11, 2012
backup database
I tried to the following but i'm getting an error near '.' Can someone tell
me if this is correct?
Here is my syntax to backup a database from another location:
BACKUP DATABASE [192.168.160.20].Mydatabase TO DISK =
N'\\BACKUPSERVER\Backup\Mydatabase.bak'You cannot server qualify the database for the backup command. Try below:
BACKUP DATABASE Mydatabase TO DISK =
N'\\BACKUPSERVER\Backup\Mydatabase.bak'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Jason" <jasonlewis@.hotrmail.com> wrote in message news:O1OAmoQNFHA.1496@.TK2MSFTNGP10.phx.g
bl...
> Hi,
> I tried to the following but i'm getting an error near '.' Can someone tel
l
> me if this is correct?
> Here is my syntax to backup a database from another location:
> BACKUP DATABASE [192.168.160.20].Mydatabase TO DISK =
> N'\\BACKUPSERVER\Backup\Mydatabase.bak'
>
Saturday, February 25, 2012
backup and resore encrypted data
I have two databases, one production and other a production copy.
One column of the production table is encrypted by the following syntax.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password!'
CREATE CERTIFICATE cert_demo
WITH SUBJECT = 'encryption demo'
CREATE SYMMETRIC KEY symkey_demo
WITH ALGORITHM = TRIPLE_DES
ENCRYPTION BY CERTIFICATE cert_demo
--
I have stored procedure to add records to a production table like this.
ALTER Procedure AddRecord
@.id int,
@.var1 varchar(100)
AS
BEGIN
DECLARE @.var2 varbinary(256)
OPEN SYMMETRIC KEY symkey_demo
DECRYPTION BY CERTIFICATE cert_demo
SET @.var2 = EncryptByKey(
key_guid( 'symkey_demo' ),
@.var1 )
insert into dbo.Test(id,Data,EData)
values(@.id,@.var1,@.var2)
CLOSE SYMMETRIC KEY symkey_demo
END
Now I need to decript the data in the production copy database. So I had export production data to the production copy database and also generates the same key and cerificate. When i tried to decrypt the data, no results has returned.
Create procedure ViewData
@.id int
AS
BEGIN
DECLARE @.var1 varbinary(256)
DECLARE @.var2 varchar(100)
OPEN SYMMETRIC KEY symkey_demo
DECRYPTION BY CERTIFICATE cert_demo
select @.var1=EData from Test where id=@.id
Set @.var2 = convert( varchar(100), DecryptByKey( @.var1))
print @.var2
END
It doesn't print the enctypted data. Please suggest what goes wrong.
The certificate protecting the key encrypting your data is protected by the DB master key (DBMK). In the server where the DBMK was created, the DBMK is protected by the password and by the service master kit (SMK). The SMK protection allows to use the DBMK automatically (i.e. without the need to open the DBMK explicitly).
When you move the DB to a different server, the protection by the SMK is no longer valid, and you need to manually open the DBMK and encrypt it with the current SMK. This is a one-time operation.
OPEN MASTER KEY DECRYPTION BY PASSWORD = '<<password>>'
Go
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
Go
For more detailed information go to BOL:
http://msdn2.microsoft.com/en-us/library/ms174433.aspx
http://msdn2.microsoft.com/en-us/library/ms186937.aspx
Thanks,
-Raul Garcia
SDE/T
SQL Server Engine
|||Thanks Raul.
I had done two things.
1.The service master key doesn't working. So I have to manually open the DBMK and encrypt with the current SMK.
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'password!'
Go
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
2. Again the symmetric key doesn't work.
Because keys cannot be individually backed up and restored, there is no direct way of moving a key from one database to another. However, by specifying the same values for the ALGORITHM, KEY_SOURCE, and IDENTITY_VALUE clauses of CREATE SYMMETRIC KEY, the same key can be generated on different databases.
so I have to change the symmetric key generation code to,
CREATE SYMMETRIC KEY symkey_demo
WITH ALGORITHM = TRIPLE_DES,
identity_value = 'Test Data encryption key',
key_source = 'test key'
ENCRYPTION BY CERTIFICATE cert_demo
Now I backed up the production database and restore it in a different server. I followed the stpe 1 and it works. Now I am able to decrypt the data in the production copy database.
Thanks
Amit
|||I see, when you described a copy of the datbase I assumed (incorrectly) that you were referring to a copy based on a backup.
Thanks a lot for letting us know, and let us know if you have further questions or comments.
-Raul Garcia
SDE/T
SQL Server Engine
backup and resore encrypted data
I have two databases, one production and other a production copy.
One column of the production table is encrypted by the following syntax.
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password!'
CREATE CERTIFICATE cert_demo
WITH SUBJECT = 'encryption demo'
CREATE SYMMETRIC KEY symkey_demo
WITH ALGORITHM = TRIPLE_DES
ENCRYPTION BY CERTIFICATE cert_demo
--
I have stored procedure to add records to a production table like this.
ALTER Procedure AddRecord
@.id int,
@.var1 varchar(100)
AS
BEGIN
DECLARE @.var2 varbinary(256)
OPEN SYMMETRIC KEY symkey_demo
DECRYPTION BY CERTIFICATE cert_demo
SET @.var2 = EncryptByKey(
key_guid( 'symkey_demo' ),
@.var1 )
insert into dbo.Test(id,Data,EData)
values(@.id,@.var1,@.var2)
CLOSE SYMMETRIC KEY symkey_demo
END
Now I need to decript the data in the production copy database. So I had export production data to the production copy database and also generates the same key and cerificate. When i tried to decrypt the data, no results has returned.
Create procedure ViewData
@.id int
AS
BEGIN
DECLARE @.var1 varbinary(256)
DECLARE @.var2 varchar(100)
OPEN SYMMETRIC KEY symkey_demo
DECRYPTION BY CERTIFICATE cert_demo
select @.var1=EData from Test where id=@.id
Set @.var2 = convert( varchar(100), DecryptByKey( @.var1))
print @.var2
END
It doesn't print the enctypted data. Please suggest what goes wrong.
The certificate protecting the key encrypting your data is protected by the DB master key (DBMK). In the server where the DBMK was created, the DBMK is protected by the password and by the service master kit (SMK). The SMK protection allows to use the DBMK automatically (i.e. without the need to open the DBMK explicitly).
When you move the DB to a different server, the protection by the SMK is no longer valid, and you need to manually open the DBMK and encrypt it with the current SMK. This is a one-time operation.
OPEN MASTER KEY DECRYPTION BY PASSWORD = '<<password>>'
Go
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
Go
For more detailed information go to BOL:
http://msdn2.microsoft.com/en-us/library/ms174433.aspx
http://msdn2.microsoft.com/en-us/library/ms186937.aspx
Thanks,
-Raul Garcia
SDE/T
SQL Server Engine
|||Thanks Raul.
I had done two things.
1.The service master key doesn't working. So I have to manually open the DBMK and encrypt with the current SMK.
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'password!'
Go
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
2. Again the symmetric key doesn't work.
Because keys cannot be individually backed up and restored, there is no direct way of moving a key from one database to another. However, by specifying the same values for the ALGORITHM, KEY_SOURCE, and IDENTITY_VALUE clauses of CREATE SYMMETRIC KEY, the same key can be generated on different databases.
so I have to change the symmetric key generation code to,
CREATE SYMMETRIC KEY symkey_demo
WITH ALGORITHM = TRIPLE_DES,
identity_value = 'Test Data encryption key',
key_source = 'test key'
ENCRYPTION BY CERTIFICATE cert_demo
Now I backed up the production database and restore it in a different server. I followed the stpe 1 and it works. Now I am able to decrypt the data in the production copy database.
Thanks
Amit
|||I see, when you described a copy of the datbase I assumed (incorrectly) that you were referring to a copy based on a backup.
Thanks a lot for letting us know, and let us know if you have further questions or comments.
-Raul Garcia
SDE/T
SQL Server Engine
Thursday, February 16, 2012
Backup - filename
I want to get a timestamp in my filename when I take a backup
I have tried the following syntax
=== S T A R T ==
BACKUP DATABASE databas
TO DISK
SELECT 'C:\Backup\database\
+ (CONVERT(char(4), Year(GetDate()))
+ (CONVERT(char(2), Month(GetDate()))
+ (CONVERT(char(2), Day(GetDate()))
+ (CONVERT(char(2), DATEPART(hh, GetDate()))
+ (CONVERT(char(2), DATEPART(hh, GetDate()))
+ '.bak
=== S T A R T ==
When I try to run this I get Incorrect syntax near the keyword 'SELECT'
Anyone who have an idea how to automatic get date and time in the filename
Please reply to may E-mail address so that I don't need to read the news for reply ;-
regard
JohnTry this ir works from Query Anyliser!
declare @.sFile varchar(150);
set @.sFile = 'p:\desktop\test'
+ (CONVERT(char(4), Year(GetDate())))
+ (CONVERT(char(2), Month(GetDate())))
+ (CONVERT(char(2), Day(GetDate())))
+ (CONVERT(char(2), DATEPART(hh, GetDate())))
+ (CONVERT(char(2), DATEPART(hh, GetDate())))
+ '.bak'
BACKUP DATABASE test TO DISK = @.sFile
Cheers!
"John A. Horve" <John.Horve@.kristiansand.kommune.no> wrote in message
news:1EF8E895-AEA1-4DC2-B6EE-57535614C349@.microsoft.com...
> Heillo,
> I want to get a timestamp in my filename when I take a backup.
> I have tried the following syntax:
> === S T A R T ===> BACKUP DATABASE database
> TO DISK => SELECT 'C:\Backup\database\'
> + (CONVERT(char(4), Year(GetDate())))
> + (CONVERT(char(2), Month(GetDate())))
> + (CONVERT(char(2), Day(GetDate())))
> + (CONVERT(char(2), DATEPART(hh, GetDate())))
> + (CONVERT(char(2), DATEPART(hh, GetDate())))
> + '.bak'
> === S T A R T ===> When I try to run this I get Incorrect syntax near the keyword 'SELECT'.
> Anyone who have an idea how to automatic get date and time in the
filename?
> Please reply to may E-mail address so that I don't need to read the news
for reply ;-)
> regards
> John
backup
the db i get the following error ' incorrect syntax near keyword 'disk' '
from the following
use master
exec sp_addumpdevice 'disk', 'mydb_1',
disk = 'd:\data\backup\mydb_1.dat'
backup database mydbTerry,
This is an example from BooksOnLine for sp_addumpdevice:
USE master
EXEC sp_addumpdevice 'disk', 'mydiskdump', 'c:\dump\dump1.bak'
--
Andrew J. Kelly SQL MVP
"Terry" <cooleyt@.woh.rr.com> wrote in message
news:QA1sd.26481$MG3.10582@.fe2.columbus.rr.com...
>i am attempting to move a data base to a new system. when trying to backup
> the db i get the following error ' incorrect syntax near keyword 'disk' '
> from the following
> use master
> exec sp_addumpdevice 'disk', 'mydb_1',
> disk = 'd:\data\backup\mydb_1.dat'
> backup database mydb
>
Tuesday, February 14, 2012
backup
the db i get the following error ' incorrect syntax near keyword 'disk' '
from the following
use master
exec sp_addumpdevice 'disk', 'mydb_1',
disk = 'd:\data\backup\mydb_1.dat'
backup database mydb
Terry,
This is an example from BooksOnLine for sp_addumpdevice:
USE master
EXEC sp_addumpdevice 'disk', 'mydiskdump', 'c:\dump\dump1.bak'
Andrew J. Kelly SQL MVP
"Terry" <cooleyt@.woh.rr.com> wrote in message
news:QA1sd.26481$MG3.10582@.fe2.columbus.rr.com...
>i am attempting to move a data base to a new system. when trying to backup
> the db i get the following error ' incorrect syntax near keyword 'disk' '
> from the following
> use master
> exec sp_addumpdevice 'disk', 'mydb_1',
> disk = 'd:\data\backup\mydb_1.dat'
> backup database mydb
>
Friday, February 10, 2012
Backing up to mirror
BACKUP DATABASE AdventureWorks
TO TAPE = '\\.\tape0'
MIRROR TO TAPE = '\\.\tape1'
MIRROR TO TAPE = '\\.\tape2'
MIRROR TO TAPE = '\\.\tape3'
WITH
FORMAT,
MEDIANAME = 'AdventureWorksSet0'
1. Am I right in thinking that this has nothing to do with database
mirroring? I've never done that either, but I've read that the mirror is
updated through transactions transferred from the database to the mirror, and
also that there can be only one mirror.
2. Can the MIRROR option be set up from the backup dialog screen, or only
through code like the above?> 1. Am I right in thinking that this has nothing to do with database
> mirroring?
Correct. The word mirror is overloaded and user in several independent contexts (just like
"snapshot", "schema" and "meta-data").
> 2. Can the MIRROR option be set up from the backup dialog screen, or only
> through code like the above?
I haven't found a way to do this through the GUI, so TSQL is the way to go.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Bev Kaufman" <BevKaufman@.discussions.microsoft.com> wrote in message
news:EFCC37AA-8F13-49D8-BB54-5C47E2DFA21F@.microsoft.com...
>I am looking at this syntax from Books-Online:
> BACKUP DATABASE AdventureWorks
> TO TAPE = '\\.\tape0'
> MIRROR TO TAPE = '\\.\tape1'
> MIRROR TO TAPE = '\\.\tape2'
> MIRROR TO TAPE = '\\.\tape3'
> WITH
> FORMAT,
> MEDIANAME = 'AdventureWorksSet0'
> 1. Am I right in thinking that this has nothing to do with database
> mirroring? I've never done that either, but I've read that the mirror is
> updated through transactions transferred from the database to the mirror, and
> also that there can be only one mirror.
> 2. Can the MIRROR option be set up from the backup dialog screen, or only
> through code like the above?