Created
June 30, 2011 11:20
-
-
Save lsm/1056037 to your computer and use it in GitHub Desktop.
Export files from MongoDB GridFS with directory paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# http://www.vladimirm.com/blog/2011/06/export-files-from-mongodb-gridfs-with-directory-paths/ | |
_host="${1:?Usage: gridfs host db}" | |
_db="${2:?Usage: gridfs host db}" | |
while read -r line; do | |
file=$(echo "$line" | awk -F'\t' '{ print $1 }') | |
[[ $file == 'connected to'* ]] && continue | |
directory=${file%/*} | |
mkdir -p $directory | |
mongofiles -h $_host -db $_db get $file | |
done < <(mongofiles -h $_host -db $_db list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey guys! I have a NodeJS app that stores all of its data, even images, to a MongoDB server. Now I want to use an S3 to store these images (43gb) and so, I need to transfer them there.
Whilst I have figured out how to transfer files from a server to an S3 using the
s3cmd
tool, I have NO idea how to export my images from the db! I know they are stored in thefs.files
andfs.chunks
collections, but I can't figure out how to actually use them as input tos3cmd
!I found this script, but I'm not sure how to use it... Any help will be much appreciated!!!