Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions CreateALogBackupToAzureBlobStorage_OutilDUrgence.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
SET NOCOUNT ON

-- Backup all databases already backuped in Azure.
-- Script is mirroring aware
-- Do not run the script within the same second otherwise backupschain could be mixed up and unuseable


-- The script won't work if any of the following is true:
-- - The database has never been backup yet to Azure using smart backups
-- - The database had a guid fork and no backup was yet done to Azure using smart backups
-- - Smart backup configuration is not set properly
-- - Azure Data storage does not exist
-- - Database recovery model is not set to FULL


------------------------------------------------------
-- Start configuration section

DECLARE @IsFullBackup AS BIT = 0 -- 0 = Log backup, 1 = Full backup

-- End configuration section
------------------------------------------------------


-- Validation

IF (@IsFullBackup IS NULL)
BEGIN
RAISERROR ('Configuration @IsFullBackup cannot be NULL. Allowed configuration: 0 = Log backup, 1 = Full backup.', 16, 1)
RETURN
END



-- Do not change the remainder configuration

DECLARE @DebugMode AS BIT = 0

DECLARE @StorageURLPrefix AS NVARCHAR(MAX) = 'https://'
DECLARE @StorageURLSuffixe AS NVARCHAR(MAX) = '.blob.core.windows.net/'

DECLARE @BackupFileExtension AS NVARCHAR(3) = 'log'
DECLARE @BackupCommandType AS NVARCHAR(8) = 'LOG'
DECLARE @BackupHeaderNameBackupType AS NVARCHAR(4) = 'LOG'

DECLARE @QueryToExecuteBackup AS NVARCHAR(MAX)
DECLARE @CurrentDateForBackup AS DATETIME2(0) = GETDATE()
DECLARE @FormattedCurrentDateForBackup AS NVARCHAR(25) = FORMAT(@CurrentDateForBackup, 'yyyyMMddHHmmss')

DECLARE @GuidLength AS INT = 32



IF (@IsFullBackup = 1)
BEGIN
SET @BackupFileExtension = 'bak'
SET @BackupCommandType = 'DATABASE'
SET @BackupHeaderNameBackupType = 'FULL'
END

SELECT
@QueryToExecuteBackup = CONCAT(@QueryToExecuteBackup,
'
BACKUP ', @BackupCommandType, ' [', frmGetDBUrl.[name], '] TO URL = N''', frmGetDBUrl.FullFileNameToUrl ,''' WITH CREDENTIAL = N''AutoBackup_Credential'' , NOFORMAT, NOINIT, NAME = N''', frmGetDBUrl.[name], '-', @BackupHeaderNameBackupType, ' Database Backup'', NOSKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10, CHECKSUM')

FROM (

SELECT
databases.[name]
, CONCAT(@StorageURLPrefix, caGetLastestBackupInfo.AzureStorageKey, @StorageURLSuffixe, LOWER(@@SERVERNAME), '-mssqlserver/', databases.[name], '_', caGetLastestBackupInfo.LastestBackupGUID, '_', @FormattedCurrentDateForBackup, LEFT(RIGHT(SYSDATETIMEOFFSET(), 6), 3), '.', @BackupFileExtension) AS 'FullFileNameToUrl'

FROM
sys.databases

CROSS APPLY (

SELECT TOP 1
SUBSTRING(backupmediafamily.physical_device_name, PATINDEX(CONCAT('%', backupset.database_name, '_%'), backupmediafamily.physical_device_name) + LEN(backupset.database_name) + 1, 32) AS 'LastestBackupGUID'
, SUBSTRING(backupmediafamily.physical_device_name, LEN(@StorageURLPrefix) + 1, PATINDEX(CONCAT('%', @StorageURLSuffixe, '%'), backupmediafamily.physical_device_name) - LEN(@StorageURLPrefix) - 1) AS 'AzureStorageKey'

FROM
msdb.dbo.backupmediafamily

INNER JOIN msdb.dbo.backupset
ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id

WHERE
backupset.database_name = databases.[name]
AND backupmediafamily.physical_device_name LIKE CONCAT(@StorageURLPrefix, '%')
AND backupset.is_copy_only = 0

ORDER BY
backupset.backup_finish_date DESC

) caGetLastestBackupInfo

WHERE
databases.state_desc = 'ONLINE'
AND databases.recovery_model_desc = 'FULL'

) frmGetDBUrl
OPTION (RECOMPILE)


PRINT @QueryToExecuteBackup
PRINT ''
IF (@DebugMode = 0) EXEC sp_executeSQL @QueryToExecuteBackup

41 changes: 41 additions & 0 deletions Fondation_Anonymized.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--** Script Fondation_Anonymized

SET XACT_ABORT ON
SET NOCOUNT ON



IF(DB_NAME() NOT LIKE '%Foundation')
BEGIN
RAISERROR ('This is not a foundation database.', 16, 1)
RETURN
END



BEGIN TRANSACTION


UPDATE dbo.[Provider]
SET ProviderDetails.modify('replace value of (/Provider/Values/UserName/text())[1] with "[email protected]"')
WHERE
[Provider].[name] = 'SmtpMailProvider' and [Provider].[ImplementationTypeName] = 'SmtpMailProvider'

UPDATE dbo.[Provider]
SET ProviderDetails.modify('replace value of (/Provider/Values/Password/text())[1] with "3ye3bSOqMcVi8mr7"')
WHERE
[Provider].[name] = 'SmtpMailProvider' and [Provider].[ImplementationTypeName] = 'SmtpMailProvider'

UPDATE dbo.[Provider]
SET ProviderDetails.modify('replace value of (/Provider/Values/SenderAddress/text())[1] with "Customer COmpany Name Test <[email protected]>"')
WHERE
[Provider].[name] = 'SmtpMailProvider' and [Provider].[ImplementationTypeName] = 'SmtpMailProvider'

UPDATE dbo.[Provider]
SET ProviderDetails.modify('replace value of (/Provider/Values/TemporaryPassword/text())[1] with "Qwerty123!"')
WHERE
[Provider].[name] = 'AzureDirectoryProvider' and [Provider].[ImplementationTypeName] = 'AzureDirectoryProvider'

COMMIT
GO

138 changes: 138 additions & 0 deletions Order_Anonymized.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
--** Script Order_Anonymized

SET XACT_ABORT ON
SET NOCOUNT ON


--*************************************************************
-- *** Configuration Section
-- *** Modify the variables in this section foy your needs
--*************************************************************



-- START OF CONFIGURATION SECTION

-- ***********************************************************************************************
-- ***********************************************************************************************

-- Did you ran Profile_Anonymized.sql first?

-- Nothing to configure here,
-- Will run with the choice of one or all customer_id selected in the Profile_Anonymized script

-- END OF CONFIGURATION SECTION

-- ***********************************************************************************************
-- ***********************************************************************************************












-- ********************************
-- *** Start of Program
-- ********************************



--***********************************************************
-- *** If not connected to the right Database, script exits
-- **********************************************************
IF(DB_NAME() NOT LIKE '%Order')
BEGIN
RAISERROR ('This is not an order database.', 16, 1)
RETURN
END



--****************************************************************
-- *** If no CustomerProfileToAnonymize table found, script exists
-- ***************************************************************
IF OBJECT_ID('tempdb..##CustomerProfileToAnonymize') IS NULL
BEGIN
RAISERROR ('You have to run Profile_Anonymized script first', 16, 1)
RETURN
END



-- **********************************************************************************
-- *** Update the ORDER table to anonymized colums related to customer(s) selected
-- **********************************************************************************
UPDATE [ORDER] SET
[ORDER].Email = CONCAT(CustomerProfileToAnonymize.CustomerEntityName, ' ', [ORDER].OrderNumber, CustomerProfileToAnonymize.AnonymizedFakeEmailSuffixe)
, [ORDER].CustomerPhone = CustomerProfileToAnonymize.AnonymizedPhoneNumber
, [ORDER].CustomerName = CONCAT(CustomerProfileToAnonymize.CustomerEntityName, ' ', [ORDER].OrderNumber)

FROM
dbo.[ORDER]

INNER JOIN
##CustomerProfileToAnonymize CustomerProfileToAnonymize
ON CustomerProfileToAnonymize.Id = [ORDER].Customer_Id
OPTION (RECOMPILE)




-- *****************************************************************************************
-- *** Update the SHIPMENTADDRESS table to anonymized colums related to customer(s) selected
-- *****************************************************************************************
UPDATE SHIPMENTADDRESS SET
SHIPMENTADDRESS.LastName = CONCAT(CustomerProfileToAnonymize.CustomerEntityName, ' ', SHIPMENTADDRESS.TransactionOrderNumber)
, SHIPMENTADDRESS.FirstName = CONCAT(CustomerProfileToAnonymize.CustomerEntityName, ' ', SHIPMENTADDRESS.TransactionOrderNumber)
, SHIPMENTADDRESS.PhoneNumber = CustomerProfileToAnonymize.AnonymizedPhoneNumber

FROM
dbo.SHIPMENTADDRESS

INNER JOIN
dbo.[ORDER]
ON [ORDER].TransactionOrderNumber = SHIPMENTADDRESS.TransactionOrderNumber

INNER JOIN
##CustomerProfileToAnonymize CustomerProfileToAnonymize
ON CustomerProfileToAnonymize.Id = [ORDER].Customer_Id
OPTION (RECOMPILE)




-- ****************************************************************************************
-- *** Update the PAYMENTADDRESS table to anonymized colums related to customer(s) selected
-- ****************************************************************************************
UPDATE PAYMENTADDRESS SET
PAYMENTADDRESS.LastName = CONCAT(CustomerProfileToAnonymize.CustomerEntityName, ' ', PAYMENTADDRESS.TransactionOrderNumber)
, PAYMENTADDRESS.FirstName = CONCAT(CustomerProfileToAnonymize.CustomerEntityName, ' ', PAYMENTADDRESS.TransactionOrderNumber)
, PAYMENTADDRESS.PhoneNumber = CustomerProfileToAnonymize.AnonymizedPhoneNumber

FROM
dbo.PAYMENTADDRESS

INNER JOIN
dbo.[ORDER]
ON [ORDER].TransactionOrderNumber = PAYMENTADDRESS.TransactionOrderNumber

INNER JOIN
##CustomerProfileToAnonymize CustomerProfileToAnonymize
ON CustomerProfileToAnonymize.Id = [ORDER].Customer_Id




-- *************************************************************
-- *** The temporary table CustomerProfileToAnonymize is dropped
-- *** It is no longger needed
-- *************************************************************
IF OBJECT_ID('tempdb..##CustomerProfileToAnonymize') IS NOT NULL
DROP TABLE ##CustomerProfileToAnonymize
GO
64 changes: 64 additions & 0 deletions PanoptaSQLSmartBackupCheck.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
DECLARE @TimeBeforeExpiration AS DATETIME2(3) = DATEADD(HOUR, -24, GETDATE())

SELECT
databases.name AS 'DatabaseName'
, CASE WHEN oaBackupExist.Exist = 1 THEN 1 ELSE 0 END AS 'UseableBackupExist'

FROM
sys.databases

OUTER APPLY (

SELECT TOP 1
1 AS 'Exist'
, fab.backup_finish_date

FROM
msdb.smart_admin.fn_available_backups(databases.name) fab

WHERE
fab.backup_finish_date >= @TimeBeforeExpiration

ORDER BY
fab.backup_finish_date DESC

) oaGetBackupStatus

OUTER APPLY (

SELECT TOP 1
1 AS 'Exist'
, smart_backup_files.backup_finish_date

FROM
msdb.dbo.smart_backup_files

WHERE
smart_backup_files.[status] = 'A'
AND smart_backup_files.database_name = databases.name
AND smart_backup_files.backup_finish_date >= @TimeBeforeExpiration

ORDER BY
smart_backup_files.last_modified_utc DESC

) oaBackupExist

WHERE
databases.state_desc = 'ONLINE'
AND (
databases.[name] LIKE '%foundation' OR
databases.[name] LIKE '%marketing' OR
databases.[name] LIKE '%membership' OR
databases.[name] LIKE '%messaging' OR
databases.[name] LIKE '%order' OR
databases.[name] LIKE '%pickandpack' OR
databases.[name] LIKE '%pnp' OR
databases.[name] LIKE '%product' OR
databases.[name] LIKE '%profile' OR
databases.[name] LIKE '%Archive' OR
databases.[name] LIKE '%Reporting' OR
databases.[name] LIKE '%DataWarehouse'
)

ORDER BY
databases.[name]
Loading