From 9d2194f64cb4e52bfeba269bf0ab32bffe1e41d1 Mon Sep 17 00:00:00 2001 From: RyanKaleliGabriel Date: Sat, 7 Dec 2024 13:39:10 +0300 Subject: [PATCH] ReadMe --- .gitignore | 3 + README.MD | 135 ++++++++++++++++++ ...res-sample_2024-12-06T10-55-00-374Z.sql.gz | Bin 20 -> 0 bytes 3 files changed, 138 insertions(+) delete mode 100644 backups/postgres-sample_2024-12-06T10-55-00-374Z.sql.gz diff --git a/.gitignore b/.gitignore index 6a7d6d8..b103868 100644 --- a/.gitignore +++ b/.gitignore @@ -91,6 +91,9 @@ out .nuxt dist +backups +backup + # Gatsby files .cache/ # Comment in the public line in if your project uses Gatsby and not Next.js diff --git a/README.MD b/README.MD index e69de29..6bfb7af 100644 --- a/README.MD +++ b/README.MD @@ -0,0 +1,135 @@ +Database Backup Utility + +> A command-line interface (CLI) utility for backing up any type of database. The utility will support various database management systems (DBMS) such as MySQL, PostgreSQL, MongoDB. + +## Table of Contents + +- [Take Aways](#take-aways) +- [Features](#features) +- [Stack](#stack) +- [Usage](#usage) +- [Project URL](#project-url) + +## Take Aways + +- Deeper understanding of database management systems, backup strategies, command-line interface development, and error handling. + +- Local and cloud storage integration and logging mechanisms. + +## Features + +1. Backup Operations: Support full backup type . +2. Compression: Compress backup files to reduce storage space. +3. Local Storage: Allow users to store backup files locally on the system. +4. Logging: Logs of backup and restore activities, including start time, end time, status, time taken, and any errors encountered. +5. Notifications: Slack notification on completion of backup operations and recoveries. +6. Restore Backup: A restore operation to recover the database from a backup file. + +## Stack + +- Node Js +- Docker +- Slack +- Postgres +- MongoDb +- MySql + +## Usage + +1. Clone the repository + + ```bash + https://github.com/RyanKaleliGabriel/RestoreMe.git + cd RestoreMe + ``` + +2. Set Environment Variables + +```bash + POSTGRES_PASSWORD= + POSTGRES_USER= + POSTGRES_DB= + + MYSQL_PASSWORD= + MYSQL_USER= + MYSQL_DATABASE= + + MONGO_USERNAME= + MONGO_PASSWORD= + MONGO_DATABASE= + + + + SLACK_OAUTH_TOKEN= + CHANNEL_ID= +``` + +3. Running the CLI: This command will. + +```bash +# Run the docker containers. These containers have the official images of the databases and file mounts. +docker compose up --build +``` + + +4. Start the options service and give you a list of databases to select. + +```bash +npm run dev + +? Select a database to backup (Use arrow keys) +❯ postgres + mysql + mongodb + A powerful, open-source relational database management system known for its advanced features, extensibility, and strong support for ACID compliance and complex queries. +``` + +5. Once you select a database a list of commands to backup and restore the selected database will be displayed + +```bash +✔ Select a database to backup postgres + + Command to backup a postgres database is: 'node dist/backup.js backup --db-type postgres --host localhost --port 5432 --user --password --database ' + Command to restore a postgres database is: 'node dist/restore.js restore --db-type postgres --host localhost --port 5432 --user --password --database ' +``` + +6. Copy the command you wish to run + +```bash +# Backup Logs +node dist/backup.js backup --db-type postgres --host localhost --port 5432 --user --password --database +Connected to postgreSQL! +/home/ryankaleligabriel/Documents/backend/RestoreMe/backups/postgres-sample_2024-12-06T10-55-00-374Z.sql.gz +[INFO] Starting postgres database backup process +[INFO] Backup start time: 1:20:51 PM +Backup completed successfully +[INFO] Backup end time: 1:20:52 PM +[INFO] Time take: -538 ms +Message sent to slack: 1733566853.027299 + +# Backup restore logs: +node dist/restore.js restore --db-type postgres --host localhost --port 5432 --user --password --database +Connected to postgres db: sample +[INFO] Starting postgres database restore process +[INFO] Restore start time: 1:22:29 PM +Restore completed successfully SET +[INFO] Restore end time: 1:22:29 PM +[INFO] Time take: 283 ms +Message sent to slack: 1733566950.387149 +``` + +7. You can access the data in the databases to backup the data, delete the data and finally restore to see how the backup and restore works. + +```bash +# Accessing MongoDb +docker exec -it mongo_db mongosh -u -p --authenticationDatabase admin + +# Accessing Mysql +docker exec -it mysql_db mysql -u root -p + +# Accessing PostgresDb +docker exec -it postgres_db psql -U +``` + +## Project URL +https://roadmap.sh/projects/database-backup-utility diff --git a/backups/postgres-sample_2024-12-06T10-55-00-374Z.sql.gz b/backups/postgres-sample_2024-12-06T10-55-00-374Z.sql.gz deleted file mode 100644 index 229151a5a27ab0cc4661f529cc0eda27e3c03e10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20 Rcmb2|=3oE=W@ZQtBmoVe0J#7F