{"id":20266635,"url":"https://github.com/pferreirafabricio/backup-mongo-db","last_synced_at":"2025-04-11T03:22:09.813Z","repository":{"id":134793884,"uuid":"317993013","full_name":"pferreirafabricio/backup-mongo-db","owner":"pferreirafabricio","description":"🗳️ A simple PowerShell script to make a backup of a MongoDB database and create a scheduled task for it on Windows","archived":false,"fork":false,"pushed_at":"2024-01-13T19:06:38.000Z","size":295,"stargazers_count":6,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T09:56:10.230Z","etag":null,"topics":["database","database-script","gzip","mongodb","mongodb-database","mongodump","powershell","powershell-script","system-schedule","windows","zip"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pferreirafabricio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-02T21:13:51.000Z","updated_at":"2024-12-30T22:25:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"eb9fa0db-27b4-4fe1-82f5-0d68d5503cd8","html_url":"https://github.com/pferreirafabricio/backup-mongo-db","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pferreirafabricio%2Fbackup-mongo-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pferreirafabricio%2Fbackup-mongo-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pferreirafabricio%2Fbackup-mongo-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pferreirafabricio%2Fbackup-mongo-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pferreirafabricio","download_url":"https://codeload.github.com/pferreirafabricio/backup-mongo-db/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248334312,"owners_count":21086373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","database-script","gzip","mongodb","mongodb-database","mongodump","powershell","powershell-script","system-schedule","windows","zip"],"created_at":"2024-11-14T12:10:35.255Z","updated_at":"2025-04-11T03:22:09.794Z","avatar_url":"https://github.com/pferreirafabricio.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :ballot_box: Dump MongoDB Database\n\nIt's a simple script made with PowerShell to create a backup of a MongoDB database and save all collections in a `.zip` folder or `.gz` file.\n\n## :arrows_clockwise: Creating a simple backup flow\n\n__1.__ Verify the version of MongoDB, running:\n```powershell\nmongod --version\n```\n\n__2.__ If the version of your MongoDB is 4.4 or above, you will need to install de _mongodump, mongorestore_, and other tools separately. For this, follow this guide: [Installing the Database Tools on Windows](https://docs.mongodb.com/database-tools/installation/installation-windows/)\n\u003e [!NOTE]\n\u003e \"Starting with MongoDB 4.4, the MongoDB Database Tools are now released separately from the MongoDB Server...\"\n\n__3.__ After the installation or if your version already has the database tools (like in version 4.2), run the following commands to guarantee that the tools are accessible by the command line:\n```powershell\nmongodump --help\n```\n```powershell\nmongorestore --help\n```\n\u003e [!NOTE]\n\u003e If they are not accessible, follow this guide: [Make the DB Tools available in your PATH](https://docs.mongodb.com/database-tools/installation/installation-windows/#make-the-db-tools-available-in-your-path)\n\n__4.__ After all the process of installation/verification we will create the flow properly\n\n  __4.1__ Edit the [backupMongoDatabase.ps1](./backupMongoDatabase.ps1) script, modifying the variables:\n  ```powershell\n  $databaseName = \"databaseName\"\n  $mongoDbHost = \"localhost:27017\"\n  $backupPath = \"C:\\Path\\To\\Back\\Folder\"\n  ```\n  \u003e [!NOTE]\n  \u003e If the database requires authorization remember to use the command with __-u__ and __-p__ flags\n  \n  __4.2.__ Edit the [createSystemScheduledTask.ps1](./createSystemScheduledTask.ps1) script, modifying the  variable with the path of the [backupMongoDatabase](./backupMongoDatabase.ps1) script and the time that the task will run\n   ```powershell\n  $scriptToExecutePath = \"C:\\Path\\To\\backupMongoDatabase.ps1\"\n  $trigger = New-ScheduledTaskTrigger -Daily -At 1am\n  ```\n  \u003e [!NOTE]\n  \u003e Change the 'databaseName' in the name and description too, for more control of which database that task will back up\n  \n  __4.3.__ Finally, open the PowerShell as admin (for precaution) and enter in the folder that the ___createSystemScheduledTask.ps1___ is\n  ```powershell\n  cd \"C:\\Path\\To\\WhereScriptIs\"\n  ```\n  \n  __4.4.__ And execute it\n  ```powershell\n  ./createSystemScheduledTask.ps1\n  ```\n  \n  __4.5.__ The following output will be shown\n  \u003cbr/\u003e\n  \u003cimg src=\"./docs/task-created.png\" /\u003e\n  \n__5.__ :white_check_mark: Success! We created a basic backup task. You can check the task in _Task Scheduler_ too:\n\u003cimg width=\"480px\" src=\"./docs/search-task-scheduler.png\" /\u003e\n\u003cbr/\u003e\u003cbr/\u003e\nThe task:\n\u003cimg src=\"./docs/task-in-task-scheduler.png\" /\u003e\n\n__6.__ Test if the task is running correctly executing it manually:\n```powershell\nStart-ScheduledTask -TaskName 'MongoDB Backup - \u003cdatabaseName\u003e'\n```\n\n### :recycle: Need to restore a database using the backup?\n\nTake a look at this discussion at _DBA Stack Exchange_: [How restore a specific database from backup using mongorestore command\n](https://dba.stackexchange.com/questions/113017/how-restore-a-specific-database-from-backup-using-mongorestore-command)\n  \n## :page_with_curl: References\n\n- [New-ScheduledTaskTrigger](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasktrigger?view=win10-ps)\n- [Powershell scripts for MSSQL or MongoDB backup to Azure \u0026 AWS](https://piotrgankiewicz.com/2016/05/03/powershell-scripts-for-mssql-or-mongodb-backup-to-azure-aws/)\n- [Installing the Database Tools](https://docs.mongodb.com/database-tools/installation/installation/)\n- [How to find the exact version of installed MongoDB](https://stackoverflow.com/questions/38160412/how-to-find-the-exact-version-of-installed-mongodb#:~:text=To%20check%20mongodb%20version%20use%20the%20mongod%20command%20with%20%2D%2Dversion%20option.)\n- [Add 'powershell' code fences where appropriate](https://github.com/MicrosoftDocs/PowerShell-Docs/issues/1511)\n- [How restore a specific database from backup using mongorestore command](https://dba.stackexchange.com/questions/113017/how-restore-a-specific-database-from-backup-using-mongorestore-command)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpferreirafabricio%2Fbackup-mongo-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpferreirafabricio%2Fbackup-mongo-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpferreirafabricio%2Fbackup-mongo-db/lists"}