Code Monkey home page Code Monkey logo

dksnap's Introduction

dksnap

Build Status Go Report Card License Slack Made by Kelda
Install  |   Key Features  |   FAQ  |   Roadmap  |   Contributing

dksnap creates, views, and runs snapshots of Docker containers.

When testing locally we often use containers with test data. dksnap allows you to snapshot those containers at a good state, and roll back or forward as needed.

For a full description check out this blogpost.

Install

Install on MacOS or Linux:

curl https://kelda.io/install-dksnap.sh | sh

Or download the latest release and copy to your path.

Demo

Watch the demo, or try it yourself with step-by-step instructions:

# Download the demo.
git clone https://github.com/kelda/dksnap.git
cd dksnap/demo

# Start the example application. You can access it in your browser at localhost:8080.
docker-compose up -d

# Use dksnap to create snapshots of the entries in the Mongo database.
dksnap

Key Features

Create Snapshots

Create a snapshot of any running Docker container. dksnap works with any container, but has extra features for select databases.

  • Snapshots are volume aware. They will capture data in volumes as well as in the container image.
  • Snapshots are database aware. When snapshotting databases that implement the plugin interface, dksnap will politely ask the database process to dump its contents before creating a Docker image.

View Snapshots

dksnap includes a terminal browser that provides a tree view of all your snapshots along with diffs showing how they've changed over time.

Replace Running Containers

Replace a running Docker container with a snapshot taken in the past. dksnap will automatically shut down the running container, boot the snapshot image, and restart the container using the same Docker command arguments.

Other Features

Works With Any Container

By default, dksnap creates snapshots by committing the container's filesystem with docker commit, and dumping the contents of all attached volumes.

Database Awareness

dksnap is database aware, meaning it knows how to politely dump and restore and diff database contents for the following databases:

  • Mongo
  • Postgres
  • MySQL

It has a plugin architecture making it easy to add more databases in the future. Contributions welcome!

Docker Images

dksnap images are simply docker images with some additional metadata. This means they can be viewed and manipulated using the standard docker command line tools.

Share Snapshots

dksnap stores all of the snapshot information in a docker image, so you can share your snapshot by pushing it to a Docker registry just like you would any other container image.

Volume Awareness

Snapshots are volume aware. The official database images all store their data in volumes which docker commit does not capture. dksnap saves volumes in addition to the container filesystem.

FAQ

How is this different than docker commit?

dksnap uses docker commit for its generic snapshot approach to capture the container’s filesystem. However, docker commit has distinct limitations:

  • It doesn't capture volumes, so it can't be used with most database docker images.
  • It isn't database aware. It doesn't politely save/restore database state meaning it's prone to creating corrupted database images.

How is this different than a Docker image?

dksnap uses Docker images as the storage format for its snapshots, which makes them fully compatible with all of the things you would normally do with an image (run, push, delete, etc). You could handcraft Docker images to mimic dksnap snapshots, but dksnap makes it easy to create them from running containers.

Roadmap

  • Automated snapshot creation from production and staging databases in CI.
  • A non-graphical CLI interface that's scriptable.
  • Native support for additional databases.
  • Snapshot of CPU and RAM state.

Contributing

dksnap is still in alpha and under heavy development. Contributions are very much welcome so please get involved. Check out the contribution guidelines to get started.

Build

dksnap requires being built with go version 1.13 or later.

It uses Go Modules, and error wrapping.

git clone https://github.com/kelda/dksnap
cd dksnap
GO111MODULE=on go build .
./dksnap

dksnap's People

Contributors

dependabot[bot] avatar ejj avatar kklin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dksnap's Issues

ERROR 1005 (HY000) Can't create table

I am in the process of migrating a database, I use a 60GB dump file to restore to the new database and I get this error
The two databases are in the same version: mariadb:10.9.3

A non-graphical CLI interface that's scriptable

Is your feature request related to a problem? Please describe.

Some people prefer working directly with a command line interface. Plus, this would make it easier to integrate with scripts.

Stop container boot if volume initialization fails

Is your feature request related to a problem? Please describe.

The generic snapshot works by copying files from the image into the volumes. If the files fail to copy for some reason, we should abort, so that the user doesn't continue using the container thinking that they're testing against the full snapshot.

Describe the solution you'd like

Abort the container boot with a helpful error message.

Failed to create snapshot: tar file exist status 1 operation not permitted

on MacOS Big Sur 11.2.3, and docker desktop 3.2.2

Attempting to snapshot kind control plane node:

Failed to create snapshot
build image: build image: failed to copy files: Error processing tar file(exit status 1): operation not permitted

Whereas this works on the same system:

$ docker run -d nginx
$ dksnap
# snapshot nginx image success

Support Mongo databases that require login

Is your feature request related to a problem? Please describe.

mongodump currently doesn't authenticate when creating the database dump, so it fails if the db was started with MONGO_INITDB_ROOT_USERNAME or MONGO_INITDB_ROOT_PASSWORD.

Describe the solution you'd like

Provide an input when creating mongo snapshots that allows setting the username and password to dump as. We can try to guess values for this by analyzing the container's environment variables. The postgres snapshotter has an example of this approach.

Additional context
Add any other context or screenshots about the feature request here.

Mariadb/Mysql restore not working?

Hi,

I was looking for a tool that could do exactly this, and I was really happy when I found it. This is functionality my expensive Datagrip totally lacks, but is super handy. However; there seems to be a bug when it comes to restoring a snapshot. The tool reports a success, but no container is actually started. I've tried replacing and starting from a snapshot; both don't work. When replacing, the old container is shut down, but no new container is spun up. In the docker logs (sudo journalctl -fu docker.service) I only see the following line pop up every time I try to start from a snapshot:

dockerd[927]: time="2020-05-01T10:23:45.486207189+02:00" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"

I am using the following docker-compose:

version: '3'
services:
  mariadb:
    image: mariadb:latest
    ports:
    - "3306:3306"
    volumes:
    - ./dump_20200210.sql:/docker-entrypoint-initdb.d/sql_dump_file.sql
    - ./packet_size.cnf:/etc/mysql/mariadb.conf.d/packet_size.cnf
    environment:
    - MYSQL_ROOT_PASSWORD=
    - MYSQL_DATABASE=testdb
    - MYSQL_ALLOW_EMPTY_PASSWORD=true

EDIT:
In my vscode-docker I see a bunch of new containers have been created, three of which had the names of the snapshots I took. The others were just hashes. I guess dksnap did something; but not what I would expect :)

Also, on another note; it is not possible to define a root password in this tool. This should totally be the case; since it would provide a little extra security. It should at least prompt the user when passwordless auth fails to let me enter the password. I have never worked with go before; so I'm afraid I won't be too much of an help in fixing this issue.

Thank you for your time.

Improve error message when diffing root database container.

Right now, if you attempt to show a diff on the root DB container there is an error message that says.

Failed to diff: can't diff generic snapshots

This is a bit misleading, because as a new user it makes me think that MongoDB is not supported for diffing.

I would expect something along the lines of:

Failed to diff: can't diff root database container

Even better would be if you could do this diff!

Kafka broker & Zookeeper backup

Describe the solution you'd like
When demoing stream processing applications via Docker, I am required to write a producer application to first ingest data. Instead, I would like a snapshot of the broker state.

Additional context
Kafka topics are time-sensitive by default via the log.retention.ms property, and periodically swept by the log cleaner. Some mechanism might be required to adjust record timestamps during restoration, if not simply disabling retention


Alternative solution - Pulsar + Bookkeeper

Support host volumes

Is your feature request related to a problem? Please describe.

Host volumes are currently ignored.

Describe the solution you'd like

Although working with host volumes can be dangerous since it affects the host filesystem, the user should have the option of snapshotting host volumes when appropriate.

Allow changing credentials for mysql

Currently I cannot take snapshot of percona/percona-server because it tries to log as mysql (no password).

Please create a way for us to supply this information (user, password).
Screen Shot 2022-06-30 at 11 43 39 AM

Snapshot CPU and RAM state

Is your feature request related to a problem? Please describe.

dksnap currently just captures the filesystem. Although this is sufficient for most scenarios, capturing the CPU and RAM state may be helpful for some applications that don't make it a point to persist to disk.

Describe the solution you'd like

Docker checkpoints may be helpful.

Automated snapshot creation from production and staging databases

Is your feature request related to a problem? Please describe.

dksnap helps create snapshots once the container is already initialized. However, it doesn't directly help with setting up the container the very first time.

Describe the solution you'd like

You could imagine pointing the snapshot at a remote database, and running this at a regular interval. Note that these databases may not be containerized, and likely contain sensitive information.

Additional context

DB-aware support for Cassandra

Describe the solution you'd like
Able to use Cassandra with this tool

Additional context
Can this tool support distributed databases? Or would it be limited to a single cassandra container?

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.