Skip to content

Instantly share code, notes, and snippets.

@chalmagean
Last active December 4, 2019 11:18
Show Gist options
  • Save chalmagean/fcf8c3d1d8e686fc0d58b9f552bdf2f2 to your computer and use it in GitHub Desktop.
Save chalmagean/fcf8c3d1d8e686fc0d58b9f552bdf2f2 to your computer and use it in GitHub Desktop.
# Here's how to back up a named volume
# 1. Using a `ubuntu` image, we mount the named volume (`myproj_dbdata`) to a `/dbdata` folder inside the `ubuntu` container.
# 2. Then, we create a new folder inside the `ubuntu` container named `/backup`.
# 3. We then create an archive containing the contents of the `/dbdata` folder and we store it inside the `/backup` folder (inside the container).
# 4. We also mount the `/backup` folder from the container to the docker host (your local machine) in a folder named `/backups` inside the current directory.
docker run --rm -v myproj_dbdata:/dbdata -v $(pwd)/backups:/backup ubuntu tar cvf /backup/db_data_"$(date '+%y-%m-%d')".tar /dbdata
@nivagator
Copy link

Thanks! This is really helpful!

@shilpa88
Copy link

can you please explain this for windows

@johnmarcou
Copy link

johnmarcou commented Nov 16, 2018

Becareful to don't backup the database files while the database process is up and running, you could backup a corrupted database.

Another way would be to dump the db with the appropriate tool, then backup the dump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment