蒙古人
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
警報範例