简体   繁体   English

如何在 Kube.netes 集群中创建自动 arangodb 集群备份?

[英]How to create automatic arangodb cluster backups in a Kubernetes Cluster?

I'm trying to get automatic backups to work for my arangodb cluster deployment.我正在尝试让自动备份为我的 arangodb 集群部署工作。 I'm trying to follow the documentation but I think I have messed it up somehow.我正在尝试按照文档进行操作,但我认为我以某种方式搞砸了。

Here is my database-config.yaml:这是我的数据库配置。yaml:

apiVersion: "database.arangodb.com/v1alpha"
kind: "ArangoDeployment"
metadata:
  name: "arangodb-cluster"
spec:
  mode: Cluster 
  agents: 
    count: 3
    args:
      - --log.level=debug
  dbservers: 
    count: 3
  coordinators:
    count: 3

---
apiVersion: "backup.arangodb.com/v1alpha"
kind: "ArangoBackup"
metadata:
  name: "arangodb-backup"
  namespace: default
spec:
  policyName: "arangodb-backup-policy"
  deployment:
    name: "arangodb-backup-deployment"
  upload:
    repositoryURL: "https://s3.filebase.com/buffer"
    credentialsSecretName: "backup-secret"
---
apiVersion: "backup.arangodb.com/v1alpha"
kind: "ArangoBackupPolicy"
metadata:
  name: "arangodb-backup-policy"
spec:
  schedule: "*/2 * * * *"
template:
  upload:
      repositoryURL: "https://s3.filebase.com/myBucket"
      credentialsSecretName: "backup-secret"
---
apiVersion: v1
kind: Secret
metadata:
  name: backup-secret
data:
   token: mybase64EnodedJSONToken
type: Opaque

Ideally I would find some data in my bucket, but it's empty.理想情况下,我会在我的存储桶中找到一些数据,但它是空的。 I think it might be either:我认为它可能是:

  1. The bucket size is to small (But that seems rather unrealistic, because that is a test deployment with only one document and 4 collections, so it shouldn't be that big) bucket size 太小了(但这似乎不太现实,因为那是一个只有一个文档和 4 个 collections 的测试部署,所以它不应该那么大)
  2. The service I'm using simply is not supported 2.1 The service I'm using is wrongly configured根本不支持我正在使用的服务 2.1 我正在使用的服务配置错误
  3. I missunderstood something in the documentation我误解了文档中的某些内容

My decoded json token looks like this (I generated it with rclones cli):我的解码 json 令牌看起来像这样(我用 rclones cli 生成它):

{
"Filebase": {
    "access_key_id": "myID",
    "acl": "private",
    "endpoint": "https://s3.filebase.com",
    "env_auth": "false",
    "provider": "Other",
    "secret_access_key": "myAccessKey",
    "type": "s3"
}

} My encoded one looks (somewhat) like this (Just placed it here in case I encoded the json token the wrong way):我的编码看起来(有点)像这样(只是把它放在这里以防我以错误的方式编码 json 令牌):

ewogICAgIkZpbGViYXNlIXXXXXXX...X== ewogICAgIkZpbGViYXNlIXXXXXXX...X==

And it's: 301 bytes long它是:301 字节长

What I tried: I tried to get some more insides on what is happening, but I lack the experience to do it propperly, also I tried to add some stuff from the documentation but to no avail.我尝试了什么:我试图深入了解正在发生的事情,但我缺乏正确执行它的经验,我也尝试从文档中添加一些内容但无济于事。

And as a final notice, the bucket is set to private on the filebase.com dashboard, I'm using the free tier there and the 2min on the cronjob timer are just for testing.最后请注意,存储桶在filebase.com仪表板上设置为私有,我在那里使用免费套餐,cronjob 计时器上的 2 分钟仅用于测试。

EDIT: It seems like that custom the backup pod is a pro feature of the db and one needs to build his own pod for this if one wants to have a backup.编辑:似乎自定义备份 pod 是数据库的一项专业功能,如果有人想要备份,则需要为此构建自己的 pod。

This is how I solved it (credits to the offical arangodb github for the first part of the script).这就是我解决它的方法(脚本第一部分归功于官方 arangodb github)。
What is the script doing?脚本在做什么?
We are creating a cronjob which will run every 14 days.我们正在创建一个每 14 天运行一次的 cronjob。 Then we spin up a pod which will use the arangodump tool to dump (in this case) the whole database.然后我们启动一个 pod,它将使用arangodump工具转储(在本例中)整个数据库。
By passing it data like the database url,password, user name and save it on a volume under temp/dump .通过将数据库 url、密码、用户名等数据传递给它,并将其保存在temp/dump下的卷上。
Afterwards we create another pod which uses the minio cli tool, which allows to interact with any of the major object storage providers.之后我们创建另一个使用minio cli 工具的 pod,它允许与任何主要的 object 存储提供商进行交互。
We first set an mc alias for gcloud with the access key and secret, you can replace this with any other s3 compatible provider url. Aftwerwards we will mirror the /temp/dump to the cloud bucket (in this case qute , replace this with your own bucket name.) in a folder with the most date of the backup.我们首先使用访问密钥和秘密为 gcloud 设置一个 mc 别名,您可以将其替换为任何其他 s3 兼容提供商 url。之后我们将镜像/temp/dump到云存储桶(在本例中为 qute ,将其替换为您的自己的存储桶名称。)在具有最新备份日期的文件夹中。 $() can be used to execute shell commands and use the return value, just for anybody not knowing that. $()可用于执行 shell 命令并使用返回值,仅供不知道的人使用。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name:  backup-job
spec:
  schedule: "0 0 */14 * *" #Runs the job at every 14 days
  jobTemplate:
    spec:
      template:
        metadata:
          name:  backup-job
        spec:
          initContainers:
            - name: dump-create
              image: "arangodb:3.7.3"
              args:
                - "arangodump"
                - "--server.endpoint=$(ENDPOINT)"
                - "--server.username=$(USERNAME)"
                - "--server.password=$(PASSWORD)"
                - "--server.database=MY-DATABASE"
                - "--output-directory=/tmp/dump"
                - "--overwrite"
              volumeMounts:
                - name: dump
                  mountPath: /tmp/dump
              env:
              - name: "PASSWORD"
                valueFrom:
                  secretKeyRef:
                    name: signing-secret
                    key: root-password
              
              - name: "USERNAME"
                valueFrom:
                  configMapKeyRef:
                    name: signing-config
                    key: "admin-user"
              
              - name: "ENDPOINT"
                valueFrom:
                  configMapKeyRef:
                    name: signing-config
                    key: db-url

          restartPolicy: OnFailure


          containers:
            - name: db-dump-upload
              image: "minio/mc"
              imagePullPolicy: IfNotPresent
              command: ["/bin/sh","-c"]
              args: ["mc alias set gcs https://storage.googleapis.com $ACCESSKEY $SECRETKEY; mc mirror /tmp/dump gcs/qute/$(date -I)"] #no () for env variables!!!!
              volumeMounts:
                - name: dump
                  mountPath: /tmp/dump

              env:
              - name: SECRETKEY
                valueFrom:
                  secretKeyRef:
                    name: backup-secret
                    key: secret
                   
              - name: ACCESSKEY
                valueFrom:
                  secretKeyRef:
                    name: backup-secret
                    key: access-key
          volumes:
            - name: dump
              emptyDir: {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM