1 Answer

answered by

inchirags@gmail.com   Chirag's MongoDB DBA Tutorial         https://www.chirags.in

*****************************************************************************************

* MongoDB Schedule Backups on a Windows Server *

*****************************************************************************************

YouTube Video:

MongoDB Database server:

Server IP: 192.168.224.133

To schedule MongoDB backups on a Windows Server, you can use the Task Scheduler and a backup script. Here's a step-by-step guide:

Step 1: Create a Backup Script

Open a text editor like Notepad.

Write a backup script using the mongodump command. Below is an example script:

@echo off
:: Set the current date in YYYY-MM-DD format
for /f "tokens=2 delims==" %%i in ('wmic os get localdatetime /value') do set datetime=%%i
set datestamp=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%

:: Set backup directory
set backupDir=C:\MongoDB_Backups\%datestamp%

:: Create backup directory
if not exist "%backupDir%" mkdir "%backupDir%"

:: Perform MongoDB dump
mongodump --host localhost --port 27017 --out "%backupDir%"

:: Optional: Remove old backups older than 7 days
forfiles /p "C:\MongoDB_Backups" /m * /d -7 /c "cmd /c if @isdir==TRUE rmdir /s /q @path"
echo Backup completed successfully!

Save the script as mongo_backup.bat in a directory, e.g., C:\Scripts.

Step 2: Test the Script

Open Command Prompt.

Navigate to the script's location:

cd C:\Scripts

Run the script:

mongo_backup.bat

Check the output in C:\MongoDB_Backups. Ensure a folder with the current date is created and contains your MongoDB backup files.

Step 3: Schedule the Backup Using Task Scheduler

Open Task Scheduler on your Windows Server.

In the Actions panel, click Create Task.

Fill in the details:

Name: Enter a name like MongoDB Daily Backup.

Description: Describe the task, e.g., "Daily backup of MongoDB databases."

Set the Trigger:

Go to the Triggers tab and click New.

Choose a schedule (e.g., Daily, Weekly, or Monthly).

Set the time and recurrence pattern. Click OK.

Set the Action:

Go to the Actions tab and click New.

Action: Select Start a program.

Program/script: Browse to mongo_backup.bat.

Click OK.

Set Conditions (Optional):

Go to the Conditions tab to configure any specific conditions, such as only running when the server is idle.

Set Settings:

Go to the Settings tab.

Check "Allow task to be run on demand".

Optionally, enable "Stop the task if it runs longer than" to prevent long-running tasks.

Click OK to save the task.

Step 4: Test the Scheduled Task

In Task Scheduler, right-click the task you created and select Run.

Verify that the task runs successfully and creates a backup in the specified directory.

Step 5: Monitor Backups

Periodically check the C:\MongoDB_Backups directory to ensure backups are being created as scheduled.

Review Task Scheduler logs if backups fail.

Let me know if you need help configuring this!

For any doubts and query, please write on YouTube video comments section.

Note : Flow the Process shown in video.

Please, Subscribe and like for more videos:

https://youtube.com/@chiragstutorial

Don't forget to, Follow, Like,  Share &, Comment

Thanks & Regards,

Chitt Ranjan Mahto "Chirag"

_________________________________________________________________________________________

Note: All scripts used in this demo will be available in our website.

Link will be available in description.

#mongodb 

#mongodbtutorial 

#mongo

#mongosh

#mongodbtutorialforbeginners 

#chiragstutorial 

#chiragsdatabasetutorial 

#chirags 

#chiragsmahto

#mongodbautobackup

Install MongoDB 8,Authentication,MongoDB Tutorial,MongoDB Chirags Tutorial,MongoDB DBA Tutorial,Chirags Tutorial,Chirags DBA Tutorial,Chirag Mahto,Chitt Ranjan Mahto,Chirag DBA Tutorial,Database Tutorial,NoSQL Database Tutorial,MongoDB NoSQL Database,MongoDB Install,MongoDB Configuration,MongoDB Access,MongoDB Compass,Mongosh,Rockmongo,Mongo,MongoDB Authorization,MongoDB Authentication,MongoDB Authorisation,Mongodb Auto Backup in Windows, MongoDB Schedule Backup in Windows

Most popular tags

laravel postgresql laravel-10 replication ha postgresql mongodb laravel-11 mongodb database mongodb tutorial ubuntu 24.04 lts streaming-replication mysql database laravel postgresql backup laravel login register logout database mysql php laravel 11 - login with otp valid for 10 minutes. user and admin registration user and admin login multiauth technlogy asp.net asp.net c# mysql master slave replication centos linux laravel sql server schedule backup autobackup postgresql django python haproxy load balancer install self sign ssl laravel 11 gaurds zabbix 7 how to install graylog on ubuntu 24.04 lts | step-by-step asp.net core mvc .net mvc network upload c# ssl integration sql server on ubuntu 22.04 lts mssql server ms sql server sql server user access in postgres mysql password change cent os linux configure replica laravel 11 socialite login with google account google login kubernetes (k8s) install nginx load balancer install install and configure .net 8.0 in ubuntu 24.04 lts php in iis php with iis php tutorial chirags php tutorials chirags php tutorial chirags tutorial laravel 11 guards mongodb sharding metabase business analytics metabase postgresql 16 to postgresql 17 postgresql migration letsencrypt mongodb crud rocky linux laravel custom captcha laravel 11 captcha laravel captcha mongo dll php.ini debian 12 nginx apache nextcloud gitea in ubuntu git gitea npm error node js mysql ndb cluster mysql cluster ssl oracle login register logout in python debian windows shell batch file bat file time stamp date time shopping cart in laravel centos rhel swap memeory rhel 5.5
...