Is there a simple way to export the data from a meteor deployed app?

后端 未结 12 2080
轻奢々
轻奢々 2020-11-30 16:30

Is there a simple way to export the data from a meteor deployed app?

So, for example, if I had deployed an app named test.meteor.com...

How could I easily d

相关标签:
12条回答
  • 2020-11-30 17:17

    meteor-backup is by far the easiest way to do this.

    sudo npm install -g meteor-db-utils
    meteor-backup [domain] [collection...]
    

    As of March 2015 you still need to specify all collections you want to fetch though (until this issue is resolved).


    Stuff from the past below

    I'm doing

    mongodump $(meteor mongo -U example.meteor.com | coffee url2args.cfee)
    

    together with this little coffeescript, with a mangled extension in order not to confuse Meteor, url2args.cfee:

    stdin = process.openStdin()
    stdin.setEncoding 'utf8'
    stdin.on 'data', (input) ->
      m = input.match /mongodb:\/\/(\w+):((\w+-)+\w+)@((\w+\.)+\w+):27017\/(\w+)/
      console.log "-u #{m[1]} -h #{m[4]} -p #{m[2]} -d #{m[6]}"
    

    (it would be nicer if meteor mongo -U --mongodumpoptions would give these options, or if mongodump would accept the mongo:// URL)

    0 讨论(0)
  • 2020-11-30 17:17

    Here is a simple bash script that lets you dump your database from meteor.com hosted sites.

    #!/bin/bash
    
    site="rankz.meteor.com"
    name="$(meteor mongo --url $site)"
    echo $name
    
    IFS='@' read -a mongoString <<< "$name"
    
    echo "HEAD: ${mongoString[0]}"
    echo "TAIL: ${mongoString[1]}"
    
    IFS=':' read -a pwd <<< "${mongoString[0]}"
    
    echo "${pwd[1]}"
    echo "${pwd[1]:2}"
    echo "${pwd[2]}"
    
    
    IFS='/' read -a site <<< "${mongoString[1]}"
    
    echo "${site[0]}"
    echo "${site[1]}"
    
    
    mongodump -u ${pwd[1]:2} -h ${site[0]} -d ${site[1]}\
              -p ${pwd[2]}
    
    0 讨论(0)
  • I have created a tool, mmongo, that wraps all the Mongo DB client shell commands for convenient use on a Meteor database. If you use npm (Node Package Manager), you can install it with:

    npm install -g mmongo
    

    Otherwise, see README.

    To back up your Meteor database, you can now do:

    mmongo test.meteor.com dump 
    

    To upload it to your local development meteor would be:

    mmongo restore dump/test_meteor_com
    

    And if you accidentally delete your production database:

    mmongo test.meteor.com --eval 'db.dropDatabase()'   # whoops!
    

    You can easily restore it:

    mmongo test.meteor.com restore dump/test_meteor_com 
    

    If you'd rather export a collection (say tasks) to something readable:

    mmongo test.meteor.com export -c tasks -o tasks.json
    

    Then you can open up tasks.json in your text editor, do some changes and insert the changes with:

    mmongo test.meteor.com import tasks.json -c tasks --upsert
    

    Github, NPM

    0 讨论(0)
  • 2020-11-30 17:27

    I made this simple Rakefile to copy the live db to local.

    To restore the live db to my local machine I just do...

    rake copy_live_db
    

    Replace myapp with the name of your meteor.com - e.g myapp.meteor.com.

    require 'rubygems'
    require 'open-uri'
    
    desc "Backup the live db to local ./dump folder"
    task :backup_live_db do
      uri = `meteor mongo myapp --url`
      pass = uri.match(/client:([^@]+)@/)[1]
      puts "Using live db password: #{pass}"
      `mongodump -h meteor.m0.mongolayer.com:27017 -d myapp_meteor_com -u client -p #{pass}`
    end
    
    
    desc "Copy live database to local"
    task :copy_live_db => :backup_live_db do
      server =  `meteor mongo --url`
      uri = URI.parse(server)
      `mongorestore --host #{uri.host} --port #{uri.port} --db meteor --drop dump/myapp_meteor_com/`
    end
    
    desc "Restore last backup"
    task :restore do
      server =  `meteor mongo --url`
      uri = URI.parse(server)
      `mongorestore --host #{uri.host} --port #{uri.port} --db meteor --drop dump/myapp_meteor_com/`
    end
    
    0 讨论(0)
  • 2020-11-30 17:30

    To get the URL for your deployed site at meteor.com use the command (you may need to provide your site password if you password protected it):

    meteor mongo --url YOURSITE.meteor.com
    

    Which will return something like :

    mongodb://client:PASSWORD@sky.member1.mongolayer.com:27017/YOURSITE_meteor_com
    

    Which you can give to a program like mongodump

    mongodump -u client -h sky.member1.mongolayer.com:27017 -d YOURSITE_meteor_com\
              -p PASSWORD
    

    The password is only good for one minute. For usage:

    $ meteor --help mongo
    
    0 讨论(0)
  • 2020-11-30 17:31

    And here's how to do the opposite: (uploading your local monogo db to meteor)

    https://gist.github.com/IslamMagdy/5519514

    # How to upload local db to meteor:
    
    # -h = host, -d = database name, -o = dump folder name
    mongodump -h 127.0.0.1:3002 -d meteor -o meteor
    
    # get meteor db url, username, and password
    meteor mongo --url myapp.meteor.com
    
    # -h = host, -d = database name (app domain), -p = password, folder = the path to the dumped db
    mongorestore -u client -h c0.meteor.m0.mongolayer.com:27017 -d myapp_meteor_com -p 'password' folder/
    
    0 讨论(0)
提交回复
热议问题