蒙古人
0.2.1
未维护,请使用 https://github.com/utilitywarehouse/streaming-mongo-burs/ 代替
该工具可以在数据库运行到 AWS S3 或从 AWS S3 运行时备份或恢复 MongoDB 集合。
go get -u github.com/utilitywarehouse/mongolizer
mongolizer --help
您可以部署一个 docker 容器,该容器将按计划运行备份(默认为每天上午 10:30)
备份的状态保存在位于/var/data/mongolizer/state.db
的 Boltdb 文件中
运行状况端点位于0.0.0.0:8080/__/health
处,如果在过去 13 小时内成功备份,则会报告运行状况良好。
检测端点位于0.0.0.0:8080/__/metrics
,公开了一个 prom 仪表,其中mongolizer_status
仪表的值为 1 或 0,具体取决于先前备份的结果。仪表标有database
和集合labels
。
如果过去 13 小时内未找到备份,将运行初始备份。
# docker run --rm mongolizer /mongolizer scheduled-backup --help
Usage: mongolizer scheduled-backup [OPTIONS] COLLECTIONS
backup a set of mongodb collections
Arguments:
COLLECTIONS="foo/content,foo/bar" Collections to process (comma separated /) ($MONGODB_COLLECTIONS)
Options:
--cron="30 10 * * *" Cron expression for when to run ($CRON)
--dbPath="/var/data/mongolizer/state.db" Path to store boltdb file ($DBPATH)
--run=true Run backups on startup? ($RUN)
使用持久卷滚动 mongo + 使用指标抓取的 mongolizer 的完整示例
# A headless service to create DNS records
apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
prometheus.io/scrape: 'true'
prometheus.io/path: /__/metrics
prometheus.io/port: '8080'
name: mongo
labels:
app: mongo
spec:
ports:
- port: 8080
targetPort: 8080
name: mongolizer
- port: 27017
targetPort: 27017
name: client
clusterIP: None
selector:
app: mongo
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mongo
spec:
replicas: 1
template:
metadata:
name: mongo
labels:
app: mongo
spec:
imagePullSecrets:
- name: dockerhub-key
containers:
- name: mongolizer
image: registry.uw.systems/system/mongolizer:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- name: data
mountPath: "/var/data/mongolizer/"
subPath: "mongolizer"
env:
- name: MONGODB_COLLECTIONS
value: "db/collection,db/collection2"
- name: MONGODB
value: "mongo:27017"
- name: AWS_ACCESS_KEY_ID
value: ""
- name: AWS_SECRET_ACCESS_KEY
value: ""
- name: S3_BUCKET
value: "backup-bucket"
- name: S3_DIR
value: "/"
- name: mongo
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: data
mountPath: /data/db
subPath: "mongodb"
volumes:
- name: data
persistentVolumeClaim:
claimName: mongo-ebs-pvc
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mongo-ebs-pvc
annotations:
volume.beta.kubernetes.io/storage-class: ebs-gp2
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
# docker run --rm mongolizer /mongolizer restore --help
Usage: mongolizer restore [OPTIONS]
restore a set of mongodb collections
Options:
--collections="foo/content,foo/bar" Collections to process (comma separated /) ($MONGODB_COLLECTIONS)
--date="2006-01-02T15-04-05" Date to restore backup from
要获取指标,您可以使用类似于以下的查询
1 - avg(mongolizer_status{kubernetes_namespace="default"}) by (app, database, collection) < bool 1
警报示例