Giter VIP home page Giter VIP logo

docktartar's Introduction

Docker Stars Docker Pulls Docker Automated buil Docker Repository on Quay

DockTartar

Introduction

Docktartar will recursively tar a directory to another location. It has been designed to stop running docker containers before doing the backup and restart them after the archival process.

Some Features:

  • Multi-Core Compression with pigz
  • CRON daemon to schedule the backup job
  • SMB Client to backup to a network share
  • Temp-Directory to build the archive locally (eg SSD), restart the containers and move the archive afterwards
  • Mail notifications with ssmtp
  • Full configuration with environment variables
  • Chose which containers to stop and restart

You can provide a temp-directory for faster archival, afterwards the script will move the archive wherever you want. This is useful in cases where you want to store your backup on a remote server (you should really do this!). The workflow in this case is:

  1. Stop Containers
  2. Build the archive in the /backupTmp directory
  3. Start containers
  4. move the archive from /backupTmp to /targetTmp
  5. Chown the archive

Getting started

Installation

Automated builds of the image are available on Dockerhub and is the recommended method of installation.

docker pull gmentsik/docktartar

Alternatively you can build the image yourself.

docker build -t gmentsik/docktartar github.com/gmentsik/docktartar

Quickstart

You can use the sample docker-compose.yml file to start the container using Docker Compose*

Or start Docktartar using:

docker run -d --name docktartar \
              --restart=always \
              --volume /srv/docker:/backupSource \
              --volume /var/backups/docker:/backupTarget  \
              --volume /var/run/docker.sock:/var/run/docker.sock \
              --volume /var/lib/docker:/var/lib/docker \
      gmentsik/docktartar

Environment Variables

Variable Default Value Description Examples
CRON "0 0 * * *" (=Midnight) When the script should start in cron format. Check cron-generator "0 30 * * *" , "0 0 */3 * *"
TIMEZONE "Europe/Vienna" Sets the timezone of the container. 'Asia/Tokyo','America/Los_Angeles'
TAR_OWNER_USERID 0 Sets the Owner of the archive. 0 = root enter id for all users on your system
TAR_OWNER_GROUPID 0 Sets the Group-Owner of the archive. 0 = root enter id for all users on your system
TAG "docker" Sets filename tag.[timestamp].tar.gz docker-backup
STOP_CONTAINERS "all" The containers to stop. Either Name, Id or all. nginx mysql all will stop nginx then mysql and then all others. mysql all, nginx mysql, all
START_CONTAINERS "all" The containers to start. Either Name, Id or all. nginx mysql all will start nginx then mysql and then all others. mysql all, nginx mysql, all
INCREMENTAL "true" Generates incremental backups true or false
SMB "false" Enables Samba integration true or false
SMB_USER "" Username of the samba user username
SMB_PASSWORD "" Password of the samba user pass
SMB_SMB_PATH "" IP+Path of the Samba Network Share 192.162.4.10/shares/backups
EMAIL_HOST_PORT "" Host and port of your e-mail server/smarthost The format is host.tld:port mail.company.com:587
EMAIL_USER "" Username for authentication on your mail server web58p4
EMAIL_PASS "" Password for authentication on your mail server secretpassword
EMAIL_USE_STARTTLS "NO" use starttls, YES or NO YES or NO
EMAIL_FROM "Docktartar" The name that is displayed in the from field Docktartar
EMAIL_FROM_ADRESS "" The e-mail adress that is displayed in the from field [email protected]
EMAIL_SUBJECT "Docktartar" The subject of the message Backupjob
EMAIL_TO "" The E-Mail adress where the emails should be send [email protected]
TEMP_DIR "NO" If set to YES, the archive is built in /backupTmp and then moved to /backupTarget, after the all containers restarted YES or NO

Samba Share and Permissions

In order to run this with samba share as the backup target, you have to either run the container with privileged: true or add cap_add: SYS_ADMIN

Volumes

Container Volume Description
/backupSource The contents of this folder will be archived in a tar-archive.
/backupTarget The tar-archive will be put in this directory. If you use a Network share, do not mount this!
/var/run/docker.sock Has to be mapped in ordner to be able to stop and start containers.
/var/lib/docker Has to be mapped in ordner to be able to stop and start containers.

Maintenance

Test Mail settings

There is a test script in the root folder called test-mail.sh which can be used to test the email settings.

docker exec -it docktartar /root/test-mail.sh

Upgrading

To upgrade to newer releases:

  1. Download the updated Docker image:
docker pull gmentsik/docktartar
  1. Stop the currently running image:
docker stop docktartar
  1. Remove the stopped container
docker rm -v docktartar
  1. Start the updated image
docker run -name docktartar -d [OPTIONS] gmentsik/docktartar

Shell Access

For debugging and maintenance purposes you may want access the containers shell. If you are using Docker version 1.3.0 or higher you can access a running containers shell by starting bash using docker exec:

docker exec -it docktartar bash

Contributing

If you find this image useful here's how you can help:

  • Send a pull request with your awesome features and bug fixes
  • Help users resolve their issues.

Issues

Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker installation guide for instructions.

SELinux users should try disabling SELinux using the command setenforce 0 to see if it resolves the issue.

If the above recommendations do not help then report your issue along with the following information:

  • Output of the docker version and docker info commands
  • The docker run command or docker-compose.yml used to start the image. Mask out the sensitive bits.
  • Please state if you are using Boot2Docker, VirtualBox, etc.

docktartar's People

Contributors

n1v0k avatar

Stargazers

 avatar  avatar

Watchers

 avatar

docktartar's Issues

mount line seems to be wrong

Hi,

I think the mount line in /root/docktartar.sh should use

password

no
passwd

If so please update the docktartar.sh script.

email without auth

Hi,

I am trying to send a test email message but that fails with the docker-compose.yml you provide.

The last line should be deleted when sending email, or there is no email.

Secondly. I want to send email without authentication. Is it possible to provide an environmental variable like
EMAIL_AUTH "false"?

when I leave the authuser blanc apparently it uses auth anyway:

root@core containers/BACKUP2017-10-07# docker exec -it backup_docktartar_1 /root/test-mail.sh
Sending test email
ssmtp: Server didn't like our AUTH LOGIN (500 Unrecognized command)
Could not send email, ssmtp returned a non-zero code!

If I delete the line with autjuser form ssmtp.conf the test goes fine:
root@core containers/BACKUP2017-10-07# docker exec -it backup_docktartar_1 /root/test-mail.sh
Sending test email
Success

ssmtp.conf then is:
root=[email protected]
mailhub=192.168.0.1:25
UseSTARTTLS=NO
FromLineOverride=YES

smb mount does not run properly: are you root?

when running:
docker exec -it backup_docktartar_1 /root/docktartar.sh

it says:
smb mount is 192.168.0.36/share
Mounting the SMB share
Unable to set current process capabilities: Operation not permitted
mount: permission denied (are you root?)

My docker-compose.yml says:
TAR_OWNER_USERID: 0
TAR_OWNER_GROUPID: 0

Should I change these user ID's or something?

when I log into the container and run by hand:bash-4.3# mount -t cifs -o username=rem,passwd=Seclet //192.168.0.66/share /backupTarget
Unable to set current process capabilities: Operation not permitted
mount: permission denied (are you root?)

bash-4.3# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

bash-4.3# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

feature: containers not to backup

Hi,
I have a few containers I do not want to be stopped, nor backupped.
For instance I have a time-server where backup is kindoff useless, and secondly a dns-server I want only backupped when the secndary is up.

Is not stopping certain containers doable or will it lock certain volumes so that the backup might go wrong?

Secondly I was wondering if Dar might be a bit more efficient.

Finally, great work, will be testing !

emails are empty

Hi,

the email sent are empty I am afraid

This is what the email source looks like
###############################################
Received: by ba0302860cf5 (sSMTP sendmail emulation); Fri, 13 Oct 2017 14:07:11 +0200
Date: Fri, 13 Oct 2017 14:07:11 +0200
From: Docktartar [email protected]
Subject: Docktartar
################################################

I also get a number of completely empty emails from root.

running a backup by hand show this:

docker exec -it backup_docktartar_1 /root/docktartar.sh
From: Docktartar [email protected]
Subject: Docktartar
Starting Backup - Fri Oct 13 14:39:30 CEST 2017 .
Mounting the SMB share
Error response from daemon: No such container: nextcloud
Stopping
Looking for sockets to exclude them from the archive...
Creating TAR-Archive from /backupSource
Error response from daemon: No such container: nextcloud
Error: failed to start containers: nextcloud
Restarting
Chown the archive
chown: /backupTarget/dockertar.14.39.30-13.10.17.tar.gz: Permission denied
Archive size: 64.0K
Unmounting the SMB share
Backup dockertar took 0 minutes and 14 seconds.
Sending email to [email protected]
Finished.

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.