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: 2 months ago
JSON representation
Docker container to perform a mongodump and rsync to a backup server
- Host: GitHub
- URL: https://github.com/qnipp/mongodump-rsync
- Owner: qnipp
- License: mit
- Created: 2020-03-07T15:52:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-07T20:54:05.000Z (over 5 years ago)
- Last Synced: 2025-02-16T20:44:31.577Z (5 months ago)
- Language: Dockerfile
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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/backupAt 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