πŸ’½Database Backup and Recovery

From time to time, data is backed up to a secondary database to avoid total corruption or loss of data. For now, data can be backed up on a local database in a development environment. This is done with the use of two MongoDB database containers, docker-compose.yml, the mongodump and mongorestore commands, and also by installing the MongoDB server and its database tools in the Dockerfile.

Sub-processes were used to run these commands in bash scripts with the help of a cron job (for backup) and an endpoint (for restoration). MongoDB Compass can be used to view and manage the databases graphically.

# backend/Dockerfile

FROM node:17-alpine As development

# setting the image working directory which the backend folder of the root directory
WORKDIR /usr/src/app/backend

# copy package.json and package-lock.json to the image working directory
COPY package*.json ./

# install tools for mongodump and mongorestore commands
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' >> /etc/apk/repositories
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/community' >> /etc/apk/repositories
RUN apk update
RUN apk add mongodb
RUN apk add mongodb-tools


# install development dependencies
RUN npm install --only=development --force


# copy the application code to the working directory of image
COPY . .

# EXPOSE 3000

#  build the application
RUN npm run build

Last updated