Giter Site home page Giter Site logo

backup2s3's Introduction

Introduction

This is a script to backup folders to AWS S3. It also includes a stack template for the AWS services needed. The script is developed for the purpose of being called by a cron job.

Deploying

Prerequisites

  • Install and configure awscli to your AWS account.

Launch stack

To create the stack for the first time:

./aws_stack create my-stack

Configuring

Edit env.sh accordingly:

  • PRG_PYTHON_ENV_ACTIVATE to your python environment activate script. (e.g. after using virtualenv). This environment needs to have awscli installed. (pip install awscli)
  • PRG_FOLDER_LIST_FILE: Path to the file where each line contains the absolute folder path which should be backed up.
  • AWS_ACCESS_KEY_ID: The aws access key from the stack created.
  • AWS_SECRET_ACCESS_KEY: The aws secret access key from the stack created.
  • PRG_S3_BUCKET_NAME: The name of the bucket to sync to. Fetched from the stack created.

Note you can use

aws cloudformation describe-stacks --stack-name=my-stack

to see the stack parameter outputs.

Customize

Customize the folder list file to your backup needs.

Example

Watch /root folder:

root@hostname:~$ echo /root > folder_list.txt

Launch stack

root@hostname:~$ ./aws_stack.sh create my-example-stack

Create a python virtual environment with awscli

root@hostname:~$ virtualenv pyenv
root@hostname:~$ ./pyenv/bin/pip install awscli

Get stack parameters:

root@hostname:~$ aws cloudformation describe-stacks --stack-name=my-example-stack
{
    "Stacks": [
        {
            "StackId": ...,
            "StackName": "my-example-stack",
            ...
            "Outputs": [
                {
                    "OutputKey": "SecretAccessKey",
                    "OutputValue": "ABCDEFGHIJKLMNOPQRSTUVXYZ012345679!"#$%&",
                    "Description": "..."
                },
                {
                    "OutputKey": "S3BucketName",
                    "OutputValue": "my-example-stack-mys3bucket-abcdefghijklm",
                    "Description": "..."
                },
                {
                    "OutputKey": "AccessKey",
                    "OutputValue": "ABCDEFGHIJKLMNOPQRST",
                    "Description": "..."
                }
            ],
            ...
        }
    ]
}

Edit env.sh to use the following parameters:

PRG_PYTHON_ENV_ACTIVATE=/root/pyenv/bin/activate
PRG_FOLDER_LIST_FILE=/root/folder_list.txt
AWS_ACCESS_KEY_ID=ABCDEFGHIJKLMNOPQRST
AWS_SECRET_ACCESS_KEY=ABCDEFGHIJKLMNOPQRSTUVXYZ012345679!"#$%&
PRG_S3_BUCKET_NAME=my-example-stack-mys3bucket-abcdefghijklm

Change permissions

root@hostname:~$ chmod 600 env.sh
root@hostname:~$ chown root:root env.sh
root@hostname:~$ chmod +x s3sync.sh
root@hostname:~$ chown root:root s3sync.sh

Run sync

root@hostname:~$ ./s3sync.sh

Development

Recommend ignoring further edits to the env.sh to prevent accidentaly AWS access key commits

git update-index --skip-worktree env.sh

Feel free to add suggestions or create pull requests.

backup2s3's People

Contributors

haggalin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.