Backup your Bluehost server remotely with Ansible

tl;dr I created a simple Ansible playbook to dump databases and folders from a Bluehost shared hosting, ideal for automating backups using a cron job, you can get the source code for this playbook here.

After all the incidents with the Heartbleed bug and security issues, I  decided to audit my servers to spot security flaws, some days ago I started redirecting all the system and application logs to a simple service to centralise all your logs and create alerts, search, store them, etc. After that I started thinking in a better way to secure my information and automate backups of multiple sites and databases I have a across multiple hosting providers.

One of those providers is Bluehost, a very popular shared hosting service. If you have some experience with shared hosting you will know there are things that simply are not possible to do in contrast with a VPS or dedicated server. Nevertheless there is a lot you can do if your provider let you access via ssh. In this post I’ll be showing you how to automate backups using Ansible a simple but powerful tool for managing and automate infrastructure. If you don’t have or dont know how to access Bluehost via ssh, read this guide.

The Bash way

The first thing that came to my mind before Ansible was a bash script a simple script that would be triggered by a cron job in my home server and use mysql-dump via SCP to dump and copy databases backups into my home server and  then rsync to maintain files and folders synced.

The method was fairly simple, but after being working with Ansible for some months I really wanted to create something simpler and cleaner, so after translating that bash script into Ansible  I ended up with this playbook:

If you are curious about the bash script, here is it (it doesn’t have the rsync part for folders, just mysql dump):

Finally if you want to schedule your backups, you can easily trigger this playbook from a cron job like this (put this in the server that will store the backups):

00 1 * * 0    cd /path/to/playbook; ansible-playbook -i hosts bluehostBackup.yml --tags databases folders

Here you can find the full repository:

Let me know what you think in the comments below, and if you have a better ideas to improve it.


Also read...


  1. Database is a very important part of your setup and if you are doing backups, you want to be sure that the database dumps you save are accurate and consistent. You don’t want to be performing database integrity check when a disaster strikes and you need to perform a restore.
    So far I have no experience with `mysql_db: state=dump` to be sure either way, so perhaps until there’s sufficient vetting, it’s safer to use Percona’s Xtrabackup.

  2. To actually “Compress sites folders” you should add -j / -z options. Otherwise it just archive.

    I’m also using Ansible to automate this kind of things (and some more). Nice to read.

  3. Thanks for pointing that out Joan, I have updated the script. Cheers!

Leave a Reply

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