I have 2 computers in different places (so it\'s impossible to use the same wifi network). One contains about 50GBs of data (MongoDB files) that I want to move to the second on
I did this myself recently, and I wanted to provide some extra considerations to be aware of, in case readers (like me) run into issues.
The following information is specific to *nix systems, but it may be applicable with very heavy modification to Windows.
Look into and make use of mongodump
and mongorestore
. That is probably safer, and it's the official way to migrate your database.
Yes, the data directory can be directly copied; however, you also need to make sure that the mongodb
user has complete access to the directory after you copy it.
My steps are as follows. On the machine you want to transfer an old database to:
/etc/mongod.conf
and change the dbPath field to the desired location.shellcheck
.mongodb
access to it through chown
.#!/bin/bash
TARGET_DATA_DIRECTORY=/path/to/target/data/directory # modify this
SOURCE_DATA_DIRECTORY=/path/to/old/data/directory # modify this too
echo shutting down mongod...
sudo systemctl stop mongod
if test "$TARGET_DATA_DIRECTORY"; then
echo removing existing data directory...
sudo rm -rf "$TARGET_DATA_DIRECTORY"
fi
echo copying backed up data directory...
sudo cp -r "$SOURCE_DATA_DIRECTORY" "$TARGET_DATA_DIRECTORY"
sudo chown -R mongodb "$TARGET_DATA_DIRECTORY"
echo starting mongod back up...
sudo systemctl start mongod
sudo systemctl status mongod # for verification