mongodb-local-backup

module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2023 License: MIT

README

MongoDB Local Backup

Release Download

Go Reference Github Actions codecov Go Report Card

Mongo DB Linux MacOS X Windows

A tool can back up your MongoDB data in Local File system.

English, 中文

Usage

1. define config file
1.1 config file type

MLB support 3 types of config files, they're json, toml and yaml. And here're the example of the config files: json, toml, yaml

1.2 config file have several fields
key value required description
mongo C:\Program Files\MongoDB\Tools\100\bin\mongoexport.exe Y specific 'mongoexport' path
host 127.0.0.1 Y MongoDB service host
port 27017 Y MongoDB service port
username test N MongoDB service username for authentication, use with password, unset or set to null means no authentication
password test N MongoDBservice password for authentication, use with username, unset or set to null means no authentication
target 'must bean array' Y define which db and collection to export
db 'must be an object' Y define which db to export
collection 'must be an array' Y define which collections in this db to export
prefix mongodb-local-backup N define the prefix of the exported data file names
type json/csv Y define the export data file format
output E:\mongo_backup\ Y define the directory where store the export data files.
cron */1 * * * * N define when run the export task, it will work only with command include '-d' option.
1.3 config file example

config.json

{
  "mongo": "C:\\Program Files\\MongoDB\\Tools\\100\\bin\\mongoexport.exe",
  "host": "127.0.0.1",
  "port": 27017,
  "username": null,
  "password": null,
  "target": [
    {
      "db": "test",
      "collection": [
        "test",
        "test1"
      ]
    }
  ],
  "prefix": "mongodb-local-backup-json",
  "type": "json",
  "output": "E:\\mongo_backup\\",
  "cron": "*/1 * * * *"
}

config.toml

# Define the path of mongoexport executable
mongo = "C:\\Program Files\\MongoDB\\Tools\\100\\bin\\mongoexport.exe"
# MongoDB host
host = "127.0.0.1"
# MongoDB port
port = 27017
# username of MongoDB connection
# username =
# password of MongoDB connection
# password =
# prefix is the prefix of exported data file name.
prefix = "mongodb-local-backup-toml"
#
type = "json"
output = "E:\\mongo_backup\\"
cron = "*/1 * * * *"
# define the MongoDB db and collections in target, mlb can do the backup for multiple dbs and collections.
[[target]]
db = "test"
collection = ["test", "test1"]

config.yaml

mongo: C:\\Program Files\\MongoDB\\Tools\\100\\bin\\mongoexport.exe
host: 127.0.0.1
port: 27017
target:
  -
    db: test
    collection:
      - test
      - test1
prefix: "mongodb-local-backup-yaml"
type: json
output: "E:\\mongo_backup\\"
cron: '*/1 * * * *'
2. Run command
2.1 Run in Windows
# one time
./mlb.exe -c config.json -f json
./mlb.exe -c config.toml -f toml
./mlb.exe -c config.yml -f yaml
./mlb.exe -c config.yaml -f yaml

# cron job
./mlb.exe -c config.json -f json -d
./mlb.exe -c config.toml -f toml -d
./mlb.exe -c config.yml -f yaml -d
./mlb.exe -c config.yaml -f yaml -d
2.2 Run in Linux/Darwin
# one time
mlb -c config.json -f json
mlb -c config.toml -f toml
mlb -c config.yml -f yaml
mlb -c config.yaml -f yaml

# cron job
mlb -c config.json -f json -d
mlb -c config.toml -f toml -d
mlb -c config.yml -f yaml -d
mlb -c config.yaml -f yaml -d

Feature plans

1. Service

The service is about the Service in Windows, Linux and MacOS. With the Service, mlb can run in background and do the backup tasks automatically.

2. Notification

Aim to send message to IM software such as Telegram,Bark, WXWorks, DingTalk and so on.

Contribution

If you have some great ideas, plz submit issue and let me know :D

Welcome to PR~

Background

Why did I design this tool? A few months before, the data in MongoDB Standalone is broken by the hard disk failure, so I lost my data and can't not backup. So if you want to keep your data safe, it's better to use MongoDB ReplicaSet or backup more often.

Thanks

  1. github.com/BurntSushi/toml MIT Licence
  2. github.com/alexflint/go-arg BSD-2-Clause License
  3. github.com/asaskevich/govalidator MIT Licence
  4. github.com/commander-cli/cmd MIT Licence
  5. github.com/go-co-op/gocron MIT Licence
  6. github.com/go-ozzo/ozzo-validation/v4 MIT Licence
  7. github.com/gorhill/cronexpr GPL v3/APL v2
  8. github.com/sirupsen/logrus MIT Licence
  9. github.com/smartystreets/goconvey/convey Licence
  10. github.com/agiledragon/gomonkey MIT Licence

Directories

Path Synopsis
cmd
mlb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL