0

I want to automate the backup my azure Postgresql flex databases to azure fileshares named as ex:"backup_psql" within Azure Storage account?. The backup should take place at certain interval. The expected architecture is given bellow. The storage account and file share i have created using terraform. Now how can i run the backup process automatically? I really appreciate your suggestions

enter image description here

Create a azure storgae account using terraform

# Create a storgae account
resource "azurerm_storage_account" "backup_storage" {
  #name                    = "pssql_storage"
  name                     = var.storage_account
  resource_group_name      = data.azurerm_resource_group.rg_pssql_flex.name
  location                 = data.azurerm_resource_group.rg_pssql_flex.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
  min_tls_version          = "TLS1_2"

  queue_properties {
    logging {
      delete                = true
      read                  = true
      write                 = true
      version               = "1.0"
      retention_policy_days = 10
    }
  }
}

Create a file share using terraform

resource "azurerm_storage_share" "backup_storage_share" {
  name                 = local.azure_storage_share_name
  storage_account_name = azurerm_storage_account.backup_storage.name
  quota                = var.backup_storage_quota

}

eku
  • 11
  • 1
  • 2
  • 6
  • Can you complete the backup from Azure Database to Azure Storage through some commands or scripts on the local machine? If you can do it manually locally, you can also migrate to other services to do it automatically. – Ziyang Liu-MSFT Nov 15 '22 at 05:41
  • Yes I can do that using bash command on my local machine which is manual and download the dump once and after the restore using another bash command. but i need a script which automatically does the backup and restore process after certain interval – eku Nov 15 '22 at 08:38
  • # Download database from the postgresql using local terminal ** pg_dump -Fc -v --host=postgressqlflex-server.postgres.database.azure.com --username=admin --dbname=testdb -f testdb.dump ** # Restore database from the postgresql local terminal ** pg_restore -v --no-owner --host=postgressqlflex-server.postgres.database.azure.com --port=5432 --username=admin --dbname=testdb tesdb.dump ** – eku Nov 15 '22 at 08:38
  • If you can use bash command at your local machine, you can try to run the same command in [Bash task](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops) in the DevOps pipeline. – Ziyang Liu-MSFT Nov 17 '22 at 07:53
  • Besides, Azure CLI can be used to backup SQL to Azure Storage, and you can use [Azure CLI task](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops) in the DevOps pipeline to do what you want automatically. For detailed info, please refer to [Backup an Azure SQL single database to an Azure storage container using the Azure CLI](https://learn.microsoft.com/en-us/azure/azure-sql/database/scripts/backup-database-cli?view=azuresql) – Ziyang Liu-MSFT Nov 17 '22 at 07:54

0 Answers0