GithubHelp home page GithubHelp logo

laurensrietveld / docker-backup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from outcoldman/docker-backup

0.0 2.0 0.0 10 KB

Docker container for automatic backups. find | tar | s3

Shell 100.00%

docker-backup's Introduction

Table of Contents

Supported tags

  • latest

Introduction

Dockerfile to build an image which allows to create backup archives on daily basic. This image is based on Alpine Linux and s3cmd tool. You can use this image to create backup archives and store them on local folder or upload to S3.

Installation

Pull the image from the docker registry. This is the recommended method of installation as it is easier to update image. These builds are performed by the Docker Trusted Build service.

docker pull outcoldman/backup:latest

Alternately you can build the image locally.

git clone https://github.com/outcoldman/docker-backup.git
cd docker-backup
docker build --tag="$USER/backup" .

Quick start

At first if you want to upload backups to AWS S3 you need to create new bucket on S3 and create an user in IAM with next policy (don't forget to update bucket locations)

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1412062044000",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::your-backup-us-west-2/*"
            ]
        },
        {
            "Sid": "Stmt1412062097000",
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListAllMyBuckets"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Sid": "Stmt1412062128000",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::your-backup-us-west-2"
            ]
        }
    ]
}

NOTE: I'm not a AWS expert, so if you think that it is possible to give less permissions - please let me know.

docker run -d \
    -e "BACKUP_FIND_OPTIONS=/etc/" \
    -e "BACKUP_PREFIX=my_etc" \
    -e "BACKUP_AWS_KEY=AWS_KEY" \
    -e "BACKUP_AWS_SECRET=AWS_SECRET" \
    -e "BACKUP_AWS_S3_PATH=s3://your-backup-us-west-2" \
    outcoldman/backup:latest

Configuration

  • BACKUP_PREFIX - prefix for the backup archives in format ${BACKUP_PREFIX}.$(date -Iseconds | sed 's/:/-/g').tar.gz, for example my_etc.2015-09-04T05-28-55+0000.tar.gz. Default value is backup.
  • BACKUP_DEST_FOLDER - if you want to keep backups locally you can change destination folder which is used to create backup archives. Default value is /var/tmp
  • BACKUP_DELETE_LOCAL_COPY - if you want to keep backups in BACKUP_DEST_FOLDER set it to true. Default value is true.
  • BACKUP_FIND_OPTIONS - this image is using find to select files you want to backup. See man find.
  • BACKUP_AWS_KEY - AWS Key.
  • BACKUP_AWS_SECRET - AWS Secret.
  • BACKUP_AWS_S3_PATH - path to S3 bucket, like s3://your-backup-us-west-2. Default value is empty, which means that archives will not be uploaded.
  • BACKUP_TIMEZONE - change timezone from UTC to tz database, for example America/Los_Angeles. Defaults to empty.
  • BACKUP_CRON_SCHEDULE - specify when and how often you want to run backup script. Defaults to 0 2 * * * (every day at 2am).

To enable email notifications, use the following settings:

  • SMTP_ENABLED - Enable sending via SMTP. Defaults to false
  • SMTP_SERVER_HOST - The server to send the mail to. Defaults to smtp.gmail.com
  • SMTP_SERVER_PORT - The port to use on the SMTP_SERVER_HOST. Defaults to 587
  • SMTP_REWRITE_DOMAIN - The domain from which this email seems to come, used for user authentication. Defaults to gmail.com
  • SMTP_HOSTNAME - The full hostname. If not specified, the host is queried for its hostname
  • SMTP_TLS - Specifies whether SSMTP uses TLS to talke to the SMTP server. Defaults to true
  • SMTP_START_TLS - Specifies wheter SSMTP does a EHLO/STARTTLS before stating SSL negotiation. Defaults to true
  • SMTP_USERNAME - Username to authenticate with. Unset by default.
  • SMTP_PASSWORD - Password to authenticate with. Unset by default
  • MAILTO_ON_SUCCESS - Email address to mail on backup success. Leave blank (default) to disable emails on success.
  • MAILTO_ON_FAIL - Email address to mail on backup failure. Leave blank (default) to disable emails on failure.
  • MAIL_FROM - The email address that notifications are send from. Defaults to [email protected]
  • MAIL_FROM_NAME - The name of the email address. Defaults to docker-backup
  • MAIL_SUBJECT_HEADER - The header to prepend to the notification email subject. Defaults to the machine hostname

Examples

Backing up Splunk etc folder

My docker-compose.yml part for backing up Splunk Light settings, including system no default settings and search non default settings

vsplunk:
  image: busybox
  volumes:
    - /opt/splunk/etc
    - /opt/splunk/var

splunk:
  image: outcoldman/splunk:latest
  volumes_from:
    - vsplunk
  restart: always

splunkbackup:
  image: outcoldman/backup:latest
  environment:
    - BACKUP_PREFIX=splunk-etc
    - BACKUP_AWS_KEY=AWS_KEY
    - BACKUP_AWS_SECRET=AWS_SECRET
    - BACKUP_AWS_S3_PATH=s3://my-backup-bucket
    - BACKUP_FIND_OPTIONS=/opt/splunk/etc \( -path "/opt/splunk/etc/apps/search/*" -a ! -path "/opt/splunk/etc/apps/search/default*" \) -o \( -path "/opt/splunk/etc/system/*" -a ! -path "/opt/splunk/etc/system/default*" \)
  volumes_from:
    - vsplunk
  restart: always

Backing up Jenkins

vdata:
  image: busybox
  volumes:
    - /var/jenkins_home
  command: chown -R 1000:1000 /var/jenkins_home

jenkins:
  build: jenkins:latest
  volumes_from:
    - vdata
  restart: always

backup:
  image: outcoldman/backup:latest
  environment:
    - BACKUP_PREFIX=jenkins
    - BACKUP_AWS_KEY=AWS_KEY
    - BACKUP_AWS_SECRET=AWS_SECRET
    - BACKUP_AWS_S3_PATH=s3://my-backup-bucket
    - BACKUP_FIND_OPTIONS=/var/jenkins_home/ -path "/var/jenkins_home/.ssh/*" -o -path "/var/jenkins_home/plugins/*.jpi" -o -path "/var/jenkins_home/users/*" -o -path "/var/jenkins_home/secrets/*" -o -path "/var/jenkins_home/jobs/*" -o -regex "/var/jenkins_home/[^/]*.xml" -o -regex "/var/jenkins_home/secret.[^/]*"
  volumes_from:
    - vdata
  restart: always

docker-backup's People

Contributors

laurensrietveld avatar outcoldman avatar

Watchers

 avatar  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.