Total Pageviews

Wednesday, November 19, 2025

PowerShell MongoDB Backup Script

Automated backup solution for MongoDB on Windows

This PowerShell script automates MongoDB backups on Windows, handling backup creation, verification, retention management, and logging. It runs quietly in the background with comprehensive logging to text files and Windows Event Log.

⬇️ Download Script Files  

Purpose

Ensures reliable MongoDB database backups with these capabilities:

  • Support local or remote MongoDB servers
  • Automated retention and cleanup
  • Detailed activity logging for auditing
  • Optional backup verification
  • Windows Event Log integration

Key Features

Flexible Target Configuration

  • Backup local or remote MongoDB instances
  • Default port 27017 with custom port support
  • Username/password authentication support

Selective or Full Backups

Backup all databases, specific databases, or selected collections. Oplog support (--oplog) enables point-in-time consistent backups.

Backup Directory and Naming

Backups stored in configurable directory (default: D:\MongoBackups) with timestamped folders:

D:\MongoBackups\mongodump_2025-11-09_080530am

Logging and Event Recording

All activities logged to daily text files and Windows Application Event Log with timestamps and status.

2025-11-19 07:57:08 AM - INFO - Server: localhost:27017 | Backup Path: D:\MongoBackups\mongodump_20251119_075708am
2025-11-19 07:57:08 AM - INFO - Backup Scope: Entire database 'openeyedb'
2025-11-19 07:57:08 AM - INFO - Retention: Keep 10 latest backups
2025-11-19 07:57:08 AM - INFORMATION - Event Log: Starting MongoDB backup from server: localhost:27017 to D:\MongoBackups\mongodump_20251119_075708am
2025-11-19 07:57:08 AM - INFO - Applying retention policy...
2025-11-19 07:57:08 AM - INFO - Deleted old backup: mongodump_20251109_091920pm
2025-11-19 07:57:08 AM - SUCCESS - Retention cleanup completed. Deleted 1 old backups
2025-11-19 07:57:08 AM - SUCCESS - Created new backup folder: D:\MongoBackups\mongodump_20251119_075708am
2025-11-19 07:57:08 AM - INFO - Using authentication for user: backupuser
2025-11-19 07:57:08 AM - INFO - Starting MongoDB backup process...
2025-11-19 07:57:09 AM - INFORMATION - Event Log: MongoDB backup completed successfully. Backup size: 4.02 MB. Location: D:\MongoBackups\mongodump_20251119_075708am
2025-11-19 07:57:09 AM - SUCCESS - Backup completed successfully. Size: 4.02 MB
2025-11-19 07:57:09 AM - INFO - Verifying backup...
2025-11-19 07:57:09 AM - SUCCESS - Backup verification successful: Found 5 BSON/JSON files
2025-11-19 07:57:09 AM - INFORMATION - Event Log: Backup verification completed successfully
2025-11-19 07:57:09 AM - SUCCESS - === MongoDB Backup Completed Successfully ===
2025-11-19 01:42:44 PM - INFO - === MongoDB Backup Started ===
2025-11-19 01:42:44 PM - INFO - Server: localhost:27017 | Backup Path: D:\MongoBackups\mongodump_20251119_014244pm
 

Data Retention Policy

Automatic cleanup of old backups based on retention settings:

  • RetentionDays: Days of backups to keep (default: 30)
  • RetentionCount: Number of recent backups to keep (takes precedence)

Log File Management

  • Maximum 10 log files retained
  • Each log file limited to 25 MB
  • Automatic rotation and deletion of old logs

Optional Backup Verification

When enabled, script verifies backup folders contain valid BSON/JSON files and metadata, with results logged to both text files and Windows Event Log.

Error Handling

All errors recorded in both text logs and Windows Event Log. Common issues include authentication failures, incorrect parameters, and insufficient disk space.

Automation and Scheduling

Can be executed manually or via Windows Task Scheduler for automatic operation. Runs silently when scheduled while maintaining complete activity logging.

Example Execution Scenarios

#############################################
# === Usage Example ===
#############################################
# Backup everything on a localhost
Backup-MongoDB 

# Basic backup without oplog and retention:
Backup-MongoDB -RetentionDays 15

# Keep only 10 latest backups:
Backup-MongoDB -RetentionCount 10

# Remote server with all features:
Backup-MongoDB -Server "SHB55" -Username "admin" -Password "secret" -UseOplog -RetentionCount 7 -VerifyBackup

# Custom backup directory with retention:
Backup-MongoDB -BackupDir "E:\MongoDB\Backups" -RetentionDays 30

# With backup verification:
Backup-MongoDB -Server "localhost" -VerifyBackup

# Backup multiple collections
Backup-MongoDB -Database "mydb" -Collections "users","orders","products"

# Backup single collection
Backup-MongoDB -Database "mydb" -Collections "users"

# Backup single database
Backup-MongoDB -Database testDB -Username "backupuser" -Password "SecureBackupPass123!" 

# Backup single database
Backup-MongoDB -Database openeyedb -Username "backupuser" -Password "SecureBackupPass123!"  -VerifyBackup -RetentionCount 10 

Event Log Entries

Event ID Type Description
1000InformationBackup started
1001InformationBackup completed successfully
1002InformationBackup verification passed
1003WarningBackup verification failed
2001ErrorBackup process failed

Create a Backup User in MongoDB

# Connect mongodb and create backup user
mongosh -u admin -p shb12345 --authenticationDatabase admin
use admin

db.createUser({
  user: "backupuser",
  pwd: "SecureBackupPass123!",
  roles: [
    { role: "backup", db: "admin" },
    { role: "restore", db: "admin" },
    { role: "readAnyDatabase", db: "admin" }
  ]
}) 

Summary

The MongoDB Backup Script provides automated, consistent backups for local and remote MongoDB servers with built-in retention management, detailed logging, and optional verification for reliable data protection with minimal maintenance.

Sunday, November 16, 2025

OpenEye: Enterprise-Grade Monitoring at Near-Zero Cost

Complete visibility into your Windows and SQL Server environments

Achieve complete visibility into your Windows and SQL Server environments with a powerful, self-managed, and agentless monitoring solution. OpenEye is a rearchitected, purpose-built performance metrics collector that delivers fast data processing and ingestion without the overhead.

  • Effortless Deployment: Get started in minutes with no complex setup or agents to install.
  • Real-Time Insights: Gain immediate visibility with live performance dashboards.
  • Proactive Monitoring: Identify and address issues before they impact your systems.
  • Cost-Effective: Enjoy enterprise-grade capabilities without the enterprise price tag.
OpenEye Dashboard Example
OpenEye Performance Metrics

What is OpenEye?

OpenEye is a 64-bit, multi-threaded performance data collector for Windows and SQL Server. Using DCOM and command-line operation, it runs on a single central server (Windows Server or Desktop) to gather real-time performance data from hundreds of remote servers. It has no dependencies, making it simple to deploy anywhere.

Download OpenEye 2025

Get started with enterprise monitoring today

Download OpenEye

Version 2.1 | Windows 64-bit | ZIP Archive| November 2025

Prerequisites

OpenEye uses two open-source applications for data storage and visualization. Both are easy to install and require no specialized knowledge. Download, install, and configure these applications on a network-accessible server before running OpenEye.

1 Install QuestDB

A high-performance time-series database for data ingestion.

Download: https://questdb.com

2 Install Grafana

A leading platform for data visualization and dashboards.

Download: https://grafana.com

3 Install QuestDB Data Source Plug-in

Required for Grafana to connect to QuestDB.

Download: QuestDB Grafana Plug-in

Quick Start Guide

Let's set up monitoring for 25 SQL Servers and their underlying Windows hosts from a central location.

Step One: Configure QuestDB and Grafana

Install QuestDB

Follow the QuestDB installation guide to install it on a server in your network. You can run it as a service or from the command line.

Install Grafana

Similarly, install Grafana on a server in your network, running it as a service or from the command line.

Install the Plug-in

Install the QuestDB data-source plug-in in your Grafana instance.

Add Data Source

In Grafana, create a new data source named qdbopeneye using the QuestDB plug-in. No username or password is required.

Import Dashboard

Import the pre-configured dashboard provided in the OpenEye.zip file into Grafana.

Step Two: Configure and Run OpenEye

Download & Extract

Download the OpenEye.zip file and extract it to a folder, e.g., D:\OpenEye.

Generate Config Files

Run OpenEye.exe twice from the command prompt. This generates the required perf_config.txt and perf_server.txt files.

Configure QuestDB Connection

Open perf_config.txt and update the QuestDB server details:

# QuestDB host name or IP address
QUEST_DB_HOST=localhost
# InfluxDB Line Protocol (ILP/HTTP) port (9000 is the default)
QUEST_DB_PORT=9000

Leave all other parameters unchanged for now.

Add Servers to Monitor

Open perf_server.txt and add your servers using the format described in the next section.

Launch

Start D:\OpenEye\OpenEye.exe.

Important Notes

Permissions: OpenEye uses Integrated Security. The account running it must have WMI read-only permissions on target Windows servers and VIEW SERVER STATE permission on target SQL Servers.

Run as a Service: To run OpenEye as a Windows service, use a tool like NSSM (www.nssm.cc).

Data Ingestion: OpenEye uses the InfluxDB Line Protocol (ILP) over HTTP to write to QuestDB. All tables are created automatically via a schema-on-write mechanism.

Adding or Removing Servers

You can dynamically add or remove servers from monitoring.

  1. Edit the perf_server.txt file.
  2. To add a server, insert a new line.
  3. To remove a server, comment out the line (with a #) or delete it.
  4. OpenEye automatically detects these changes. The frequency is controlled by the DURATION_TO_REFRESH_SERVER_MIN parameter (default: 5 minutes).
  5. For immediate effect, stop and restart the OpenEye process.

Server Configuration Format

The perf_server.txt file uses the following format:

# Duration | ServerName[,Port] | WIN or SQL
#
# Duration = Collection interval in seconds (0 = use global default)
# ServerName = Windows hostname or IP
# SQLServer[,Port] = SQL Server in format Server\Instance, optional port
# WIN = Collect Windows performance data only
# SQL = Collect both Windows and SQL performance data

Examples

Configuration Description
5|SRV1967|WIN Monitor Windows server SRV1967 every 5 seconds.
5|SRV1967|SQL Monitor SQL Server SRV1967 (default instance) every 5 seconds.
10|SRV1967,2345|SQL Monitor SQL Server on SRV1967 port 2345 every 10 seconds.
0|SRV1967\SQL2025|SQL Monitor named instance SQL2025 using the global collection interval.
15|SRV1967\SQL2022|SQL Monitor named instance SQL2022 every 15 seconds.

Key Configuration Parameters

Parameter Description
DURATION_TO_REFRESH_SERVER_MIN How often (in minutes) OpenEye reloads the perf_server.txt file to add new servers or remove commented-out ones.
OPENEYE_RESET_INTERVAL_MIN & OPENEYE_RESET_AT Controls how often OpenEye performs a full reset.
  • OPENEYE_RESET_INTERVAL_MIN=720 (12 hours)
  • OPENEYE_RESET_AT=12:01AM (Resets daily at 12:01 AM). If blank, the interval parameter is used.
During a reset, OpenEye restarts all monitoring threads, re-reading all configuration files.

External TSQL and WQL Queries

OpenEye allows you to extend its functionality by using your own custom queries, and can even replace its built-in data collection.

Configuration (perf_config.txt)

# Enable/Disable built-in collectors
USE_BUILTIN_WMI_COLLECTOR=YES
USE_BUILTIN_SQL_COLLECTOR=YES
# Enable external custom queries
USE_EXTERNAL_WMI_QUERY=YES
USE_EXTERNAL_SQL_QUERY=YES

Query File Format

  1. Place WQL queries in the \wqlqueries folder and TSQL queries in the \sqlqueries folder.
  2. WQL File Name Format: wql_[CustomName]-[Duration].txt
  3. TSQL File Name Format: sql_[CustomName]-[Duration].txt
    • The prefix (wql_/sql_) is mandatory.
    • [CustomName] defines the resulting table name in QuestDB.
    • [Duration] is the execution interval in seconds. If omitted, the global default is used.

Sample Queries (included in the package)

WQL Queries

  • wql_transactions-15.txt → Creates table wql_transactions, runs every 15 seconds.
  • wql_volume-10.txt → Creates table wql_volume, runs every 10 seconds.

TSQL Queries

  • sql_host_memory-30.txt → Creates table sql_host_memory, runs every 30 seconds.
  • sql_single_useplan-60.txt → Creates table sql_single_useplan, runs every 60 seconds.
  • sql_waittype-15.txt → Creates table sql_waittype, runs every 15 seconds.

Note: For SQL Server-related WMI classes, use the placeholder [WQLSQLName] in your query. OpenEye will automatically substitute the correct WMI class name based on the server and instance defined in perf_server.txt.

Monitoring Hundreds of Servers

Scaling OpenEye for Large Environments

While OpenEye can collect performance metrics from hundreds of servers without restrictions, each OpenEye process is optimized to monitor 32-48 remote servers due to its DCOM and RPC-based architecture. For optimal performance, we recommend limiting each instance to a maximum of 48 servers.

To monitor 200 servers from a central location:

  1. Divide your 200 servers into 5 groups of 40 servers each
  2. Create a main directory: D:\OpenEye
  3. Create 5 sub-folders: D:\OpenEye\sub-01, D:\OpenEye\sub-02, etc.
  4. Copy the perf_config.txt file into each sub-folder
  5. Create individual perf_server.txt files in each sub-folder with the corresponding server groups
  6. Copy the \wqlqueries and \sqlqueries folders along with OpenEye.exe to each sub-folder
  7. Use NSSM to create a unique Windows service for each sub-folder instance
  8. Optionally, use OPENEYE_SERVICE_NAME='Service Name' in your config to identify each service, or leave blank to use the sub-folder name
OpenEye Scaling Architecture
Sample OpenEye Management panel

Note: This distributed approach ensures optimal performance and resource utilization when monitoring large server environments.