MongoDB的备份与恢复
<h2>1.1 MongoDB的常用命令</h2><div>
<div class="cnblogs_code">
<pre>mongoexport /<span style="color: rgba(0, 0, 0, 1)"> mongoimport
mongodump</span>/ mongorestore</pre>
</div>
<p> 有以上两组命令在备份与恢复中进行使用。</p>
</div>
<h3>1.1.1 导出工具mongoexport</h3>
<p>Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件。可以通过参数指定导出的数据项,也可以根据指定的条件导出数据。</p>
<p> 该命令的参数如下:</p>
<table class="MsoTable15Grid2" style="width: 100%; border-style: none" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 40.64%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 5" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数说明</span></strong></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-h</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库宿主机的</span><span lang="EN-US">IP</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-u</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的用户名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-p</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的密码</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-d</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-c</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明</span><span lang="EN-US">collection</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-f</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明要导出那些列</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-o</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明到要导出的文件名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-q</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明导出数据的过滤条件</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">--type</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指定文件类型</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--authenticationDatabase</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">验证数据的名称</span></p>
</td>
</tr>
</tbody>
</table>
<p><span style="background-color: rgba(255, 255, 0, 1)"><strong>mongoexport</strong><strong>备份实践</strong></span></p>
<p>备份app库下的vast集合</p>
<div>
<div class="cnblogs_code">
<pre>mongoexport -h <span style="color: rgba(128, 0, 128, 1)">10.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.152</span>:<span style="color: rgba(128, 0, 128, 1)">27017</span> -uroot -proot --authenticationDatabase admin -d app -c vast -o /home/mongod/backup/vasts.dat</pre>
</div>
</div>
<p align="right">注:备份文件的名字可以自定义,默认导出了JSON格式的数据。</p>
<p>导出CSV格式的数据</p>
<div>
<div class="cnblogs_code">
<pre>mongoexport -h <span style="color: rgba(128, 0, 128, 1)">10.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.152</span>:<span style="color: rgba(128, 0, 128, 1)">27017</span> -uroot -proot --authenticationDatabase admin-d app -c vast --type=csv -f id,name -o /home/mongod/backup/vast_csv.dat</pre>
</div>
</div>
<h3>1.1.2 导入工具mongoimport</h3>
<p> Mongodb中的mongoimport工具可以把一个特定格式文件中的内容导入到指定的collection中。该工具可以导入JSON格式数据,也可以导入CSV格式数据。</p>
<p>该命令的参数如下: </p>
<table class="MsoTable15Grid2" style="width: 100%; border-style: none" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 40.64%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 5" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数说明</span></strong></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-h</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库宿主机的</span><span lang="EN-US">IP</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-u</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的用户名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-p</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的密码</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-d</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-c</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明</span><span lang="EN-US">collection</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-f</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明要导出那些列</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-o</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明到要导出的文件名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-q</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明导出数据的过滤条件</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">--drop</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">插入之前先删除原有的</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--headerline</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明第一行是列名,不需要导入。</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-j</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">同时运行的插入操作数(默认为</span><span lang="EN-US">1</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">),并行</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--authenticationDatabase</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">验证数据的名称</span></p>
</td>
</tr>
</tbody>
</table>
<p><strong>mongoimport</strong><strong>恢复实践</strong></p>
<div>
<p class="a1">将之前恢复的数据导入</p>
<div class="cnblogs_code">
<pre>mongoimport -h <span style="color: rgba(128, 0, 128, 1)">10.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.152</span>:<span style="color: rgba(128, 0, 128, 1)">27017</span> -uroot -proot --authenticationDatabase admin-d app -c vast--drop /home/mongod/backup/vasts.dat</pre>
</div>
</div>
<p>将之前恢复的CSV格式数据导入</p>
<div>
<div class="cnblogs_code">
<pre>mongoimport -h <span style="color: rgba(128, 0, 128, 1)">10.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.152</span>:<span style="color: rgba(128, 0, 128, 1)">27017</span> -uroot -proot --authenticationDatabase admin -d app -c vast --type=csv --headerline --file vast_csv.dat</pre>
</div>
</div>
<h3>1.1.3 【实验】mysql数据迁移至mongodb数据库</h3>
<p> mysql相关的参考文档:http://www.cnblogs.com/clsn/category/1131345.html</p>
<p>将mysql数据库中的mysql下的user表导出。</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(255, 0, 255, 1)">user</span>,host,password <span style="color: rgba(0, 0, 255, 1)">from</span> mysql.<span style="color: rgba(255, 0, 255, 1)">user</span>
<span style="color: rgba(0, 0, 255, 1)">into</span> outfile <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">/tmp/user.csv</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
fields terminated </span><span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">,</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
optionally enclosed </span><span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">"</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
escaped </span><span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">"</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
lines terminated </span><span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">\r\n</span><span style="color: rgba(255, 0, 0, 1)">'</span>;</pre>
</div>
</div>
<p>命令说明:</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">into</span> outfile <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">/tmp/user.csv</span><span style="color: rgba(255, 0, 0, 1)">' </span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----导出文件位置</span>
fields terminated <span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">,</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----字段间以,号分隔</span>
optionally enclosed <span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">"</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----字段用"号括起</span>
escaped <span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">"</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----字段中使用的转义符为"</span>
lines terminated <span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">\r\n</span><span style="color: rgba(255, 0, 0, 1)">'</span>; <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">----行以\r\n结束</span></pre>
</div>
</div>
<p>查看导出内容</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">mongod@MongoDB tmp</span><span style="color: rgba(255, 0, 0, 1)">]</span>$ cat <span style="color: rgba(255, 0, 255, 1)">user</span><span style="color: rgba(0, 0, 0, 1)">.csv
"root","localhost",""
"root","db02",""
"root","</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">127.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.1</span><span style="color: rgba(0, 0, 0, 1)">",""
"root","::</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span><span style="color: rgba(0, 0, 0, 1)">",""
"","localhost",""
"","db02",""
"repl","</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>.<span style="color: rgba(128, 128, 128, 1)">%</span>","<span style="color: rgba(128, 128, 128, 1)">*</span><span style="color: rgba(0, 0, 0, 1)">23AE809DDACAF96AF0FD78ED04B6A265E05AA257"
"mha","</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>.<span style="color: rgba(128, 128, 128, 1)">%</span>","<span style="color: rgba(128, 128, 128, 1)">*</span>F4C9AC49A736981AE2739FC2F4A1FD92B4F07929"</pre>
</div>
</div>
<p>在mongodb中导入数据</p>
<div>
<div class="cnblogs_code">
<pre>mongoimport <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin -d app -c user -f user,host,password--type=csv --file /tmp/user.csv</span></pre>
</div>
</div>
<p> 查看导入的内容</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">root@MongoDB tmp</span><span style="color: rgba(255, 0, 0, 1)">]</span># mongo <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 27017 </span>
MongoDB shell version: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">3.2</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span><span style="color: rgba(0, 0, 0, 1)">
connecting </span><span style="color: rgba(0, 0, 255, 1)">to</span>: <span style="color: rgba(128, 0, 0, 1); font-weight: bold">127.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.1</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span><span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">test
</span><span style="color: rgba(128, 128, 128, 1)">></span> <span style="color: rgba(0, 0, 255, 1)">use</span><span style="color: rgba(0, 0, 0, 1)"> app
switched </span><span style="color: rgba(0, 0, 255, 1)">to</span><span style="color: rgba(0, 0, 0, 1)"> db app
</span><span style="color: rgba(128, 128, 128, 1)">></span> db.<span style="color: rgba(255, 0, 255, 1)">user</span><span style="color: rgba(0, 0, 0, 1)">.find()
{ "_id" : ObjectId("5a53206b3b42ae4683180009"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span><span style="color: rgba(0, 0, 0, 1)">" : "root\tlocalhost" }
{ "_id" : ObjectId("5a53206b3b42ae468318000a"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span><span style="color: rgba(0, 0, 0, 1)">" : "root\tdb02" }
{ "_id" : ObjectId("5a53206b3b42ae468318000b"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span>" : "root\t127.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span><span style="color: rgba(0, 0, 0, 1)">" }
{ "_id" : ObjectId("5a53206b3b42ae468318000c"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span>" : "root\t::<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span><span style="color: rgba(0, 0, 0, 1)">" }
{ "_id" : ObjectId("5a53206b3b42ae468318000d"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span><span style="color: rgba(0, 0, 0, 1)">" : "localhost" }
{ "_id" : ObjectId("5a53206b3b42ae468318000e"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span><span style="color: rgba(0, 0, 0, 1)">" : "db02" }
{ "_id" : ObjectId("5a53206b3b42ae468318000f"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span>" : "repl\t10.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.0</span>.<span style="color: rgba(128, 128, 128, 1)">%</span>\t<span style="color: rgba(128, 128, 128, 1)">*</span><span style="color: rgba(0, 0, 0, 1)">23AE809DDACAF96AF0FD78ED04B6A265E05AA257" }
{ "_id" : ObjectId("5a53206b3b42ae4683180010"), "</span><span style="color: rgba(255, 0, 255, 1)">user</span>" : "mha\t10.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.0</span>.<span style="color: rgba(128, 128, 128, 1)">%</span>\t<span style="color: rgba(128, 128, 128, 1)">*</span>F4C9AC49A736981AE2739FC2F4A1FD92B4F07929" }</pre>
</div>
<p> 到此数据迁移完成。</p>
</div>
<h2>1.2 mongodump/mongorestore实践</h2>
<h3>1.2.1 mongodump备份工具</h3>
<p> mongodump的参数与mongoexport的参数基本一致 </p>
<table class="MsoTable15Grid2" style="width: 100%; border-style: none" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 40.64%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 5" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数说明</span></strong></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-h</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库宿主机的</span><span lang="EN-US">IP</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-u</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的用户名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-p</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的密码</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-d</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-c</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明</span><span lang="EN-US">collection</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-o</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明到要导出的文件名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-q</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明导出数据的过滤条件</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--authenticationDatabase</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">验证数据的名称</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">--gzip</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">备份时压缩</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--oplog</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span lang="EN-US">use oplog for taking a point-in-time snapshot</span></p>
</td>
</tr>
</tbody>
</table>
<p><strong>mongodump</strong><strong>参数实践</strong></p>
<div>
<p class="a1">全库备份</p>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin-o /home/mongod/backup/full</span></pre>
</div>
</div>
<p>备份test库</p>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin-d test -o /home/mongod/backup/</span></pre>
</div>
</div>
<p>备份test库下的vast集合</p>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin-d test -c vast -o /home/mongod/backup/</span></pre>
</div>
</div>
<p>压缩备份库</p>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin-d test -o /home/mongod/backup/ --gzip</span></pre>
</div>
</div>
<p>压缩备份单表</p>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin-d test -c vast -o /home/mongod/backup/ --gzip</span></pre>
</div>
</div>
<h3>1.2.2 mongorestore恢复实践</h3>
<p> mongorestore与mongoimport参数类似 </p>
<table class="MsoTable15Grid2" style="width: 100%; border-style: none" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 40.64%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 5" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数说明</span></strong></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-h</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库宿主机的</span><span lang="EN-US">IP</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-u</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的用户名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-p</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的密码</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-d</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明数据库的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-c</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明</span><span lang="EN-US">collection</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的名字</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">-o</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明到要导出的文件名</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">-q</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">指明导出数据的过滤条件</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--authenticationDatabase</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">验证数据的名称</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">--gzip</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">备份时压缩</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--oplog</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center" align="center"><span lang="EN-US">use oplog for taking a point-in-time snapshot</span></p>
</td>
</tr>
<tr>
<td style="width: 40.64%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="40%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">--drop</span></strong></p>
</td>
<td style="width: 59.36%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="59%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">恢复的时候把之前的集合</span><span lang="EN-US">drop</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">掉</span></p>
</td>
</tr>
</tbody>
</table>
<p>全库备份中恢复单库(基于之前的全库备份)</p>
<div>
<div class="cnblogs_code">
<pre>mongorestore <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin -d test --drop/home/mongod/backup/full/test/</span></pre>
</div>
</div>
<p>恢复test库</p>
<div>
<div class="cnblogs_code">
<pre>mongorestore <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin -d test /home/mongod/backup/test/</span></pre>
</div>
</div>
<p>恢复test库下的vast集合</p>
<div>
<div class="cnblogs_code">
<pre>mongorestore <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">27017</span> <span style="color: rgba(128, 128, 128, 1)">-</span>uroot <span style="color: rgba(128, 128, 128, 1)">-</span>proot <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">authenticationDatabase admin -d test -c vast /home/mongod/backup/test/vast.bson</span></pre>
</div>
</div>
<p>--drop参数实践恢复</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 恢复单库</span>
mongorestore -h 10.0.0.152:27017 -uroot -proot --authenticationDatabase admin -d test --drop /home/mongod/backup/test/
<span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 恢复单表</span>
mongorestore -h 10.0.0.152:27017 -uroot -proot --authenticationDatabase admin -d test -c vast --drop /home/mongod/backup/test/vast.bson</pre>
</div>
</div>
<h3>1.2.3 mongoexport/mongoimport与mongodump/mongorestore的对比</h3>
<blockquote>
<p> </p>
<ol style="color: rgba(0, 0, 0, 1)">
<li>mongoexport/mongoimport导入/导出的是JSON格式,而mongodump/mongorestore导入/导出的是BSON格式。</li>
<li>JSON可读性强但体积较大,BSON则是二进制文件,体积小但对人类几乎没有可读性。</li>
<li>在一些mongodb版本之间,BSON格式可能会随版本不同而有所不同,所以不同版本之间用mongodump/mongorestore可能不会成功,具体要看版本之间的兼容性。当无法使用BSON进行跨版本的数据迁移的时候,使用JSON格式即mongoexport/mongoimport是一个可选项。跨版本的mongodump/mongorestore并不推荐,实在要做请先检查文档看两个版本是否兼容(大部分时候是的)。</li>
<li>JSON虽然具有较好的跨版本通用性,但其只保留了数据部分,不保留索引,账户等其他基础信息。使用时应该注意。</li>
</ol></blockquote>
<h2>1.3 MongoDB中的oplog</h2>
<h3>1.3.1 什么是oplog</h3>
<p> MongoDB 的Replication是通过一个日志来存储写操作的,这个日志就叫做oplog。</p>
<p> 在默认情况下,oplog分配的是5%的空闲磁盘空间。通常而言,这是一种合理的设置。可以通过mongod --oplogSize来改变oplog的日志大小。</p>
<p><strong> oplog</strong>是capped collection,因为oplog的特点(不能太多把磁盘填满了,固定大小)需要,MongoDB才发明了capped collection(the oplog is actually the reason capped collections were invented). 定值大小的集合,oplogSizeMB: 2048,oplog是具有幂等性,执行过后的不会反复执行。</p>
<p><strong> <span style="background-color: rgba(255, 255, 0, 1)">值得注意的是,oplog</span></strong><span style="background-color: rgba(255, 255, 0, 1)"><strong>为replica set</strong><strong>或者master/slave</strong><strong>模式专用(standalone</strong><strong>模式运行mongodb</strong><strong>并不推荐)。</strong></span></p>
<p>oplog的位置:</p>
<div>
<blockquote>
<p class="a1" style="color: rgba(0, 0, 0, 1)">oplog在local库: local。oplog</p>
<p class="a1" style="color: rgba(0, 0, 0, 1)">master/slave 架构下:local.oplog.$main;</p>
<p class="a1"> </p>
<p class="a1" style="color: rgba(0, 0, 0, 1)">replica sets 架构下:local.oplog.rs</p>
</blockquote>
</div>
<p>参数说明</p>
<div>
<div class="cnblogs_code">
<pre>$ mongodump --<span style="color: rgba(0, 0, 0, 1)">help
</span>--oplog use oplog <span style="color: rgba(0, 0, 255, 1)">for</span> taking a point-<span style="color: rgba(0, 0, 255, 1)">in</span>-time snapshot</pre>
</div>
<p> 该参数的主要作用是在导出的同时生成一个oplog.bson文件,存放在你开始进行dump到dump结束之间所有的oplog。</p>
</div>
<p> oplog 官方说明https://docs.mongodb.com/manual/core/replica-set-oplog/</p>
<p align="center"> <img src="https://images2017.cnblogs.com/blog/1190037/201801/1190037-20180108182310613-2083013963.png" alt=""></p>
<p> 简单地说,在replica set中oplog是一个定容集合(capped collection),它的默认大小是磁盘空间的5%(可以通过--oplogSizeMB参数修改),位于local库的db.oplog.rs,有兴趣可以看看里面到底有些什么内容。</p>
<p> 其中记录的是整个mongod实例一段时间内数据库的所有变更(插入/更新/删除)操作。当空间用完时新记录自动覆盖最老的记录。</p>
<p> 所以从时间轴上看,oplog的覆盖范围大概是这样的:</p>
<p style="text-align: center"> <img src="https://images2017.cnblogs.com/blog/1190037/201801/1190037-20180108182407426-484765998.png" alt=""> </p>
<p> 其覆盖范围被称作oplog时间窗口。需要注意的是,因为oplog是一个定容集合,所以时间窗口能覆盖的范围会因为你单位时间内的更新次数不同而变化。想要查看当前的oplog时间窗口预计值.</p>
<div>
<div class="cnblogs_code">
<pre>sh1:<span style="color: rgba(0, 0, 255, 1)">PRIMARY</span><span style="color: rgba(128, 128, 128, 1)">></span><span style="color: rgba(0, 0, 0, 1)"> rs.printReplicationInfo()
configured oplog size: 2048MB </span><span style="color: rgba(128, 128, 128, 1)"><</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">集合大小</span>
<span style="color: rgba(255, 0, 255, 1)">log</span> length start <span style="color: rgba(0, 0, 255, 1)">to</span> <span style="color: rgba(0, 0, 255, 1)">end</span>: 305451secs (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">84</span>.85hrs)<span style="color: rgba(128, 128, 128, 1)"><</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">预计窗口覆盖时间</span>
oplog first event time:Thu Jan <span style="color: rgba(128, 0, 0, 1); font-weight: bold">04</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">19</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">39</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">05</span> GMT<span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span><span style="color: rgba(0, 0, 0, 1)"> (CST)
oplog last event time: Mon Jan </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">08</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">08</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">29</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">56</span> GMT<span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span><span style="color: rgba(0, 0, 0, 1)"> (CST)
now: Mon Jan </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">08</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">16</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">33</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">25</span> GMT<span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> (CST)</pre>
</div>
</div>
<p> oplog有一个非常重要的特性——<span style="background-color: rgba(255, 255, 0, 1)"><strong>幂等性(</strong><strong>idempotent</strong><strong>)</strong></span>。即对一个数据集合,使用oplog中记录的操作重放时,无论被重放多少次,其结果会是一样的。</p>
<p> 举例来说,如果oplog中记录的是一个插入操作,并<span style="background-color: rgba(255, 255, 0, 1)"><strong>不会因为你重放了两次,数据库中就得到两条相同的记录</strong>。</span>这是一个很重要的特性.</p>
<h3>1.3.2 oplog.bson作用</h3>
<p>与oplog相关的参数</p>
<table class="MsoTable15Grid2" style="width: 100%; border-style: none" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 29.8%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="29%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 5" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数</span></strong></p>
</td>
<td style="width: 70.2%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" valign="top" width="70%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数说明</span></strong></p>
</td>
</tr>
<tr>
<td style="width: 29.8%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="29%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 68" align="center"><strong><span lang="EN-US">--oplogReplay</span></strong></p>
</td>
<td style="width: 70.2%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" valign="top" width="70%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 64" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">重放</span><span lang="EN-US">oplog.bson</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">中的操作内容</span></p>
</td>
</tr>
<tr>
<td style="width: 29.8%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="29%">
<p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 4" align="center"><strong><span lang="EN-US">--oplogLimit</span></strong></p>
</td>
<td style="width: 70.2%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" valign="top" width="70%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">与</span><span lang="EN-US">--oplogReplay</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">一起使用时,可以限制重放到的时间点</span></p>
</td>
</tr>
</tbody>
</table>
<p> 首先要明白的一个问题是数据之间互相有依赖性,比如集合A中存放了订单,集合B中存放了订单的所有明细,那么只有一个订单有完整的明细时才是正确的状态。</p>
<p> 假设在任意一个时间点,A和B集合的数据都是完整对应并且有意义的(对非关系型数据库要做到这点并不容易,且对于MongoDB来说这样的数据结构并非合理。但此处我们假设这个条件成立),那么如果A处于时间点x,而B处于x之后的一个时间点y时,可以想象A和B中的数据极有可能不对应而失去意义。</p>
<p> mongodump的进行过程中并不会把数据库锁死以保证整个库冻结在一个固定的时间点,这在业务上常常是不允许的。所以就有了dump的最终结果中A集合是10点整的状态,而B集合则是10点零1分的状态这种情况。</p>
<p> 这样的备份即使恢复回去,可以想象得到的结果恐怕意义有限。</p>
<p> 那么上面这个oplog.bson的意义就在这里体现出来了。如果在dump数据的基础上,再重做一遍oplog中记录的所有操作,这时的数据就可以代表dump结束时那个时间点(point-in-time)的数据库状态。</p>
<h3>1.3.3 【模拟】mongodump使用</h3>
<p>首先我们模拟一个不断有插入操作的集合foo,</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">use</span><span style="color: rgba(0, 0, 0, 1)"> clsn
</span><span style="color: rgba(0, 0, 255, 1)">for</span>(<span style="color: rgba(255, 0, 255, 1)">var</span> i <span style="color: rgba(128, 128, 128, 1)">=</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>; i <span style="color: rgba(128, 128, 128, 1)"><</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10000</span>; i<span style="color: rgba(128, 128, 128, 1)">++</span><span style="color: rgba(0, 0, 0, 1)">) {
db.clsn.</span><span style="color: rgba(0, 0, 255, 1)">insert</span><span style="color: rgba(0, 0, 0, 1)">({a: i});
}</span></pre>
</div>
<p> 然后在插入过程中模拟一次mongodump并指定--oplog。</p>
</div>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021--oplog-o /home/mongod/backup/oplog</span></pre>
</div>
<p> <span style="color: rgba(255, 0, 0, 1)"><strong>注意:</strong></span>--oplog选项只对全库导出有效,所以不能指定-d选项。</p>
</div>
<p> 因为整个实例的变更操作都会集中在local库中的oplog.rs集合中。</p>
<p>根据上面所说,从dump开始的时间系统将记录所有的oplog到oplog.bson中,所以我们得到这些文件:</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">mongod@MongoDB ~</span><span style="color: rgba(255, 0, 0, 1)">]</span>$ ll <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">oplog
total </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span><span style="color: rgba(0, 0, 0, 1)">
drwxrwxr</span><span style="color: rgba(128, 128, 128, 1)">-</span>x <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span> mongod mongod <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4096</span> Jan<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">16</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">49</span><span style="color: rgba(0, 0, 0, 1)"> admin
drwxrwxr</span><span style="color: rgba(128, 128, 128, 1)">-</span>x <span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span> mongod mongod <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4096</span> Jan<span style="color: rgba(128, 0, 0, 1); font-weight: bold">8</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">16</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">49</span><span style="color: rgba(0, 0, 0, 1)"> clsn
</span><span style="color: rgba(128, 128, 128, 1)">-</span>rw<span style="color: rgba(128, 128, 128, 1)">-</span>rw<span style="color: rgba(128, 128, 128, 1)">-</span>r<span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 1 mongod mongod77256 Jan8 16:49 oplog.bson</span></pre>
</div>
</div>
<p>查看oplog.bson中第一条和最后一条内容</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">mongod@MongoDB oplog</span><span style="color: rgba(255, 0, 0, 1)">]</span>$ bsondump oplog.bson<span style="color: rgba(128, 128, 128, 1)">>/</span>tmp<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">oplog.bson.tmp
</span><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">mongod@MongoDB oplog</span><span style="color: rgba(255, 0, 0, 1)">]</span>$ head <span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> <span style="color: rgba(128, 128, 128, 1)">/</span>tmp<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">oplog.bson.tmp
{"ts":{"$</span><span style="color: rgba(0, 0, 255, 1)">timestamp</span>":{"t":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1515401553</span>,"i":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">666</span>}},"t":{"$numberLong":"<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span>"},"h":{"$numberLong":"<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5737315465472464503</span>"},"v":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span>,"op":"i","ns":"clsn.clsn1","o":{"_id":{"$oid":"5a533151cc075bd0aa461327"},"a":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3153.0</span><span style="color: rgba(0, 0, 0, 1)">}}
</span><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">mongod@MongoDB oplog</span><span style="color: rgba(255, 0, 0, 1)">]</span>$ tail <span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span> <span style="color: rgba(128, 128, 128, 1)">/</span>tmp<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">oplog.bson.tmp
{"ts":{"$</span><span style="color: rgba(0, 0, 255, 1)">timestamp</span>":{"t":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1515401556</span>,"i":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">34</span>}},"t":{"$numberLong":"<span style="color: rgba(128, 0, 0, 1); font-weight: bold">5</span>"},"h":{"$numberLong":"<span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">7438621314956315593</span>"},"v":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2</span>,"op":"i","ns":"clsn.clsn1","o":{"_id":{"$oid":"5a533154cc075bd0aa4615de"},"a":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">3848.0</span>}}</pre>
</div>
<p> 最终dump出的数据既不是最开始的状态,也不是最后的状态,而是中间某个随机状态。这正是因为集合不断变化造成的。</p>
</div>
<p> 使用mongorestore来恢复</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">mongod@MongoDB oplog</span><span style="color: rgba(255, 0, 0, 1)">]</span>$ mongorestore <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021--oplogReplay--drop /home/mongod/backup/oplog</span>
<span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">18.053</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> building a list <span style="color: rgba(0, 0, 255, 1)">of</span> dbs <span style="color: rgba(128, 128, 128, 1)">and</span> collections <span style="color: rgba(0, 0, 255, 1)">to</span> <span style="color: rgba(0, 0, 255, 1)">restore</span> <span style="color: rgba(0, 0, 255, 1)">from</span> <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">oplog dir
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">18.066</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> reading metadata <span style="color: rgba(0, 0, 255, 1)">for</span> clsn.clsn <span style="color: rgba(0, 0, 255, 1)">from</span> <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span>oplog<span style="color: rgba(128, 128, 128, 1)">/</span>clsn<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">clsn.metadata.json
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">18.157</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> restoring clsn.clsn <span style="color: rgba(0, 0, 255, 1)">from</span> <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span>oplog<span style="color: rgba(128, 128, 128, 1)">/</span>clsn<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">clsn.bson
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">18.178</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> reading metadata <span style="color: rgba(0, 0, 255, 1)">for</span> clsn.clsn1 <span style="color: rgba(0, 0, 255, 1)">from</span> <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span>oplog<span style="color: rgba(128, 128, 128, 1)">/</span>clsn<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">clsn1.metadata.json
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">18.216</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> restoring clsn.clsn1 <span style="color: rgba(0, 0, 255, 1)">from</span> <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span>oplog<span style="color: rgba(128, 128, 128, 1)">/</span>clsn<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 0, 1)">clsn1.bson
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">18.669</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> restoring indexes <span style="color: rgba(0, 0, 255, 1)">for</span> collection clsn.clsn1 <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> metadata
</span><span style="color: rgba(255, 204, 0, 1)"><span style="font-weight: bold">2018</span>-<span style="font-weight: bold">01</span>-08T16:<span style="font-weight: bold">59</span>:<span style="font-weight: bold">18.679</span>+<span style="font-weight: bold">0800</span> finished restoring clsn.clsn1 (<span style="font-weight: bold">3165</span> documents)
<span style="font-weight: bold">2018</span>-<span style="font-weight: bold">01</span>-08T16:<span style="font-weight: bold">59</span>:<span style="font-weight: bold">19.850</span>+<span style="font-weight: bold">0800</span> restoring indexes for collection clsn.clsn from metadata
<span style="font-weight: bold">2018</span>-<span style="font-weight: bold">01</span>-08T16:<span style="font-weight: bold">59</span>:<span style="font-weight: bold">19.851</span>+<span style="font-weight: bold">0800</span> finished restoring clsn.clsn (<span style="font-weight: bold">10000</span> documents)
<span style="font-weight: bold">2018</span>-<span style="font-weight: bold">01</span>-08T16:<span style="font-weight: bold">59</span>:<span style="font-weight: bold">19.851</span>+<span style="font-weight: bold">0800</span> replaying oplog
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">2018</span><span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">01</span><span style="color: rgba(128, 128, 128, 1)">-</span>08T16:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">59</span>:<span style="color: rgba(128, 0, 0, 1); font-weight: bold">19.919</span><span style="color: rgba(128, 128, 128, 1)">+</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0800</span> done</pre>
</div>
</div>
<p> 注意黄字体,第一句表示clsn.clsn1集合中恢复了3165个文档;第二句表示重放了oplog中的所有操作。所以理论上clsn1应该有16857个文档(3165个来自clsn.bson,剩下的来自oplog.bson)。验证一下:</p>
<div>
<div class="cnblogs_code">
<pre>sh1:<span style="color: rgba(0, 0, 255, 1)">PRIMARY</span><span style="color: rgba(128, 128, 128, 1)">></span> db.clsn1.<span style="color: rgba(255, 0, 255, 1)">count</span><span style="color: rgba(0, 0, 0, 1)">()
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">3849</span></pre>
</div>
<p> 这就是带oplog的mongodump的真正作用。</p>
</div>
<h3>1.3.4 从别处而来的oplog</h3>
<p>oplog有两种来源:</p>
<div>
<blockquote>
<p class="a" style="color: rgba(0, 0, 0, 1)">1、mongodump时加上--oplog选项,自动生成的oplog,这种方式的oplog直接 --oplogReplay 就可以恢复</p>
<p class="a"> </p>
<p class="a" style="color: rgba(0, 0, 0, 1)">2、从别处而来,除了--oplog之外,人为获取的oplog</p>
</blockquote>
</div>
<p>例如:</p>
<div>
<div class="cnblogs_code">
<pre>mongodump<span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021 -d local -c oplog.rs</span></pre>
</div>
<p> 既然dump出的数据配合oplog就可以把数据库恢复到某个状态,那是不是拥有一份从某个时间点开始备份的dump数据,再加上从dump开始之后的oplog,如果oplog足够长,是不是就可以把数据库恢复到其后的任意状态了?<strong>是的!</strong></p>
</div>
<p> 事实上replica set正是依赖oplog的重放机制在工作。当secondary第一次加入replica set时做的initial sync就相当于是在做mongodump,此后只需要不断地同步和重放oplog.rs中的数据,就达到了secondary与primary同步的目的。</p>
<p> 既然oplog一直都在oplog.rs中存在,我们为什么还需要在mongodump时指定--oplog呢?需要的时候从oplog.rs中拿不就完了吗?答案是肯定的,你确实可以只dump数据,不需要oplog。</p>
<p>在需要的时候可以再从oplog.rs中取。但前提是oplog时间窗口必须能够覆盖dump的开始时间。</p>
<p><span style="background-color: rgba(255, 255, 0, 1)"><strong>及时点恢复场景模拟</strong></span></p>
<p>模拟生产环境</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">for</span>(i<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span>;i<span style="color: rgba(128, 128, 128, 1)"><</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">300000</span>;i<span style="color: rgba(128, 128, 128, 1)">++</span>){ db.oplog.<span style="color: rgba(0, 0, 255, 1)">insert</span>({"id":i,"name":"shenzheng","age":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">70</span>,"date":new Date()}); }</pre>
</div>
</div>
<p> 插入数据的同时备份</p>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021--oplog-o /home/mongod/backup/config</span></pre>
</div>
</div>
<div>
<p class="a"> 备份完成后进行次错误的操作</p>
<div class="cnblogs_code">
<pre> db.oplog.remove({});</pre>
</div>
</div>
<p>备份oplog.rs文件</p>
<div>
<div class="cnblogs_code">
<pre>mongodump <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021 -d local -c oplog.rs -o/home/mongod/backup/config/oplog</span></pre>
</div>
</div>
<p> 恢复之前备份的数据</p>
<div>
<div class="cnblogs_code">
<pre>mongorestore <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021--oplogReplay /home/mongod/backup/config</span></pre>
</div>
</div>
<p> 截取oplog,找到发生误删除的时间点</p>
<div>
<div class="cnblogs_code">
<pre>bsondump oplog.rs.bson <span style="color: rgba(128, 128, 128, 1)">|</span>egrep "\"op\":\"d\"\,\"ns\":\"test\.oplog\"" <span style="color: rgba(128, 128, 128, 1)">|</span>head <span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span><span style="color: rgba(0, 0, 0, 1)">
"t":</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1515379110</span>,"i":<span style="color: rgba(128, 0, 0, 1); font-weight: bold">1</span></pre>
</div>
</div>
<p> 复制oplog到备份目录</p>
<div>
<div class="cnblogs_code">
<pre>cp<span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span>config<span style="color: rgba(128, 128, 128, 1)">/</span>oplog<span style="color: rgba(128, 128, 128, 1)">/</span>oplog.rs.bson <span style="color: rgba(128, 128, 128, 1)">/</span>home<span style="color: rgba(128, 128, 128, 1)">/</span>mongod<span style="color: rgba(128, 128, 128, 1)">/</span><span style="color: rgba(0, 0, 255, 1)">backup</span><span style="color: rgba(128, 128, 128, 1)">/</span>config<span style="color: rgba(128, 128, 128, 1)">/</span>oplog.bson</pre>
</div>
</div>
<p> 进行恢复,添加之前找到的误删除的点(limt)</p>
<div>
<div class="cnblogs_code">
<pre>mongorestore <span style="color: rgba(128, 128, 128, 1)">-</span>h <span style="color: rgba(128, 0, 0, 1); font-weight: bold">10.0</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.152</span> <span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">port 28021 --oplogReplay --oplogLimit "1515379110:1"/home/mongod/backup/config</span></pre>
</div>
<p> <span style="color: rgba(255, 0, 0, 1); background-color: rgba(255, 255, 0, 1)"><strong> </strong><strong>至此一次恢复就完成了</strong></span></p>
</div>
<h3>1.3.5 mongodb的备份准则</h3>
<p>只针对replica或master/slave,满足这些准则MongoDB就可以进行point-in-time恢复操作:</p>
<div>
<blockquote>
<p> </p>
<ol style="color: rgba(0, 0, 0, 1)">
<li>任意两次数据备份的时间间隔(第一次备份开始到第二次备份结束)不能超过oplog时间窗口覆盖范围。</li>
<li>在上次数据备份的基础上,在oplog时间窗口没有滑出上次备份结束的时间点前进行完整的oplog备份。请充分考虑oplog备份需要的时间,权衡服务器空间情况确定oplog备份间隔。</li>
</ol></blockquote>
</div>
<p>实际应用中的注意事项:</p>
<blockquote>
<p> </p>
<ol style="color: rgba(0, 0, 0, 1)">
<li>考虑到oplog时间窗口是个变化值,请关注oplog时间窗口的具体时间。</li>
<li>在靠近oplog时间窗口滑动出有效时间之前必须要有足够的时间dump出需要的oplog.rs,请预留足够的时间,不要顶满时间窗口再备份。</li>
<li>当灾难发生时,第一件事情就是要停止数据库的写入操作,以往oplog滑出时间窗口。特别是像上述这样的remove({})操作,瞬间就会插入大量d记录从而导致oplog迅速滑出时间窗口。</li>
</ol></blockquote>
<p>分片集群的备份注意事项</p>
<div>
<blockquote>
<p class="a" style="color: rgba(0, 0, 0, 1)">1、备份什么?</p>
<p class="a" style="color: rgba(0, 0, 0, 1)"> (1)configserver</p>
<p class="a" style="color: rgba(0, 0, 0, 1)"> (2)每一个shard节点</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">2、备份需要注意什么?</p>
<p class="a" style="color: rgba(0, 0, 0, 1)"> (1)元数据和真实数据要有对等性(blancer迁移的问题,会造成config和shard备份不一致)</p>
<p class="a"> </p>
<p class="a" style="color: rgba(0, 0, 0, 1)"> (2)不同部分备份结束时间点不一样,恢复出来的数据就是有问题的。</p>
</blockquote>
</div>
<h2>1.4 MongoDB监控</h2>
<p>为什么要监控?</p>
<div>
<blockquote>
<p class="a"><span style="color: rgba(0, 0, 0, 1)">监控及时获得应用的运行状态信息,在问题出现时及时发现。</span></p>
</blockquote>
</div>
<p>监控什么?</p>
<div>
<blockquote>
<p class="a"><span style="color: rgba(0, 0, 0, 1)">CPU、内存、磁盘I/O、应用程序(MongoDB)、进程监控(ps -aux)、错误日志监控</span></p>
</blockquote>
</div>
<h3>1.4.1 MongoDB集群监控方式</h3>
<div>
<div class="cnblogs_code">
<pre>db.serverStatus()</pre>
</div>
<p> 查看实例运行状态(内存使用、锁、用户连接等信息)</p>
</div>
<p> 通过比对前后快照进行性能分析</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">connections</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 128, 0, 1)"># </span><span style="color: rgba(0, 128, 0, 1)">当前连接到本机处于活动状态的连接数</span>
<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">activeClients</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 连接到当前实例处于活动状态的客户端数量</span>
<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">locks</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 128, 0, 1)">#</span><span style="color: rgba(0, 128, 0, 1)"> 锁相关参数</span>
<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">opcounters</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 128, 0, 1)"># </span><span style="color: rgba(0, 128, 0, 1)">启动之后的参数</span>
<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">opcountersRepl</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 128, 0, 1)"># </span><span style="color: rgba(0, 128, 0, 1)">复制想关</span>
<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">storageEngine</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 128, 0, 1)"># </span><span style="color: rgba(0, 128, 0, 1)">查看数据库的存储引擎</span>
<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">mem</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 128, 0, 1)"># </span><span style="color: rgba(0, 128, 0, 1)">内存相关</span></pre>
</div>
<div>
<p class="a1">状态:</p>
<div class="cnblogs_code">
<pre>db.stats()</pre>
</div>
</div>
<p>显示信息说明:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">db</span><span style="color: rgba(128, 0, 0, 1)">"</span> : <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">test</span><span style="color: rgba(128, 0, 0, 1)">"</span> ,表示当前是针对<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">test</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">这个数据库的描述。想要查看其他数据库,可以先运行$ use databasename(e.g$use admiin).
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">collections</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 3<span style="color: rgba(0, 0, 0, 1)">,表示当前数据库有多少个collections.可以通过运行show collections查看当前数据库具体有哪些collection.
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">objects</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 13<span style="color: rgba(0, 0, 0, 1)">,表示当前数据库所有collection总共有多少行数据。显示的数据是一个估计值,并不是非常精确。
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">avgObjSize</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 36<span style="color: rgba(0, 0, 0, 1)">,表示每行数据是大小,也是估计值,单位是bytes
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">dataSize</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 468<span style="color: rgba(0, 0, 0, 1)">,表示当前数据库所有数据的总大小,不是指占有磁盘大小。单位是bytes
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">storageSize</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 13312<span style="color: rgba(0, 0, 0, 1)">,表示当前数据库占有磁盘大小,单位是bytes,因为mongodb有预分配空间机制,为了防止当有大量数据插入时对磁盘的压力,因此会事先多分配磁盘空间。
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">numExtents</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 3<span style="color: rgba(0, 0, 0, 1)">,似乎没有什么真实意义。我弄明白之后再详细补充说明。
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">indexes</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 1<span style="color: rgba(0, 0, 0, 1)"> ,表示system.indexes表数据行数。
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">indexSize</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 8192<span style="color: rgba(0, 0, 0, 1)">,表示索引占有磁盘大小。单位是bytes
</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">fileSize</span><span style="color: rgba(128, 0, 0, 1)">"</span> : 201326592,表示当前数据库预分配的文件大小,例如test.0,test.1,不包括test.ns。</pre>
</div>
<h3>1.4.2 mongostat</h3>
<p> 实时数据库状态,读写、加锁、索引命中、缺页中断、读写等待队列等情况。</p>
<p> 每秒刷新一次状态值,并能提供良好的可读性,通过这些参数可以观察到MongoDB系统整体性能情况。</p>
<div>
<div class="cnblogs_code">
<pre>$ mongostat -h 10.0.0.152 --port 28017<span style="color: rgba(0, 0, 0, 1)">
insert query update delete getmore command flushes mappedvsize res faults qr</span>|qw ar|<span style="color: rgba(0, 0, 0, 1)">aw netIn netOut conn set repl time
</span>*0 *0 *0 *0 0 1|0 0 303.0M 13.0M 0 0|0 0|0143b 8k 1 RTR 2018-01-08T17:28:42+08:00</pre>
</div>
</div>
<p>参数说明: </p>
<table class="MsoTable15Grid2" style="width: 100%; border-style: none" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width: 14.88%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 5"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1.5pt; border-bottom-color: rgba(102, 102, 102, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 1"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">参数说明</span></strong></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 68"><strong><span lang="EN-US">insert</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">每秒插入量</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 4"><strong><span lang="EN-US">query</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">每秒查询量</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 68"><strong><span lang="EN-US">update</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">每秒更新量</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 4"><strong><span lang="EN-US">delete</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">每秒删除量</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 68"><strong><span lang="EN-US">conn</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">当前连接数</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 4"><strong><span lang="EN-US">qr|qw </span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">客户端查询排队长度(读</span><span lang="EN-US">|</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">写)最好为</span><span lang="EN-US">0</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">,如果有堆积,数据库处理慢。</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 68"><strong><span lang="EN-US">ar|aw</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); background: rgba(204, 204, 204, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">活跃客户端数量(读</span><span lang="EN-US">|</span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">写)</span></p>
</td>
</tr>
<tr>
<td style="width: 14.88%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); border-right-width: 1pt; border-right-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="14%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 4"><strong><span lang="EN-US">time</span></strong></p>
</td>
<td style="width: 85.12%; border-top: none; border-right: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(102, 102, 102, 1); padding: 0 5.4pt" width="85%">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">当前时间</span></p>
</td>
</tr>
</tbody>
</table>
<p><span style="background-color: rgba(255, 255, 0, 1)"><strong>mongotop</strong><strong>命令说明:</strong></span></p>
<div>
<div class="cnblogs_code">
<pre>$ mongotop-h 127.0.0.1:27017
2018-01-08T17:32:56.623+0800 connected to: 127.0.0.1:27017<span style="color: rgba(0, 0, 0, 1)">
ns total read write </span>2018-01-08T17:32:57+08:00<span style="color: rgba(0, 0, 0, 1)">
admin.system.roles 0ms 0ms 0ms
admin.system.users 0ms 0ms 0ms
admin.system.version 0ms 0ms 0ms
app.user 0ms 0ms 0ms
automationcore.automation.job.status 0ms 0ms 0ms
automationcore.config.automation 0ms 0ms 0ms
automationcore.config.automationTemplates 0ms 0ms 0ms
automationcore.config.automationTemplates_archive 0ms 0ms 0ms
automationcore.config.automation_archive 0ms 0ms 0ms
automationstatus.lastAgentStatus 0ms 0ms 0ms </span></pre>
</div>
</div>
<p>mongotop重要指标</p>
<div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">ns:数据库命名空间,后者结合了数据库名称和集合。
total:mongod在这个命令空间上花费的总时间。
</span><span style="color: rgba(0, 0, 255, 1)">read</span><span style="color: rgba(0, 0, 0, 1)">:在这个命令空间上mongod执行读操作花费的时间。
write:在这个命名空间上mongod进行写操作花费的时间。</span></pre>
</div>
</div>
<h3>1.4.3 db级别命令</h3>
<div>
<div class="cnblogs_code">
<pre>db.currentOp()</pre>
</div>
<p> 查看数据库当前执行什么操作。</p>
</div>
<p> 用于查看长时间运行进程。</p>
<p> 通过(执行时长、操作、锁、等待锁时长)等条件过滤。</p>
<p> 如果发现一个操作太长,把数据库卡死的话,可以用这个命令杀死他:> db.killOp(608605)</p>
<div>
<div class="cnblogs_code">
<pre>db.setProfilingLevel()</pre>
</div>
<p> 设置server级别慢日志</p>
</div>
<p> 打开profiling:</p>
<div>
<blockquote>
<p class="a" style="color: rgba(0, 0, 0, 1)">0:不保存</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">1:保存慢查询日志</p>
<p class="a"> </p>
<p class="a" style="color: rgba(0, 0, 0, 1)">2:保存所有查询日志</p>
</blockquote>
</div>
<p> 注意:级别是对应当前的数据库,而阈值是全局的。</p>
<blockquote>
<p style="color: rgba(0, 0, 0, 1)">查看profiling状态</p>
<p style="color: rgba(0, 0, 0, 1)">查看慢查询:system.profile</p>
<p> </p>
<p style="color: rgba(0, 0, 0, 1)">关闭profiling</p>
</blockquote>
<div>
<p class="a1" style="text-align: center">企业工具ops manager官方文档: https://docs.opsmanager.mongodb.com/v3.6/</p>
</div>
<h2>1.5 MongoDB集群性能优化方案</h2>
<h3>1.5.1 优化方向</h3>
<div>
<blockquote>
<p class="a" style="color: rgba(0, 0, 0, 1)">硬件(内存、SSD)</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">收缩数据</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">增加新的机器、新的副本集</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">集群分片键选择</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">chunk大小设置</p>
<p class="a"> </p>
<p class="a" style="color: rgba(0, 0, 0, 1)">预分片(预先分配存储空间)</p>
</blockquote>
</div>
<h3>1.5.2 存储引擎方面</h3>
<p> WiredTiger是3.0以后的默认存储引擎,细粒度的并发控制和数据压缩提供了更高的性能和存储效率。3.0以前默认的MMAPv1也提高了性能。</p>
<p> 在MongoDB复制集中可以组合多钟存储引擎,各个实例实现不同的应用需求。</p>
<h3>1.5.3 其他优化建议</h3>
<div>
<blockquote>
<p class="a" style="color: rgba(0, 0, 0, 1)">收缩数据</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">预分片</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">增加新的机器、新的副本集</p>
<p class="a" style="color: rgba(0, 0, 0, 1)">集群分片键选择</p>
<p class="a"> </p>
<p class="a" style="color: rgba(0, 0, 0, 1)">chunk大小设置</p>
</blockquote>
</div>
<h2>1.6 附录:Aliyun 备份策略</h2>
<h3>1.6.1 MongoDB云数据库备份/恢复</h3>
<p align="center"><img src="https://images2017.cnblogs.com/blog/1190037/201801/1190037-20180108183457535-611170065.png" alt=""> </p>
<p>备份策略:</p>
<div>
<blockquote><ol>
<li>从hidden节点备份</li>
<li>每天一次全量备份</li>
<li>持续拉取oplog增量备份</li>
<li>定期巡检备份有效性</li>
<li>恢复时克隆到新实例</li>
</ol></blockquote>
</div>
<h3>1.6.2 全量备份方法</h3>
<p align="center"> <img src="https://images2017.cnblogs.com/blog/1190037/201801/1190037-20180108183559394-794158819.png" alt=""></p>
<h3>1.6.3 逻辑备份流程 - mongodump</h3>
<p align="center"> <img src="https://images2017.cnblogs.com/blog/1190037/201801/1190037-20180108183607176-300071779.png" alt=""></p>
<p>特点:</p>
<div>
<blockquote><ol>
<li>全量遍历所有数据、</li>
<li>备份、恢复慢</li>
<li>对业务影响较大</li>
<li>无需备份索引、恢复时重建</li>
<li>通用性强</li>
</ol></blockquote>
</div>
<h3>1.6.4 物理备份流程</h3>
<p align="center"><img src="https://images2017.cnblogs.com/blog/1190037/201801/1190037-20180108183621379-438094970.png" alt=""> </p>
<p>备份特点</p>
<div>
<blockquote><ol>
<li>拷贝数据目录所有文件,效率高</li>
<li>备份、恢复快</li>
<li>对业务影响较小</li>
<li>跟数据库版本、配置强关联</li>
</ol></blockquote>
</div>
<h3>1.6.5 逻辑备份 vs 物理备份</h3>
<table class="MsoNormalTable" style="width: 100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; height: 7.85pt">
<td style="width: 18.9%; border-width: 1pt 1pt 3pt; border-color: rgba(255, 255, 255, 1); background: rgba(129, 184, 89, 1); padding: 0.75pt 0.75pt 0; height: 7.85pt" valign="top" width="18%"> </td>
<td style="width: 42.06%; border-width: 1pt 1pt 3pt initial; border-color: rgba(255, 255, 255, 1) rgba(255, 255, 255, 1) rgba(255, 255, 255, 1) initial; border-left-style: none; background: rgba(129, 184, 89, 1); padding: 3.05pt 0.75pt 0; height: 7.85pt" valign="top" width="42%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">逻辑备份</span></strong></p>
</td>
<td style="width: 39.02%; border-width: 1pt 1pt 3pt initial; border-color: rgba(255, 255, 255, 1) rgba(255, 255, 255, 1) rgba(255, 255, 255, 1) initial; border-left-style: none; background: rgba(129, 184, 89, 1); padding: 3.05pt 0.75pt 0; height: 7.85pt" valign="top" width="39%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">物理备份</span></strong></p>
</td>
</tr>
<tr style="mso-yfti-irow: 1; height: 12.55pt">
<td style="width: 18.9%; border-width: initial 1pt 1pt; border-color: initial rgba(255, 255, 255, 1) rgba(255, 255, 255, 1); border-top-style: none; background: rgba(221, 232, 216, 1); padding: 2.05pt 0.75pt 0; height: 12.55pt" valign="top" width="18%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">备份效率</span></p>
</td>
<td style="width: 42.06%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(221, 232, 216, 1); padding: 2.05pt 0.75pt 0; height: 12.55pt" valign="top" width="42%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">低</span></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">数据库接口读取数据</span></p>
</td>
<td style="width: 39.02%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(221, 232, 216, 1); padding: 2.05pt 0.75pt 0; height: 12.55pt" valign="top" width="39%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">高</span></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">拷贝物理文件</span></p>
</td>
</tr>
<tr style="mso-yfti-irow: 2; height: 31.55pt">
<td style="width: 18.9%; border-width: initial 1pt 1pt; border-color: initial rgba(255, 255, 255, 1) rgba(255, 255, 255, 1); border-top-style: none; background: rgba(239, 244, 237, 1); padding: 3.05pt 0.75pt 0; height: 31.55pt" valign="top" width="18%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">恢复效率</span></p>
</td>
<td style="width: 42.06%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(239, 244, 237, 1); padding: 3.05pt 0.75pt 0; height: 31.55pt" valign="top" width="42%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">低</span></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">下载备份集</span> <span lang="EN-US">+ </span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">导入数据</span> <span lang="EN-US">+ </span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">建立索引</span></p>
</td>
<td style="width: 39.02%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(239, 244, 237, 1); padding: 3.05pt 0.75pt 0; height: 31.55pt" valign="top" width="39%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">高</span></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">下载备份集</span> <span lang="EN-US">+ </span><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">启动进程</span></p>
</td>
</tr>
<tr style="mso-yfti-irow: 3; height: 1.15pt">
<td style="width: 18.9%; border-width: initial 1pt 1pt; border-color: initial rgba(255, 255, 255, 1) rgba(255, 255, 255, 1); border-top-style: none; background: rgba(221, 232, 216, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="18%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">备份影响</span></p>
</td>
<td style="width: 42.06%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(221, 232, 216, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="42%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">大</span></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">直接与业务争抢资源</span></p>
</td>
<td style="width: 39.02%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(221, 232, 216, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="39%">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">小</span></strong></p>
</td>
</tr>
<tr style="mso-yfti-irow: 4; height: 1.15pt">
<td style="width: 18.9%; border-width: initial 1pt 1pt; border-color: initial rgba(255, 255, 255, 1) rgba(255, 255, 255, 1); border-top-style: none; background: rgba(239, 244, 237, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="18%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">备份集大小</span></p>
</td>
<td style="width: 42.06%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(239, 244, 237, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="42%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">比原库小</span></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">无需备份索引数据</span></p>
</td>
<td style="width: 39.02%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(239, 244, 237, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="39%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">与原库相同</span></p>
</td>
</tr>
<tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes; height: 1.15pt">
<td style="width: 18.9%; border-width: initial 1pt 1pt; border-color: initial rgba(255, 255, 255, 1) rgba(255, 255, 255, 1); border-top-style: none; background: rgba(221, 232, 216, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="18%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">兼容性</span></p>
</td>
<td style="width: 42.06%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(221, 232, 216, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="42%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">兼容绝大部分版本</span></p>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">可跨存储引擎</span></p>
</td>
<td style="width: 39.02%; border-top: none; border-left: none; border-bottom-width: 1pt; border-bottom-color: rgba(255, 255, 255, 1); border-right-width: 1pt; border-right-color: rgba(255, 255, 255, 1); background: rgba(221, 232, 216, 1); padding: 3.05pt 0.75pt 0; height: 1.15pt" valign="top" width="39%">
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-family: "微软雅黑", sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">依赖存储布局</span></p>
</td>
</tr>
</tbody>
</table>
<p style="text-align: right"> 更多内容参考http://www.mongoing.com/archives/3962</p>
<h2>1.7 参考文献</h2>
<div>
<blockquote>
<p class="a"> http://www.cnblogs.com/yaoxing/p/mongodb-backup-rules.html</p>
<p class="a"> http://blog.itpub.net/15498/viewspace-2073272/</p>
<p class="a"> http://www.mongoing.com/archives/3962</p>
<p class="a"> http://chenzhou123520.iteye.com/blog/1641319</p>
<p class="a"> http://www.mongoing.com/oplog</p>
<p class="a"> https://www.cnblogs.com/datazhang/p/5917861.html</p>
</blockquote>
</div>
<p> </p>
</div>
<div id="MySignature" role="contentinfo">
<div style="padding: 5px; background: #ff9; border: solid 1px #ccc">
作者:惨绿少年
<br>
出处:http://clsn.io
<br>
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
<br>
</div><br><br>
来源:https://www.cnblogs.com/clsn/p/8244206.html
頁:
[1]