How to Mount Azure Files on Linux and Sync Data with Rsync

Microsoft Azure Files provides cloud-based SMB/NFS file shares that can be integrated with Linux systems. This guide covers mounting Azure Files on Ubuntu using SMB/CIFS, automating sync with rsync for backups, and troubleshooting common issues.

Prerequisites:

  • An Azure Storage Account with a file share created
  • A Linux machine (tested on Ubuntu/Debian)
  • cifs-utils package for SMB mounting

First, install the required tools by running:
sudo apt update && sudo apt install cifs-utils -y

Next, securely store your Azure credentials by creating a file at /etc/smbcredentials/azure.cred with these contents:

username=yourstorageaccount
password=your-access-key

Set proper permissions on the credentials file:
sudo chmod 600 /etc/smbcredentials/azure.cred

Create a mount point directory:

sudo mkdir -p /media/azure-backup

Mount the Azure file share using:

sudo mount -t cifs //yourstorage.file.core.windows.net/sharename /media/azure-backup -o vers=3.0,credentials=/etc/smbcredentials/azure.cred,uid=(id−u),gid=(id−u),gid=(id -g),dir_mode=0755,file_mode=0755

To make the mount persistent across reboots, add this line to /etc/fstab:

//yourstorage.file.core.windows.net/sharename /media/azure-backup cifs vers=3.0,credentials=/etc/smbcredentials/azure.cred,uid=1000,gid=1000,dir_mode=0755,file_mode=0755 0 0

Verify the fstab entry works with:

sudo mount -a

For syncing data with rsync, first test with a dry run:

rsync -avzh --dry-run --progress /local/data/ /media/azure-backup/

When ready, perform the actual sync:

rsync -avzh --progress /local/data/ /media/azure-backup/

To exclude certain files from syncing:

rsync -avzh --exclude='*.tmp' --exclude='temp/' /local/data/ /media/azure-backup/

For automated daily syncs, edit crontab with crontab -e and add:

0 3 * * * rsync -avzh --delete /local/data/ /media/azure-backup/ >> /var/log/azure-sync.log 2>&1

Note on the --delete Flag: The rsync commands in this guide intentionally omit the --delete flag, which means files deleted from your local drive will not be automatically removed from your Azure backup. This is a safer default for most backup scenarios, as it prevents accidental data loss if files are deleted locally. However, be aware that over time this may lead to increased storage usage in Azure, as obsolete files accumulate. If you prefer a true mirror where the backup exactly matches your local drive (including deletions), you can add --delete to the rsync command. For example: rsync -avzh --progress --delete /local/data/ /media/azure-backup/. Always test with --dry-run first when using --delete to verify which files would be removed. For long-term backup strategies, consider combining approaches – perhaps maintaining multiple backup sets with some that prune deleted files and others that preserve all versions indefinitely.

Common troubleshooting solutions:

  • “No route to host”: Check Azure Firewall allows port 445
  • “Permission denied”: Remount with proper uid/gid parameters
  • Slow transfers: Use –bwlimit=5000 or switch to AzCopy
  • Rsync failures: Use –partial flag to resume interrupted transfers
  • Unmount issues: Use lsof +D /media/azure-backup or umount -l

Alternative methods include:

This configuration creates a reliable cloud backup solution by combining Azure Files with Linux tools. Always verify with dry runs first, monitor logs, and consider AzCopy for large transfers. For enterprise use, explore Azure Private Link for enhanced security or NFS options for Linux-centric workflows.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *