How to backup and restore your database(mysql, postgresql, mongodb)

Reading Time : ~ .

In the production environments, data loss when we accidentally delete the files, or when server crashes or system fails, or when we applied migrations to the data that didn't work so we don't get previous data with the schema.

So we need to do data dump each time or every day when we do changes in the production

In this blog post, you will see how to take a backup, restore your database for MySQL, PostgreSQL, MongoDB databases.

Mysql:

    Data Backup Command: 

    mysqldump -u user_name -puser_password database_name > mysql_dump_file
    Data Restore Command:

    mysql -u username -p database_name < mysql_dump_file            

    user_name: Mysql username

    password: Mysql Password

    database_name: database name

    mysql_dump_file: the file to which you want to dump the data

Postgresql:

   Data Backup Command: 

   psql -U user_name -h host_name db_name < pgsql_dump_file
   Data Restore Command:   

   psql -U user_name -h host_name db_name < pgsql_dump_file         

   user_name: MySQL username

   password: Mysql Password

   db_name: database name

   pgsql_dump_file: the file to which you want to dump the data

Mongo db:

   Data Backup Command: 

   mongodump --username user_name --password pass_word --db database_name --out path_to_your_dump_directory        
   mongoexport --username user_name --password pass_word --db database_name --collection collection_name --out collection_name.json  

   Data Restore Command:

   mongorestore --username user_name --password pass_word --db database_name path_to_your_dump_directory        
   mongorestore --collection collection_name --db database_name path_to_your_dump_collection         

      user_name: mongo username

      password: mongo Password

      collection_name: database collection name

      database_name: database name

    By Posted On
SENIOR DEVELOPER at MICROPYRAMID

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Fabric - Learning part1 Ashwin Kumar

Using Fabric, we can configure Linux production server with uwsgi, nginx, vsftpd, mysql, mongodb, postfix, php, python tools, and other relevant pieces of software single-handedly ...

Continue Reading...
Celery With Supervisor Siva Chittamuru

Celery is a task queue with focus on real-time processing, while also supports task scheduling. Task queues are used as mechanisms to distribute work across ...

Continue Reading...
How to Deploy Django Project into Docker Container. Jagadeesh V

Docker, has captured the hearts and minds of the Devops community, with its platform for delivering distributed applications in containers. In this Blog Post, Lets ...

Continue Reading...

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties