• Home
  • About Me

Software Theory and Practice

  • Home
  • About Me
Home  /  Cloud • Docker • MongoDB • NoSql Database  /  Docker backup and restore volume container
26 January 2015
Cloud

Docker backup and restore volume container

Alvin Henrick 2 Comments 29449 Views

This is the continuation from my previous post where I had explained how to run spring boot app inside the docker container as daemon which is using MongoDB as storage and the [/data/db] volume was mounted as docker container volume.

This post will provide the steps to take the backup of volume container and restore it back.

Step 1: Take the backup via tar command provided below.

docker run --volumes-from mongodata -v $(pwd):/backup busybox tar cvf /backup/backup.tar /data/db
kup.tar /data/db
tar: removing leading '/' from member names
data/db/
data/db/local.ns
data/db/TEST_DB.ns
data/db/mongod.lock
data/db/journal/
data/db/TEST_DB.0
data/db/local.0
  • This is how it works first the volume from mongodata [/data/db] is mounted .
  • The current working directory [$(pwd)] of host is mounted as volume with path [/backup] directory inside container.
  • The tar command is executed inside the container on /data/db directory and the backup.tar  is copied to [/backup]
  • Execute the ls -l command from the current  directory of the host you will notice the backup.tar file.

Step 2: Restore the backup via tar command provide below.

docker run --volumes-from mongodata -v $(pwd):/backup busybox tar xvf /backup/backup.tar
  • This is how it works first the volume from mongodata [/data/db] is mounted .
  • The current working directory [$(pwd)] of host is mounted as volume with path [/backup] directory inside container.
  • The tar command is executed inside the container on /backup/backup.tar file and the it contents are extracted to [/data/db] directory (this is mounted via volume container which is mongodata).

Step 3 : List the contents

docker run --rm --volumes-from mongodata  busybox ls -lh /data/db
  • Notice the –rm option.This command will execute  and spawn the temporary docker container mount the volume list the [/data/db] directory .
  • After the command is executed the temporary docker container will be automatically removed.

Copy existing folder from host to docker volume container.

First of all the credit must be given to the person who has this covered already on his blog here. but I thought it is worth mentioning it again here because we are covering the topic of backup and restore.

Step 1. Create volume only docker container named as testdata.

 docker run -v /test/data --name testdata busybox true

Step 2. Copy the folder named as sample from current host directory to volume container.

 tar -c sample/ | docker run -i --rm -w /test/data --volumes-from testdata busybox tar -xv
  •  The tar command  pipes the content of sample folder into the docker volume container directory [/test/data].
  • You can use the ls command like we did earlier change the mongodata to testdata and [/data/db] to [/test/data]
  • All the contents from sample directory copied will be listed.

Please feel free to notify if you encounter any issues.I am always learning :).

Thank You!!!

About Author

Alvin Henrick

Previous Article Spring Boot App deployed with Docker and Data Only Container Pattern Explained.
Next Article Query Nested JSON via Spark SQL

Related Posts

  • How to index geospatial data with Apache Spark Solr Connector and query with Solr Client

    How to index geospatial data with Apache Spark Solr Connector and query with Solr Client

  • Spring Boot App deployed with Docker and Data Only Container Pattern Explained.

    Spring Boot App deployed with Docker and Data Only Container Pattern Explained.

  • Apache Storm and Kafka Cluster with Docker

    Apache Storm and Kafka Cluster with Docker

Search

Recent Posts

  • How to index geospatial data with Apache Spark Solr Connector and query with Solr Client August 1, 2018
  • Apache Spark Analytical Window Functions May 16, 2017
  • Apache Spark User Defined Functions July 10, 2016
  • Query Nested JSON via Spark SQL November 26, 2015
  • Docker backup and restore volume container January 26, 2015

Calendar

January 2015
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Aug   Nov »