Categorygithub.com/catfishlty/mongodb-local-backup

# 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

keyvaluerequireddescription
mongoC:\Program Files\MongoDB\Tools\100\bin\mongoexport.exeYspecific 'mongoexport' path
host127.0.0.1YMongoDB service host
port27017YMongoDB service port
usernametestNMongoDB service username for authentication, use with password, unset or set to null means no authentication
passwordtestNMongoDBservice password for authentication, use with username, unset or set to null means no authentication
target'must bean array'Ydefine which db and collection to export
db'must be an object'Ydefine which db to export
collection'must be an array'Ydefine which collections in this db to export
prefixmongodb-local-backupNdefine the prefix of the exported data file names
typejson/csvYdefine the export data file format
outputE:\mongo_backup\Ydefine the directory where store the export data files.
cron*/1 * * * *Ndefine 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

# Packages

No description provided by the author
No description provided by the author