Create an Automated Backup System with Azure
Set Up Azure Blob Storage
Go to Azure Portal: https://portal.azure.com
Create a Storage Account:
- Click Create a Resource > Storage > Storage Account
- Use Standard performance and Hot access tier for frequent access
Create a Container:
- After the storage account is deployed, go to it and select Containers
- Add a new container (e.g., backups)
- Set public access to Private
Create an Azure Function
Create a Function App:
- Go to Create a resource > Compute > Function App
- Choose Python 3.10, use Consumption Plan to save costs
Deploy Code:
- Use VS Code with the Azure Functions Extension
- Create a new function with an HTTP trigger
- Example Python code to back up a file:
import logging
import azure.functions as func
from azure.storage.blob import BlobServiceClient
import os
def main(req: func.HttpRequest) -> func.HttpResponse:
file_name = req.params.get('file')
if not file_name:
return func.HttpResponse("Please pass the file name as ?file=", status_code=400)
connection_str = os.getenv("AzureWebJobsStorage")
blob_service_client = BlobServiceClient.from_connection_string(connection_str)
container_client = blob_service_client.get_container_client("backups")
# Simulate local file (replace with real file path or stream)
local_path = f"/home/site/wwwroot/temp/{file_name}"
if not os.path.exists(local_path):
return func.HttpResponse(f"{file_name} not found", status_code=404)
with open(local_path, "rb") as data:
container_client.upload_blob(name=file_name, data=data, overwrite=True)
return func.HttpResponse(f"{file_name} backed up successfully.")
Set Environment Variable:
Add AzureWebJobsStorage in your Function App’s configuration (it's already set if you chose a storage account during creation)
Automate It with Logic Apps
If you want a no-code trigger, use Azure Logic Apps to call your function on a schedule.
Go to Logic Apps > Create
Select Blank Logic App
Add a Recurrence trigger (e.g., daily at 2 AM)
Add HTTP action:
- Method: GET
- URL: Your function URL (include ?file=filename.txt)
Save and Test
Test the Backup System
Upload a file to your local directory or GitHub
Call your function URL (via browser or Logic App)
Go to your Azure Blob Storage > Container
Confirm the file was uploaded