Skip to content

Mustafa Ateş UZUN Blog

mustafauzun.co

  • About
  • Blog
  • Home
  • »
  • CMD
  • »
  • MongoDB Backup With CMD
  • »
    • May 17, 2023
    • by mustafauzun
  • CMD

MongoDB Backup With CMD

To download MongoDB Database Tools and place the .cmd file in the same directory;

Open your web browser and go to the official MongoDB website;

https://www.mongodb.com/try/download/database-tools

@echo off
echo "Preparing..."

set "backup_path=C:\Backups\"
set "backup_days=30"

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%"

mkdir %backup_path%"

set "backup_file=%backup_path%%datestamp%.gzip"
echo "Starting backup at %backup_file%"

"mongodump.exe" --gzip --archive=%backup_file%  --host=127.0.0.1 --port=27017 --username=admin --password="123" --authenticationDatabase=admin --db=myDB

if %errorlevel% neq 0 exit /b %errorlevel%

echo "Success..."
Share

View .MSI File Logs

Build & Publish .SLN File With CMD

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Javascript, Task Queue
  • Javascript, Thread Pool
  • Javascript, Lexical Environment
  • Javascript, Execution Context
  • Javascript, Event Delegation

Recent Comments

No comments to show.

Archives

  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • January 2022

Categories

  • C#
  • CMD
  • CSS
  • HTML
  • JavaScript
  • MongoDB
  • Node.js
  • Podcast
  • Powershell
  • Uncategorized
Theme: Puskar by Template Sell.