Skip to content

Ansible playbook that takes AWS RDS, EFS and EC2 snapshots and application(Neo4j DB) backup in parallel

License

Notifications You must be signed in to change notification settings

sanket-bengali/aws-backup-ansible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS services backup using Ansible playbooks

Ansible playbook that takes AWS RDS, EFS (using AWS Backup), EC2 snapshots and application(ex. Neo4j DB on Ubuntu EC2 instance) backup in parallel

This is a sample Ansible playbook solution that executes below flow :

Alt text

Assumptions

  1. Dependencies : For this solution, it is assumed that the Bastian host has necessary dependencies installed like Ansible, Boto (to execute AWS operations), etc. More info on AWS Linux Bastian host

  2. Ansible operations from playbooks : Ansible supported AWS modules

    For other AWS operations, AWS CLI is used. Configuring the AWS CLI

  3. SSH key of the <my_app> EC2 instance is copied from S3 bucket into Bastian host to perform SSH operations.

  4. AWS constants : Some variables for AWS operations like region, account_id are stored as constants in vars files. This could to be enhanced to be dynamic.

  5. Pre and post scripts : As pre-script, httpd service is stopped and as post-script, httpd service is started. This could be enhanced to run any scripts.

  6. This sample solution doesn't include automated/scheduled backup option. It can be enhanced as needed.

Playbooks structure

Alt text

Inventories

The inventories section contains the hosts information [Bastian host + <my_app> EC2 instances].

It also includes common variables (like AWS region, account_id etc.) across all hosts and roles that are used for executing AWS operations.

NOTE : Values in these files need to be updated accordingly.

Roles

The playbook is divided into roles as shown in above tree structure.

Each role has its own vars (can be changed as needed) and tasks directories mentioning the operations to be performed by that role.

Running the playbook

NOTE : Running these playbooks uses AWS services and creates Backup resources, which could add cost as per AWS pricing.

  1. Clone this repository : git clone https://github.com/sanket-bengali/aws-backup-ansible.git

  2. Go to the playbook directory : cd /path/to/repository/ansible/aws/

  3. Update inventory files variables

    In "inventories/poc/hosts" : <ec2_public_ip>, <ec2_user>, <neo4j_ec2_public_ip>

    In "inventories/poc/group_vars/all.yaml" : "aws-region", "aws-account-id"

  4. Update playbooks variables inside "roles"

    a. get_ssh_key

    -> In "get_ssh_key/tasks/main.yaml" : <bucket_name>, <path_to_ssh_key/key_name.pem>

    -> In "get_ssh_key/vars/main.yaml" : <key_name.pem>

    b. take_ec2_snapshot

    -> In "take_ec2_snapshot/vars/main.yaml" : "my-app-ec2-instance-name", "ec2_device_name"

    c. take_efs_backup

    -> In "take_efs_backup/vars/main.yaml" : "my-app-efs-name", "efs-backup-vault-name"

    d. take_rds_snapshot

    -> In "take_rds_snapshot/vars/main.yaml" : "my-app-pgsql-db"

    e. take_neo4j_db_backup

    -> In "take_neo4j_db_backup/vars/main.yaml" : "/home/ubuntu/<neo4j_backup_dir>"

  5. Run the playbook : ansible-playbook my_app_backup.yaml -i inventories/poc/hosts

More information

AWS services backup using Ansible playbooks

License

The MIT License (MIT). Please see License File for more information.

About

Ansible playbook that takes AWS RDS, EFS and EC2 snapshots and application(Neo4j DB) backup in parallel

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published