使用mgob 进行mongodb 数据库备份

mgob 是就有golang 编写的mongodb 数据库备份工具,支持cron 调度,基于cli (mongodump,minio mc ...) 各种工具以及rest api 的模式进行
数据的备份管理,实际上我们基于webhook 的模式比如(adnanh/webhook)也是可以解决的,对于任务调度的我们可以基于crontab 方式处理
以下是一个简单的配置学习

环境准备

  • docker-compose 文件 
version: "3"
services: 
  mgob:
    image: dalongrong/mgob
    command: -LogLevel=info
    restart: always
    ports: 
    - "8090:8090"
    volumes: 
    - "./config:/config"
    - "./storage:/storage"
    - "./tmp:/tmp"
    - "./data:/data"
  • docker 镜像说明
    因为官方对于中文时区处理不是很好,所以做了调整,以下是dockerfile
FROM stefanprodan/mgob
RUN apk update && apk add --no-cache tzdata \ 
   && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
   && echo "Asia/Shanghai" > /etc/timezone

配置格式

  • 官方提供了demo以下是一个简单的demo 配置
scheduler:
  # run every day at 6:00 and 18:00 UTC
  cron: "0 6,18 */1 * *"
  # number of backups to keep locally
  retention: 14
  # backup operation timeout in minutes
  timeout: 60
target:
  # mongod IP or host name
  host: "172.18.7.21"
  # mongodb port
  port: 27017
  # mongodb database name, leave blank to backup all databases
  database: "test"
  # leave blank if auth is not enabled
  username: "admin"
  password: "secret"
  # add custom params to mongodump (eg. Auth or SSL support), leave blank if not needed
  params: "--ssl --authenticationDatabase admin"
# S3 upload (optional)
s3:
  url: "https://play.minio.io:9000"
  bucket: "backup"
  accessKey: "Q3AM3UQ867SPQQA43P2F"
  secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
  # For Minio and AWS use S3v4 for GCP use S3v2
  api: "S3v4"
# GCloud upload (optional)
gcloud:
  bucket: "backup"
  keyFilePath: /path/to/service-account.json
# Azure blob storage upload (optional)
azure:
  containerName: "backup"
  connectionString: "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...;EndpointSuffix=core.windows.net"
# SFTP upload (optional)
sftp:
  host: sftp.company.com
  port: 2022
  username: user
  password: secret
  # you can also specify path to a private key and a passphrase
  private_key: /etc/ssh/ssh_host_rsa_key
  passphrase: secretpassphrase
  # dir must exist on the SFTP server
  dir: backup
# Email notifications (optional)
smtp:
  server: smtp.company.com
  port: 465
  username: user
  password: secret
  from: mgob@company.com
  to:
    - devops@company.com
    - alerts@company.com
# Slack notifications (optional)
slack:
  url: https://hooks.slack.com/services/xxxx/xxx/xx
  channel: devops-alerts
  username: mgob
  # 'true' to notify only on failures
  warnOnly: false

说明

mgob 具有cron + rest api + cli 的模式进行数据备份的集成,也是一种很不错的玩法,同时基于yaml 的配置,可以方便的解决我们的实际
业务问题,开发模式值得借鉴

参考资料

https://github.com/stefanprodan/mgob

猜你喜欢

转载自www.cnblogs.com/rongfengliang/p/12584783.html