Skip to content

qnipp/mongodump-rsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongodump-rsync

Docker container to perform a mongodump and rsync to a backup server

Usage

Use the following environment variables to configure the image to your needs:

Variable Behaviour Default
MONGO_URL Sets the MongoDB URL to dump from mongodb://localhost:27017
MONGO_DUMP_OPTIONS Sets additional command line options for mongodump (empty)
TARBZ2_PATH Path, where the tar.bz2 file is built /tmp
SSH_DIR Directory, where the SSH configuration files will be found /ssh
RSYNC_TARGET Target for the rsync operation backup:/var/lib/backup

At least, MONGO_URL and RSYNC_TARGET must be set to fit your case.

SSH Files

Use the volume on /ssh to provide your SSH files, especially

File Description
id_rsa The private key, which is used for the SSH connection. The public key must be installed on the target server.
known_hosts The target server should be listed in this file.
config The SSH config file.

You can use the respective files from a real user's .ssh directory.

Using it on a Kubernetes Cluster

Saving the SSH Files as Secret

Inside the directory, a kustomization.yaml file can be set up like this:

secretGenerator:
- name: rsync-backup-ssh
  files:
  - config
  - id_rsa
  - known_hosts

The secret can then be generated by executing kubectl apply -k . in the same directory. It will display the name of the generated secret, something like rsync-backup-ssh-7fctbgfgdb. You need this name for the CronJob.

Setting up the CronJob

Create a CronJob in the file cronjob.yaml.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: backup-mongo-production
spec:
  schedule: "0 4 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: rsync-backup
            image: qnipp/mongodump-rsync
            env:
              - name: MONGO_URL
                value: mongodb://mongo-production/?replicaSet=rs0
              - name: RSYNC_TARGET
                value: backup.company.com:mongo-production
            volumeMounts:
              - name: ssh
                mountPath: /ssh
                readOnly: true
          volumes:
          - name: ssh
            secret:
              secretName: rsync-backup-ssh-7fctbgfgdb
          restartPolicy: OnFailure

Afterwards, it is applied using kubectl apply -f cronjob.yaml.

For testing, a simple Job can be used and applied. It is set up like this:

apiVersion: batch/v1
kind: Job
metadata:
  name: backup-mongo-production
spec:
  template:
    spec:
      containers:
      - name: rsync-backup
        image: qnipp/mongodump-rsync
        env:
          - name: MONGO_URL
            value: mongodb://mongo-production/?replicaSet=rs0
          - name: RSYNC_TARGET
            value: backup.company.com:mongo-production
        volumeMounts:
          - name: ssh
            mountPath: /ssh
            readOnly: true
      volumes:
      - name: ssh
        secret:
          secretName: rsync-backup-ssh-7fctbgfgdb
      restartPolicy: OnFailure

License

MIT

About

Docker container to perform a mongodump and rsync to a backup server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published