Skip to main content

Backup

All user data and documents are stored in a mongo database. The other components only store log files and configuration. Mongo provides an easy way to backup the information using the mongodump command. This also includes any documents and images.

If you are just testing the installation or already have a procedure for mongo database backup you may skip this section.

Backup database

Creating a backup can be done by executing a docker exec command into the application that is deployed. A second command creates a tar archive, which is then copied to the host system. This file can then be transferred to a backup server using ssh. These commands can be added to a file 'backup.sh'.

#!/bin/bash
docker exec -it mongo mongodump --db idata --out /tmp
docker exec -it mongo tar -cvf /tmp/idata.tar /tmp/idata
docker cp mongo:/tmp/idata.tar /tmp/idata.tar'
scp -P 4422 /tmp/idata.tar [USER]@[IP]:[DIRECTORY]

Save the file in a local directory and make sure it has execute rights. Then add the following command to the cron scheduler. In this case a backup is created every hour at 33 minutes past the hour.

chmod 777 backup.sh
crontab -e
33 * * * * /home/devops/bin/backup.sh > /home/devops/bin/backup.log

Restore database

To restore the database you copy the tar file to the deployed mongo instance and unpack and restore from the host system.

docker cp /tmp/idata.tar mongo:/tmp
docker exec -it mongo tar -xvf /tmp/idata.tar /tmp/idata
docker exec -it mongo mongorestore --db idata /tmp/idata