如何为Azure File Storage(v1)添加可靠版本控制支持
Great question—since Azure Blob Storage’s soft delete doesn’t fit your workflow and you’re committed to Azure File Storage, let’s break down practical, production-ready options to add version control similar to AWS S3. I’ll cover three approaches with clear tradeoffs to match your needs:
1. Custom Versioning Workflow with Azure Automation + Event Grid
This approach lets you build a fully customizable versioning system using native Azure services, no external tools required.
How to implement:
- Set up a "version archive" file share: Create a dedicated share in your Azure File Storage account to store historical versions (e.g.,
file-versions). - Configure Event Grid triggers: Set up an Event Grid subscription to listen for
FileCreated,FileUpdated, andFileDeletedevents on your primary file share. - Build an Azure Automation Runbook: Write a PowerShell or Python runbook that:
- On file creation/update: Copies the file to the archive share with a versioned filename (e.g.,
vacation-photo.jpg-20240520-1430-v1). Track version numbers via metadata tags on the original file or a simple counter in the runbook. - On file deletion: Moves the deleted file to the archive share (or copies it first if you want to retain the "deleted" version alongside updates).
- On file creation/update: Copies the file to the archive share with a versioned filename (e.g.,
- Add cleanup logic: Include a scheduled runbook to delete old versions after a set retention period (e.g., 90 days) to control storage costs.
Pros & Cons:
- ✅ Fully customizable to match S3-like versioning behavior
- ✅ Uses native Azure services, no third-party dependencies
- ❌ Requires writing and maintaining runbook code
- ❌ Manual setup for event triggers and permissions
2. Azure File Sync with Restore Points
If you want a low-code solution, Azure File Sync includes built-in versioning capabilities via file restore points that can recover deleted or overwritten files.
How to implement:
- Create an Azure File Sync service: Provision a sync service in your Azure region.
- Set up a sync group: Link your existing Azure File Storage share to the sync group (you don’t need a local server unless you’re syncing on-prem files).
- Enable restore points: In the sync group settings, turn on "File restore points" and set a retention period (e.g., 30 days). Azure will automatically capture point-in-time snapshots of your share.
- Restore files: When you need to recover a version, use the Azure portal or Azure CLI to restore a specific restore point, or pull individual files from the snapshot.
Pros & Cons:
- ✅ Zero custom code required—native Azure feature
- ✅ Easy to set up and manage via the portal
- ❌ Restore points are time-based, not per-file version (you can’t see every single edit, just snapshots at intervals)
- ❌ Retention periods are limited to a maximum of 100 days
3. Git LFS + Azure Repos (Refined Collaborative Workflow)
Your initial idea of Git LFS with Azure Repos (VST) can work—here’s how to refine it for a file storage use case:
How to implement:
- Create an Azure Repos repository: Set up a new repo and enable Git LFS to handle large binary files (images, PDFs).
- Map your file storage to the repo: Use a script or Azure Function to sync files between your Azure File Storage share and the Git LFS repo. For example:
- When a file is added/updated in the share, trigger a function to commit it to the repo with a meaningful message (e.g., "Updated invoice.pdf - 2024-05-20").
- Use branch protection rules to require pull requests and approvals before merging changes to the main branch, preventing accidental overwrites.
- Restore versions: To recover an old version, clone the repo, check out the specific commit, and sync the file back to your Azure File Storage share.
Pros & Cons:
- ✅ Full version history with commit messages, branches, and approval workflows
- ✅ Integrates with Azure DevOps tools for collaboration
- ❌ Git LFS can struggle with extremely large file sets (1000s of GBs) due to performance overhead
- ❌ Requires your team to be familiar with Git workflows
Which Option Should You Choose?
- Go with Azure File Sync Restore Points if you want minimal setup and just need to recover from accidental deletes/overwrites.
- Choose Azure Automation + Event Grid if you need precise, S3-like per-file versioning with custom retention rules.
- Use Git LFS + Azure Repos if you need collaborative version control with approval processes for file changes.
内容的提问来源于stack exchange,提问作者Dan Csharpster

