如何在MongoDB 2.4.9上从OpenShift进行mongodump并在本地进行mongorestore? [英] How to mongodump from OpenShift and mongorestore locally on MongoDB 2.4.9?

查看:105
本文介绍了如何在MongoDB 2.4.9上从OpenShift进行mongodump并在本地进行mongorestore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是自己做的(因为RockMongo的导出和导入已损坏),所以就在这里发布.

I just did this myself (as a RockMongo export and import was corrupted) so just posting here.

请注意,这是针对具有相应版本mongodumpmongorestore的MongoDB版本2.4.9的.

Note this was for MongoDB verison 2.4.9 with corresponding versions of mongodump and mongorestore.

推荐答案

请先阅读与您的版本相关的文档,进行备份,确保以下解决方案与您的方案相关.

Read the documentation relevant to your versions first, backup, make sure the solution below is relevant to your scenario etc.

http://docs.mongodb.org/v2.4/参考/程序/mongodump/
http://docs.mongodb.org/v2.4/reference/program /mongorestore/

BEGIN 20/11/18更新

我只需要再次重新访问这些步骤,以下内容可能会对其他人有所帮助:

I just had to revisit these steps again, the following may be helpful to others:

01)要在本地计算机上查看所有MongoDB环境变量,请执行以下操作:

01) To view all MongoDB environment variables, from local computer run:

oc exec mongodb-XX-XXXXX env 

(摘自评论此处)

02)要执行转储,请转到openshift控制台中的pod终端并输入以下内容:

02) To perform the dump, go to pod terminal in openshift console and enter this:

mongodump --host MONGODB_SERVICE_HOST:MONGODB_SERVICE_PORT --username admin --password "MONGODB_ADMIN_PASSWORD"

将变量名称替换为运行上一个命令时显示的实际值.

replacing the variable names with the actual values displayed from running the previous command.

我必须使用用户名admin,而不是MONGODB_USER的环境变量值.

I had to use the username admin rather than the environment variable value for MONGODB_USER.

03)如果要压缩转储文件夹,请从控制台的pod终端执行此操作:

03) If you want to zip the dump folder, do this from pod terminal in console:

tar czf my_dump.tar.gz dump

(摘自评论此处)

04)要从本地PC终端下载文件夹,请执行以下操作:

04) To download the folder, from local PC terminal, do this:

oc rsync mongodb-20-XXXXX:/opt/app-root/src/dump /c/Users/Your-Directory

(摘自官方文档 END 20/11/18更新

SSH输入

rhc ssh [app-name]
cd app-root/repo/

检查您拥有的mongodump版本:

Check what version of mongodump you have:

mongodump --version
mongodump version 2.4.9

mongodump

下面的命令将转储* ALL *数据库.

The command below will dump *ALL* databases.

mongodump --host $OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT --username $OPENSHIFT_MONGODB_DB_USERNAME --password $OPENSHIFT_MONGODB_DB_PASSWORD  

Zip Dump文件夹

zip -r dump.zip dump

退出SSH

exit

通过SCP下载

(将下面的环境变量替换为实际值).

(Replace the environment variable below with the actual value).

scp OPENSHIFT_APP_UUID@appname-username.rhcloud.com:~/app-root/repo/dump.zip /var/www/html

SSH重新登录并删除转储文件

rhc ssh [app-name]
cd app-root/repo/
rm -r dump 
rm -r dump.zip

在本地命令行中,转到下载zip文件的目录:

In local command line, go to the directory where you downloaded the zip file:

cd /var/www/html

解压缩转储文件夹

unzip dump.zip -d dump

查看您拥有的mongorestore版本以及所有内容兼容:

See what version of mongorestore you have and that everything is compatible:

mongorestore --version
mongorestore version 2.4.9

这时,我删除了RockMongo中的所有本地*对应*数据库,以便还原过程从头开始创建它们.

At this point, I deleted all my local *corresponding* databases in RockMongo so that the restore process would create them from scratch.

mongorestore

mongorestore dump

使用的默认主机和端口是localhost27017.

The default host and port used is localhost and 27017.

这篇关于如何在MongoDB 2.4.9上从OpenShift进行mongodump并在本地进行mongorestore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆