alexkravets / heroku-mongo-backup

Backup mongodb on Heroku and push it to S3 or FTP with cron task.
https://github.com/alexkravets/heroku-mongo-backup
55 stars 33 forks source link

Some GridFS files aren't restored properly #7

Closed moonhouse closed 12 years ago

moonhouse commented 12 years ago

We see that the data chunks for some of the files stored with GridFS in our database isn't restored properly. We can restore them manually by

require 'bson'
require 'zlib'
require 'digest/md5'

@file_name = '/Users/david.hall/Downloads/2012-09-04_10-30-26.gz'

file = Zlib::GzipReader.open(@file_name)
obj = Marshal.load file.read
file.close

obj.each do |col_name, records|
  next unless col_name == 'fs.chunks'

  records.each do |record|
    if record["files_id"].to_s=='503dffd59701bf0002000004'
      File.open('outfile.jpg', 'w') {|f| f.write(record["data"]) }
    end
  end

end
moonhouse commented 12 years ago

Embarrassingly enough I had a too small MongoHQ instance which fooled me since the chunks were restored at the end.

alexkravets commented 12 years ago

No problem. Glad you've figured it out!