This is the monster I created to get gridfs files backed up as if they where on filesystem:
One thing I wanted was to keep the script in one file, and to make it work with the least dependencies possibile.
This is what it does with the dump commnad
1 - dump all collections but fs.chunks as usual, with mongodump
2 - Gzip all bson files
3 - create a directory for grids files
4 - dump gridfs files to filesystem via Ruby, only if id+checksum did not change
5 - remove fs files that are no longer in the database
On restore
1 - unzip bson files
2 - restore the database from bson files
3 - iterate over fs.files collection, read dumped file from filesystem and restore it into gridfs.
The operations above can be performed on a subset of databases.
I learned a couple of things working on this script:
1 - What :snapshot => true is for. I ended up in an endless loop on restore. Cursor was beeing fed with new records on every iteration.
2 - Authentication in mongodb is painful. You have to add admin user to each and every database in order to make this script work for the whole instance when --auth is on.
Enjoy!