为网站项目创建Azure数据库后,咨询备份管理及导入导出方法
Hey Steven, let’s walk through everything you need to know about managing backups for your Azure database, plus how to handle import and export operations—super practical stuff for keeping your data safe and flexible.
Automated Backups (The "Set It and Forget It" Option)
Azure’s automated backups are your first line of defense, running in the background without manual intervention. Here’s what you should know:
- Backup Types: Azure automatically creates weekly full backups, 12-hour differential backups, and transaction log backups every 5-10 minutes. This combination lets you restore your database to almost any point in time within your retention window.
- Retention Periods: The default window varies by your database tier: Basic tier gets 7 days, Standard/Premium tiers go up to 35 days. You can extend this with Long-Term Retention (LTR) to store backups for up to 10 years—just head to your database in the Azure Portal, navigate to Backups > Backup Policy, and adjust the retention settings.
- Redundancy Options: Choose between Local Redundant Storage (LRS) for cost-effective, same-region backups, or Geo-Redundant Storage (GRS) to replicate backups to a secondary region for disaster recovery peace of mind.
Manual Backups (On-Demand Snapshots)
For scenarios like pre-deployment checks or one-off data snapshots, you can trigger manual backups:
- Azure Portal: Go to your database > Backups > Backup Now, set a retention period (up to 10 years), and confirm.
- Azure CLI: Run this command to create a full backup:
az sql db backup create --resource-group <your-rg-name> --server <your-server-name> --name <your-db-name> --backup-type full - PowerShell: Use this cmdlet:
New-AzSqlDatabaseBackup -ResourceGroupName <your-rg-name> -ServerName <your-server-name> -DatabaseName <your-db-name>
Restoring from Backups
Restoring is just as important as backing up. Here are the common scenarios:
- Point-in-Time Restore: If you need to roll back to a specific moment (say, before an accidental data deletion), use this option. In the Portal, select your database > Restore, choose the target time, configure a new database name, and launch the restore.
- Restore Deleted Databases: If you accidentally drop a database, head to your SQL Server resource > Deleted Databases, select the one you need, and restore it to a new or existing server.
- Long-Term Retention Restore: For backups stored in LTR, go to your database > Backups > Long-Term Retention, select the backup snapshot, and restore it to a target server.
Exporting a Backup to Azure Blob Storage
Exporting creates a .bacpac file (a data-level backup with schema and data) and saves it to Azure Blob Storage—great for migrations or offline archiving:
- Azure Portal: Go to your database > Export, select your target storage account and container, name the
.bacpacfile, enter your SQL admin credentials, and start the export. - Azure CLI: Use this command to trigger an export:
az sql db export --resource-group <your-rg-name> --server <your-server-name> --name <your-db-name> --storage-key-type StorageAccessKey --storage-key <your-storage-key> --storage-uri https://<storage-account>.blob.core.windows.net/<container>/<backup-name>.bacpac - Pro Tip: If your database is over 200GB,
.bacpacexports might hit limits—consider using Azure Data Factory or database replication tools instead.
Importing a .bacpac Backup to Azure
To bring a .bacpac file into a new or existing Azure database:
- Azure Portal: Go to your target SQL Server > Import Database, select the
.bacpacfile from your storage account, set the target database name and service tier, enter admin credentials, and start the import. - Azure CLI: Run this command to initiate the import:
az sql db import --resource-group <your-rg-name> --server <your-server-name> --name <target-db-name> --storage-key-type StorageAccessKey --storage-key <your-storage-key> --storage-uri https://<storage-account>.blob.core.windows.net/<container>/<backup-name>.bacpac - Key Notes: Make sure your target server’s service tier has enough storage to accommodate the imported data. You can monitor progress in the Azure Portal’s Activity Log or with
az sql db operation listin the CLI.
Quick Best Practices
- Always test restores periodically—backups are useless if you can’t restore them!
- For large databases, schedule exports during off-peak hours to avoid performance hits.
- Restrict storage account access to only the users/services that need to handle backups.
内容的提问来源于stack exchange,提问作者steven

