Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/qnipp/mongodump-rsync

Docker container to perform a mongodump and rsync to a backup server
https://github.com/qnipp/mongodump-rsync

Last synced: 9 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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:

```yaml
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_.

```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:

```yaml
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