programing

유성 배포 앱에서 데이터를 내보내는 간단한 방법이 있습니까?

nasanasas 2020. 10. 26. 08:03
반응형

유성 배포 앱에서 데이터를 내보내는 간단한 방법이 있습니까?


유성 배포 앱에서 데이터를 내보내는 간단한 방법이 있습니까?

예를 들어 test.meteor.com이라는 앱을 배포했다면 ...

배포 된 앱의 데이터로 로컬에서 실행할 수 있도록 해당 앱에서 수집 한 데이터를 어떻게 쉽게 다운로드 할 수 있습니까?


meteor.com에서 배포 된 사이트의 URL을 얻으려면 다음 명령을 사용하십시오 (암호로 보호 된 경우 사이트 암호를 제공해야 할 수 있음).

meteor mongo --url YOURSITE.meteor.com

다음과 같은 결과가 반환됩니다.

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

같은 프로그램에 줄 수있는 mongodump

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

암호는 1 분 동안 만 유효합니다. 사용법 :

$ meteor --help mongo

그 반대의 방법은 다음과 같습니다 : (로컬 monogo db를 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/

Kasper Souren의 솔루션을 기반으로 현재 버전의 Meteor에서 작동하고 원격 Meteor 앱을 암호로 보호 할 때도 작동하는 업데이트 된 스크립트를 만들었습니다.

다음 스크립트를 작성하십시오 parse-mongo-url.coffee.

spawn = require('child_process').spawn
mongo = spawn 'meteor', ['mongo', '--url', 'YOURPROJECT.meteor.com'], stdio: [process.stdin, 'pipe', process.stderr]

mongo.stdout.on 'data', (data) ->
    data = data.toString()
    m = data.match /mongodb:\/\/([^:]+):([^@]+)@([^:]+):27017\/([^\/]+)/
    if m?
        process.stdout.write "-u #{m[1]} -p #{m[2]} -h #{m[3]} -d #{m[4]}"
    else
        if data == 'Password: '
            process.stderr.write data

그런 다음 * nix 셸에서 다음과 같이 실행합니다.

mongodump `coffee parse-mongo-url.coffee`

mmongoMeteor 데이터베이스에서 편리하게 사용할 수 있도록 모든 Mongo DB 클라이언트 셸 명령을 래핑 하는 도구를 만들었습니다 . npm(노드 패키지 관리자) 를 사용하는 경우 다음을 사용하여 설치할 수 있습니다.

npm install -g mmongo

그렇지 않으면 README를 참조하십시오 .

Meteor 데이터베이스를 백업하려면 이제 다음을 수행 할 수 있습니다.

mmongo test.meteor.com dump 

지역 개발 유성에 업로드하는 방법은 다음과 같습니다.

mmongo restore dump/test_meteor_com

실수로 프로덕션 데이터베이스를 삭제 한 경우 :

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

쉽게 복원 할 수 있습니다.

mmongo test.meteor.com restore dump/test_meteor_com 

컬렉션 (예 tasks:)을 읽을 수있는 것으로 내보내 려면 다음을 수행하십시오.

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

그런 다음 tasks.json텍스트 편집기에서 열고 다음을 사용 하여 변경 사항을 삽입 할 수 있습니다.

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

Github , NPM


나는 당신의 데이터가 mongodb 데이터베이스에 있다고 가정하므로, 그렇다면 질문은 유성보다 몽고와 관련이 있습니다. mongoexport 및 mongoimport 명령 줄 도구를 살펴볼 수 있습니다 .

편집 (예 :) :

mongoexport -h flame.mongohq.com:12345 -u my_user -p my_pwd -d my_db -c my_coll

이 명령 줄 도구를 사용하려면 컴퓨터에 mongodb를 설치해야하며 mongodb 정보가 필요합니다. 위의 예에서 MongoHQ (flame.mongohq.com은 호스트, '12345'는 mongo 서버의 포트)에 연결했지만 실제로 유성 호스팅에서 어떤 Mongo 호스트를 사용하는지 모르겠습니다. Meteor 예제 (TODO, Leaderboard 등)를 로컬에서 시도했다면 Mongo는 기본적으로 로컬 서버를 사용하기 때문에 이미 설치되었을 가능성이 있습니다.


다음은 bash의 또 다른 솔루션입니다.

#! /bin/bash
# inspired by http://stackoverflow.com/questions/11353547/bash-string-extraction-manipulation

# http://www.davidpashley.com/articles/writing-robust-shell-scripts/
set -o nounset
set -o errexit
set -o pipefail
set -x

# stackoverflow.com/questions/7216358/date-command-on-os-x-doesnt-have-iso-8601-i-option
function nowString {
    date -u +"%Y-%m-%dT%H:%M:%SZ"
}

NOW=$(nowString)

# prod_url="mongodb://...:...@...:.../..."
prod_pattern="mongodb://([^:]+):([^@]+)@([^:]+):([^/]+)/(.*)"
prod_url=$(meteor mongo katapoolt --url | tr -d '\n')
[[ ${prod_url} =~ ${prod_pattern} ]]
PROD_USER="${BASH_REMATCH[1]}"
PROD_PASSWORD="${BASH_REMATCH[2]}"
PROD_HOST="${BASH_REMATCH[3]}"
PROD_PORT="${BASH_REMATCH[4]}"
PROD_DB="${BASH_REMATCH[5]}"
PROD_DUMP_DIR=dumps/${NOW}
mkdir -p dumps

# local_url="mongodb://...:.../..."
local_pattern="mongodb://([^:]+):([^/]+)/(.*)"
local_url=$(meteor mongo --url | tr -d '\n')
[[ ${local_url} =~ ${local_pattern} ]]
LOCAL_HOST="${BASH_REMATCH[1]}"
LOCAL_PORT="${BASH_REMATCH[2]}"
LOCAL_DB="${BASH_REMATCH[3]}"

mongodump --host ${PROD_HOST} --port ${PROD_PORT} --username ${PROD_USER} --password ${PROD_PASSWORD} --db ${PROD_DB} --out ${PROD_DUMP_DIR}
mongorestore --port ${LOCAL_PORT} --host ${LOCAL_HOST} --db ${LOCAL_DB} ${PROD_DUMP_DIR}/${PROD_DB}

meteor-backup 은이를 수행하는 가장 쉬운 방법입니다.

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

2015 년 3 월부터 여전히 가져올 모든 컬렉션을 지정해야합니다 ( 이 문제 가 해결 될 때까지 ).


아래 과거의 물건

나는 일을 해요

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

Meteor를 혼동하지 않기 위해이 작은 coffeescript와 함께 엉망진창 확장을 추가했습니다 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]}"

(meteor mongo -U --mongodumpoptions가 이러한 옵션을 제공하거나 mongodump가 mongo : // URL을 수락한다면 더 좋을 것입니다)


# How to upload local db to meteor:

# -h = host, -d = database name, -o = dump folder name
mongodump -h 127.0.0.1:3001 -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 http://production-db-a2.meteor.io:27017 -d myapp_meteor_com -p 'password' folder/

로컬 DB를 원격 DB에 업로드하는 동안 어설 션 예외가 있음

shubham@shubham-PC:$ mongorestore -u client -h http://production-db-a2.meteor.io:27017 -d myapp_meteor_com -p my_password local/
2015-04-22T16:37:38.504+0530 Assertion failure _setName.size() src/mongo/client/dbclientinterface.h 219
2015-04-22T16:37:38.506+0530 0xdcc299 0xd6c7c8 0xd4bfd2 0x663468 0x65d82e 0x605f98 0x606442 0x7f5d102f8ec5 0x60af41 
 mongorestore(_ZN5mongo15printStackTraceERSo+0x39) [0xdcc299]
 mongorestore(_ZN5mongo10logContextEPKc+0x198) [0xd6c7c8]
 mongorestore(_ZN5mongo12verifyFailedEPKcS1_j+0x102) [0xd4bfd2]
 mongorestore(_ZN5mongo16ConnectionStringC2ENS0_14ConnectionTypeERKSsS3_+0x1c8) [0x663468]
 mongorestore(_ZN5mongo16ConnectionString5parseERKSsRSs+0x1ce) [0x65d82e]
 mongorestore(_ZN5mongo4Tool4mainEiPPcS2_+0x2c8) [0x605f98]
 mongorestore(main+0x42) [0x606442]
 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f5d102f8ec5]
 mongorestore() [0x60af41]
terminate called after throwing an instance of 'mongo::AssertionException'
  what():  assertion src/mongo/client/dbclientinterface.h:219
Aborted (core dumped)

이 간단한 Rakefile을 만들어 라이브 DB를 로컬에 복사했습니다.

내 로컬 컴퓨터에 라이브 DB를 복원하려면 그냥 ...

rake copy_live_db

myappmeteor.com의 이름 (예 :)으로 바꿉니다 myapp.meteor.com.

'rubygems'필요
'open-uri'필요

desc "라이브 DB를 로컬 ./dump 폴더에 백업"
작업 : 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

To use an existing local mongodb database on your meteor deploy myAppName site, you need to dump, then restore the mongodb.

Follow the instructions above to mongodump (remember the path) and then run the following to generate your 'mongorestore' (replaces the second step and copy/pasting):

CMD=meteor mongo -U myAppName.meteor.com | tail -1 | sed 's_mongodb://\([a-z0-9\-]*\):\([a-f0-9\-]*\)@\(.*\)/\(.*\)_mongorestore -u \1 -p \2 -h \3 -d \4_'

then

$CMD /path/to/dump 

From Can mongorestore take a single url argument instead of separate arguments?


I think you can use a remotely mounted file system via sshfs and then rsync to synchronize the mongodb's folder itself or your entire Meteor folder I believe as well. This is like doing an incremental backup and potentially more efficient. It's possible to use the same solution for sending changes of your code, etc. so why not get you database changes back at the same time too?! (killing 2 birds with 1 stone)


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]}

참고URL : https://stackoverflow.com/questions/11024888/is-there-a-simple-way-to-export-the-data-from-a-meteor-deployed-app

반응형