Backup and restore

Backup

The contacts are saved in Mongo database. The data files of the database are stored in /data/mongo directory on the host computer. This means that data are not lost if you remove mongo container. However, you should not back up these files by simply copying them while mongo is running unless your system provides instantaneous snapshots. To make regular backups of the database, we recommend you run the following command regularly. It will create a timestamped directory with database content inside of /data/mongo/dump which you can then backup normally.

docker exec contacts_mongo_1 mongodump -o /data/db/dump/$(date -I)

contacts_mongo_1 is the name of contacts container that was created when running docker-compose.

Restore

Place your directory with backup (we will use name mybackup in this example) to into /data/mongo/dump. There should be a directory /data/mongo/dump/mybackup/contact_server/ containing several .bson files (and possibly others).

Stop container contacts_contact_server_1.

docker stop contacts_contact_server_1

And run the following commands:

docker exec -i contacts_mongo_1 mongorestore --drop /data/db/dump/mybackup

Note

If restore fails with error ``

echo "db.getSiblingDB('admin').runCommand( { setParameter: 1, failIndexKeyTooLong: false } )" | docker exec -i contacts_mongo_1 mongo