Recently i needed a simple solutions to backup a couple of files but did not want to spend the money to get azure backup. I am already using azure blob for my offsite/cloud storage, so why won’t i do the same for my linux VM.

  1. Start by adding the ppa for duplicity
    sudo add-apt-repository ppa:duplicity-team/duplicity-release-git
    sudo apt update
    sudo apt install duplicity
    
  2. Install the python addin for azure which we need to connect to our blob storage
    sudo apt install python3-pip
    sudo pip install azure-storage-blob
    
  3. Create an scripts folder in root and backup script
    sudo mkdir /root/scripts
    sudo touch /root/scripts/backup.sh
    
  4. With everything ready we can fill the backup.sh file with the following commands
    #!/bin/sh
    export AZURE_CONNECTION_STRING='<Azure connection string>'
    export PASSPHRASE=<Backup file password>
    duplicity incr --full-if-older-than 1W /path/to/backup/ azure://<containername>
    duplicity remove-older-than 1M azure://<containername>
    unset AZURE_CONNECTION_STRING
    unset PASSPHRASE
    

    Fill in your information on the <> fields. This script will first set 2 variables for the azure connection string and the password used for the backup files. You can find the connection string in your storage account. When you run this script it will create a weekly full backup and delete everthing older than 1 month.

  5. Set up crontab to automate the backups Edit crontab using crontab -e and add the following line:
    0 1 * * * /root/scripts/backup.sh >> /var/log/duplicity/backup.log
    

    The backup script will now be run daily and backup the files to azure blob