Heim Datenbank MySQL-Tutorial MongoDB之整库备份还原单表collection备份还原

MongoDB之整库备份还原单表collection备份还原

Jun 07, 2016 pm 04:06 PM
collection mongodb 备份 还原

MongoDB之整库备份还原单表collection备份还原 cd D:\MongoDB\bin 1整库备份: mongodump -h dbhost -d dbname -o dbdirectory -h:MongDB所在服务器地址,例如:127.0.0.1:27017 -d:需要备份的数据库实例,例如:wlwdb -o:备份的数据存放位置,例如:D:\M

MongoDB之整库备份还原单表collection备份还原

cd D:\MongoDB\bin

1整库备份:

mongodump -h dbhost -d dbname -o dbdirectory

-h:MongDB所在服务器地址,例如:127.0.0.1:27017

-d:需要备份的数据库实例,例如:wlwdb

-o:备份的数据存放位置,例如:D:\MongoDB\data\dump,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个wlwdb目录,这个目录里面存放该数据库实例的备份数据。

eg:

mongodump -h 127.0.0.1 -d wlwdb -o D:\MongoDB\data\dump

\

 

可以查看该备份目录:

\

 

mongodump --help

\
mongodump的官方说明:
options:
 --help          produce help message
 -v [ --verbose ]     be more verbose (include multiple times for more
              verbosity e.g. -vvvvv)
 --version        print the program's version and exit
 -h [ --host ] arg    mongo host to connect to ( /s1,s2 for
              sets)
 --port arg        server port. Can also use --host hostname:port
 --ipv6          enable IPv6 support (disabled by default)
 -u [ --username ] arg  username
 -p [ --password ] arg  password
 --dbpath arg       directly access mongod database files in the given
              path, instead of connecting to a mongod server -
              needs to lock the data directory, so cannot be used
              if a mongod is currently accessing the same path
 --directoryperdb     if dbpath specified, each db is in a separate
              directory
 --journal        enable journaling
 -d [ --db ] arg     database to use
 -c [ --collection ] arg collection to use (some commands)
 -o [ --out ] arg (=dump) output directory or "-" for stdout
 -q [ --query ] arg    json query
 --oplog         Use oplog for point-in-time snapshotting
 --repair         try to recover a crashed database
 --forceTableScan     force a table scan (do not use $snapshot)
Nach dem Login kopieren

2整库恢复:

mongorestore -h dbhost -d dbname –directoryperdb dbdirectory

-h:MongoDB所在服务器地址

-d:需要恢复的数据库实例,例如:wlwdb(可以和备份时候的不一样)

–directoryperdb:备份数据所在位置,例如:D:\MongoDB\data\dump\wlwdb

–drop:恢复的时候,先删除当前数据,然后恢复备份的数据。

eg:

mongorestore -h 127.0.0.1 -d wlwdb –directoryperdb D:\MongoDB\data\dump\wlwdb

mongorestore的官方说明(可通过mongorestore --help查看):
options:
 --help         produce help message
 -v [ --verbose ]    be more verbose (include multiple times for more
             verbosity e.g. -vvvvv)
 --version        print the program's version and exit
 -h [ --host ] arg    mongo host to connect to ( /s1,s2 for sets)
 --port arg       server port. Can also use --host hostname:port
 --ipv6         enable IPv6 support (disabled by default)
 -u [ --username ] arg  username
 -p [ --password ] arg  password
 --dbpath arg      directly access mongod database files in the given
             path, instead of connecting to a mongod server -
             needs to lock the data directory, so cannot be used
             if a mongod is currently accessing the same path
 --directoryperdb    if dbpath specified, each db is in a separate
             directory
 --journal        enable journaling
 -d [ --db ] arg     database to use
 -c [ --collection ] arg collection to use (some commands)
 --objcheck       validate object before inserting
 --filter arg      filter to apply before inserting
 --drop         drop each collection before import
 --oplogReplay      replay oplog for point-in-time restore
 --oplogLimit arg    exclude oplog entries newer than provided timestamp
             (epoch[:ordinal])
 --keepIndexVersion   don't upgrade indexes to newest version
 --noOptionsRestore   don't restore collection options
 --noIndexRestore    don't restore indexes
 --w arg (=1)      minimum number of replicas per write
Nach dem Login kopieren
3单个collection备份:

mongoexport -h dbhost -d dbname -c collectionname -f collectionKey -o dbdirectory

-h: MongoDB所在服务器地址

-d: 需要恢复的数据库实例

-c: 需要恢复的集合

-f: 需要导出的字段(省略为所有字段)

-o: 表示导出的文件名

mongoexport的官方说明(可通过mongoexport --help查看):
 --help          produce help message
 -v [ --verbose ]     be more verbose (include multiple times for more
              verbosity e.g. -vvvvv)
 --version         print the program's version and exit
 -h [ --host ] arg     mongo host to connect to ( /s1,s2 for
              sets)
 --port arg        server port. Can also use --host hostname:port
 --ipv6          enable IPv6 support (disabled by default)
 -u [ --username ] arg   username
 -p [ --password ] arg   password
 --dbpath arg       directly access mongod database files in the given
              path, instead of connecting to a mongod server -
              needs to lock the data directory, so cannot be used
              if a mongod is currently accessing the same path
 --directoryperdb     if dbpath specified, each db is in a separate
              directory
 --journal         enable journaling
 -d [ --db ] arg      database to use
 -c [ --collection ] arg  collection to use (some commands)
 -f [ --fields ] arg    comma separated list of field names e.g. -f
              name,age
 --fieldFile arg      file with fields names - 1 per line
 -q [ --query ] arg    query filter, as a JSON string
 --csv           export to csv instead of json
 -o [ --out ] arg     output file; if not specified, stdout is used
 --jsonArray        output to a json array rather than one object per
              line
 -k [ --slaveOk ] arg (=1) use secondaries for export if available, default
              true
 --forceTableScan     force a table scan (do not use $snapshot)
Nach dem Login kopieren
4单个collection恢复:

mongoimport -d dbhost -c collectionname –type csv –headerline –file

-type: 指明要导入的文件格式

-headerline: 批明不导入第一行,因为第一行是列名

-file: 指明要导入的文件路径

mongoimport的官方说明(可通过mongoimport --help查看):
 --help         produce help message
 -v [ --verbose ]    be more verbose (include multiple times for more
             verbosity e.g. -vvvvv)
 --version        print the program's version and exit
 -h [ --host ] arg    mongo host to connect to ( /s1,s2 for sets)
 --port arg       server port. Can also use --host hostname:port
 --ipv6         enable IPv6 support (disabled by default)
 -u [ --username ] arg  username
 -p [ --password ] arg  password
 --dbpath arg      directly access mongod database files in the given
             path, instead of connecting to a mongod server -
             needs to lock the data directory, so cannot be used
             if a mongod is currently accessing the same path
 --directoryperdb    if dbpath specified, each db is in a separate
             directory
 --journal        enable journaling
 -d [ --db ] arg     database to use
 -c [ --collection ] arg collection to use (some commands)
 -f [ --fields ] arg   comma separated list of field names e.g. -f name,age
 --fieldFile arg     file with fields names - 1 per line
 --ignoreBlanks     if given, empty fields in csv and tsv will be ignored
 --type arg       type of file to import. default: json (json,csv,tsv)
 --file arg       file to import from; if not specified stdin is used
 --drop         drop collection first
 --headerline      CSV,TSV only - use first line as headers
 --upsert        insert or update objects that already exist
 --upsertFields arg   comma-separated fields for the query part of the
             upsert. You should make sure this is indexed
 --stopOnError      stop importing at first error rather than continuing
 --jsonArray       load a json array, not one item per line. Currently
             limited to 16MB.
Nach dem Login kopieren
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Wie verwende ich MySQL-Backup und -Wiederherstellung in PHP? Wie verwende ich MySQL-Backup und -Wiederherstellung in PHP? Jun 03, 2024 pm 12:19 PM

Das Sichern und Wiederherstellen einer MySQL-Datenbank in PHP kann durch Befolgen dieser Schritte erreicht werden: Sichern Sie die Datenbank: Verwenden Sie den Befehl mysqldump, um die Datenbank in eine SQL-Datei zu sichern. Datenbank wiederherstellen: Verwenden Sie den Befehl mysql, um die Datenbank aus SQL-Dateien wiederherzustellen.

So verbinden Sie Navicat mit Mongodb So verbinden Sie Navicat mit Mongodb Apr 24, 2024 am 11:27 AM

Um mit Navicat eine Verbindung zu MongoDB herzustellen, müssen Sie: Navicat installieren. Eine MongoDB-Verbindung erstellen: a. Geben Sie den Verbindungsnamen, die Hostadresse und den Port ein. b. Geben Sie die Authentifizierungsinformationen ein (falls erforderlich). Überprüfen Sie die Verbindung Speichern Sie die Verbindung

Was nützt net4.0? Was nützt net4.0? May 10, 2024 am 01:09 AM

.NET 4.0 wird zum Erstellen einer Vielzahl von Anwendungen verwendet und bietet Anwendungsentwicklern umfangreiche Funktionen, darunter objektorientierte Programmierung, Flexibilität, leistungsstarke Architektur, Cloud-Computing-Integration, Leistungsoptimierung, umfangreiche Bibliotheken, Sicherheit, Skalierbarkeit, Datenzugriff und Mobilgeräte Entwicklungsunterstützung.

Integration von Java-Funktionen und Datenbanken in serverlose Architektur Integration von Java-Funktionen und Datenbanken in serverlose Architektur Apr 28, 2024 am 08:57 AM

In einer serverlosen Architektur können Java-Funktionen in die Datenbank integriert werden, um auf Daten in der Datenbank zuzugreifen und diese zu bearbeiten. Zu den wichtigsten Schritten gehören: Erstellen von Java-Funktionen, Konfigurieren von Umgebungsvariablen, Bereitstellen von Funktionen und Testen von Funktionen. Durch Befolgen dieser Schritte können Entwickler komplexe Anwendungen erstellen, die nahtlos auf in Datenbanken gespeicherte Daten zugreifen.

So konfigurieren Sie die automatische Expansion von MongoDB auf Debian So konfigurieren Sie die automatische Expansion von MongoDB auf Debian Apr 02, 2025 am 07:36 AM

In diesem Artikel wird vorgestellt, wie MongoDB im Debian -System konfiguriert wird, um eine automatische Expansion zu erzielen. Die Hauptschritte umfassen das Einrichten der MongoDB -Replikat -Set und die Überwachung des Speicherplatzes. 1. MongoDB Installation Erstens stellen Sie sicher, dass MongoDB im Debian -System installiert ist. Installieren Sie den folgenden Befehl: sudoaptupdatesudoaptinstall-emongoDB-org 2. Konfigurieren von MongoDB Replika-Set MongoDB Replikate sorgt für eine hohe Verfügbarkeit und Datenreduktion, was die Grundlage für die Erreichung der automatischen Kapazitätserweiterung darstellt. Start MongoDB Service: SudosystemctlstartMongodsudosysys

Wie Sie eine hohe Verfügbarkeit von MongoDB bei Debian gewährleisten Wie Sie eine hohe Verfügbarkeit von MongoDB bei Debian gewährleisten Apr 02, 2025 am 07:21 AM

In diesem Artikel wird beschrieben, wie man eine hoch verfügbare MongoDB -Datenbank für ein Debian -System erstellt. Wir werden mehrere Möglichkeiten untersuchen, um sicherzustellen, dass die Datensicherheit und -Dienste weiter funktionieren. Schlüsselstrategie: ReplicaSet: Replicaset: Verwenden Sie Replikaten, um Datenreduktion und automatisches Failover zu erreichen. Wenn ein Master -Knoten fehlschlägt, wählt der Replikate -Set automatisch einen neuen Masterknoten, um die kontinuierliche Verfügbarkeit des Dienstes zu gewährleisten. Datensicherung und Wiederherstellung: Verwenden Sie den Befehl mongodump regelmäßig, um die Datenbank zu sichern und effektive Wiederherstellungsstrategien zu formulieren, um das Risiko eines Datenverlusts zu behandeln. Überwachung und Alarme: Überwachungsinstrumente (wie Prometheus, Grafana) bereitstellen, um den laufenden Status von MongoDB in Echtzeit zu überwachen, und

Navicat -Methode zum Anzeigen von MongoDB -Datenbankkennwort Navicat -Methode zum Anzeigen von MongoDB -Datenbankkennwort Apr 08, 2025 pm 09:39 PM

Es ist unmöglich, das MongoDB -Passwort direkt über Navicat anzuzeigen, da es als Hash -Werte gespeichert ist. So rufen Sie verlorene Passwörter ab: 1. Passwörter zurücksetzen; 2. Überprüfen Sie die Konfigurationsdateien (können Hash -Werte enthalten). 3. Überprüfen Sie Codes (May Hardcode -Passwörter).

Großes Update von Pi Coin: Die PI Bank kommt! Großes Update von Pi Coin: Die PI Bank kommt! Mar 03, 2025 pm 06:18 PM

Pinetwork startet Pibank, eine revolutionäre Mobile -Banking -Plattform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). Was ist der Charme von Pibank? Lass uns herausfinden! Die Hauptfunktionen von Pibank: One-Stop-Management von Bankkonten und Kryptowährungsvermögen. Unterstützen Sie Echtzeittransaktionen und übernehmen Sie Biospezies

See all articles