How to automate in taking backup of a required table in sql datawarehouse by using ADF?
Loading
How to automate in taking backup of a required table in sql datawarehouse by using ADF?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Jan 30, 2025, 6:49 AM EST
To automate table backups in Azure SQL Data Warehouse (now Azure Synapse Analytics) using Azure Data Factory (ADF) we need to follow few things:
1. Backup Strategy
Use stored procedures to create timestamped backup tables, then orchestrate them via ADF.
2. Implementation Steps
A. Create Backup Stored Procedure
CREATE PROCEDURE [dbo].[sp_BackupTable] @SourceTableName NVARCHAR(128), @BackupSuffix NVARCHAR(50) AS BEGIN DECLARE @BackupTableName NVARCHAR(128) = @SourceTableName + '_Backup_' + @BackupSuffix; DECLARE @Sql NVARCHAR(MAX) = ' IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = ''' + @BackupTableName + ''') CREATE TABLE ' + QUOTENAME(@BackupTableName) + ' WITH (DISTRIBUTION = ROUND_ROBIN) AS SELECT * FROM ' + QUOTENAME(@SourceTableName) + ' WHERE 1 = 0; -- Create empty table INSERT INTO ' + QUOTENAME(@BackupTableName) + ' SELECT * FROM ' + QUOTENAME(@SourceTableName) + '; '; EXEC sp_executesql @Sql; ENDB. ADF Pipeline Setup
Linked Services
Configure connections to:
Azure Synapse Analytics (SQL Data Warehouse)
Azure Storage (for logging, optional)
Parameters
Add pipeline parameters:
- tableName: Your source table name - backupSuffix: Timestamp (dynamic)Pipeline Activities
Use this sequence:
- Stored Procedure:
[dbo].[sp_BackupTable]- Parameters:
@SourceTableName = @pipeline().parameters.tableName,@BackupSuffix = @pipeline().parameters.backupSuffixC. Dynamic Timestamp Handling
Use ADF expressions for dynamic naming:
D. Automation & Scheduling
Trigger
Create a scheduled trigger:
Daily/weekly backups
Time zone aware
Retention Policy
Add a cleanup step to delete backups older than
Ndays:DELETE FROM [dbo].[TableBackupLog] WHERE BackupDate < DATEADD(day, -30, GETDATE())3. Key Considerations
WHEREclauses with watermark columns for delta loads.db_ddladminanddb_datawriterroles.Failurepath + retry policies.4. Sample Pipeline JSON
{ "name": "BackupPipeline", "properties": { "activities": [ { "name": "ExecuteBackupSP", "type": "SqlServerStoredProcedure", "linkedServiceName": { "referenceName": "AzureSynapseLS", "type": "LinkedServiceReference" }, "typeProperties": { "storedProcedureName": "[dbo].[sp_BackupTable]", "storedProcedureParameters": { "SourceTableName": { "value": "@pipeline().parameters.tableName", "type": "String" }, "BackupSuffix": { "value": "@pipeline().parameters.backupSuffix", "type": "String" } } } } ], "parameters": { "tableName": { "type": "String" }, "backupSuffix": { "type": "String", "defaultValue": "@formatDateTime(utcnow(), 'yyyyMMdd_HHmmss')" } } } }Jayraj ChhayaRank #304 · 8.2K reputationPosted Jan 30, 2025, 1:37 AM EST
Hi @Tharunkumar Magudeeswaran,
To automate the backup of a required table in Azure SQL Data Warehouse using Azure Data Factory (ADF), you can follow these steps:
Create a Data Factory: If you haven't already, create an Azure Data Factory instance in the Azure portal.
Set Up Linked Services: Configure linked services for both your source SQL Data Warehouse and the destination where you want to store the backup (e.g., Azure Blob Storage).
Create a Pipeline: In ADF, create a new pipeline. Use the "Copy Data" activity to copy data from the source table to the destination.
Configure the Copy Activity:
Schedule the Pipeline: Use the ADF trigger feature to schedule the pipeline to run at your desired frequency (e.g., daily, weekly).
Here’s a simple example of a copy activity configuration in JSON:
{ "name": "CopyTableBackup", "type": "Copy", "inputs": [ { "referenceName": "SourceTable", "type": "DatasetReference" } ], "outputs": [ { "referenceName": "BackupBlob", "type": "DatasetReference" } ], "source": { "type": "SqlSource" }, "sink": { "type": "BlobSink" } }By following these steps, you can effectively automate the backup process of your SQL Data Warehouse table using Azure Data Factory.