Skip to content

Instantly share code, notes, and snippets.

@stefanandres
Last active January 13, 2019 15:40
Show Gist options
  • Save stefanandres/56c7cd6590175f1bd3a29fb9f4a1d8bc to your computer and use it in GitHub Desktop.
Save stefanandres/56c7cd6590175f1bd3a29fb9f4a1d8bc to your computer and use it in GitHub Desktop.
apiVersion: v1
data:
start-backup: |
set -e
cd /backup &&
rm -rf dump
mongodump --host "$MONGO_HOST" &&
tar czpf dump-$(date +%F-%H-%M).tar.gz dump &&
rm -rf dump
kind: ConfigMap
metadata:
name: mongodb-backup-configmap
namespace: rocketchat
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: rocketchat
name: mongodb-backup
labels:
app: chat-sandres
spec:
schedule: "0 0,12 * * *"
#schedule: "35 * * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
metadata:
labels:
app: chat-sandres
annotations:
backup.ark.heptio.com/backup-volumes: mongodb-backup
spec:
restartPolicy: OnFailure
containers:
- name: mongodb-backup
image: mongo:4.0
volumeMounts:
- name: mongodb-backup
mountPath: "/backup"
- name: script
mountPath: /usr/local/bin/mongodb-backup/
env:
- name: MONGO_HOST
value: "chat-sandres-mongodb"
command:
- bash
args:
- /usr/local/bin/mongodb-backup/start-backup
volumes:
- name: mongodb-backup
persistentVolumeClaim:
claimName: mongodb-backup
- name: script
configMap:
name: mongodb-backup-configmap
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
namespace: rocketchat
name: mongodb-backup
labels:
app: chat-sandres
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
$ kubectl -n rocketchat logs mongodb-backup-1547393700-whqps -f
2019-01-13T15:35:17.103+0000 writing admin.system.version to
2019-01-13T15:35:17.105+0000 done dumping admin.system.version (1 document)
2019-01-13T15:35:17.105+0000 writing rocketchat.rocketchat_message to
2019-01-13T15:35:17.105+0000 writing rocketchat._raix_push_notifications to
2019-01-13T15:35:17.105+0000 writing rocketchat.rocketchat_statistics to
2019-01-13T15:35:17.106+0000 writing rocketchat.rocketchat_uploads.chunks to
2019-01-13T15:35:17.164+0000 done dumping rocketchat._raix_push_notifications (2548 documents)
2019-01-13T15:35:17.167+0000 writing rocketchat.rocketchat_settings to
2019-01-13T15:35:17.182+0000 done dumping rocketchat.rocketchat_settings (761 documents)
2019-01-13T15:35:17.187+0000 writing rocketchat.rocketchat_uploads to
2019-01-13T15:35:17.205+0000 done dumping rocketchat.rocketchat_uploads (702 documents)
2019-01-13T15:35:17.207+0000 writing rocketchat.rocketchat_uploads.files to
2019-01-13T15:35:17.263+0000 done dumping rocketchat.rocketchat_uploads.files (702 documents)
2019-01-13T15:35:17.263+0000 writing rocketchat.rocketchat_cron_history to
2019-01-13T15:35:17.271+0000 done dumping rocketchat.rocketchat_cron_history (292 documents)
2019-01-13T15:35:17.271+0000 writing rocketchat.rocketchat_permissions to
2019-01-13T15:35:17.276+0000 done dumping rocketchat.rocketchat_permissions (86 documents)
2019-01-13T15:35:17.276+0000 writing rocketchat.rocketchat__trash to
2019-01-13T15:35:17.329+0000 done dumping rocketchat.rocketchat_statistics (8311 documents)
2019-01-13T15:35:17.329+0000 writing rocketchat.rocketchat_oembed_cache to
2019-01-13T15:35:17.390+0000 done dumping rocketchat.rocketchat_message (20704 documents)
2019-01-13T15:35:17.390+0000 writing rocketchat.rocketchat_subscription to
2019-01-13T15:35:17.395+0000 done dumping rocketchat.rocketchat_subscription (23 documents)
2019-01-13T15:35:17.395+0000 writing rocketchat.rocketchat_roles to
2019-01-13T15:35:17.396+0000 done dumping rocketchat.rocketchat_roles (11 documents)
2019-01-13T15:35:17.396+0000 writing rocketchat.rocketchat_room to
2019-01-13T15:35:17.397+0000 done dumping rocketchat.rocketchat_room (10 documents)
2019-01-13T15:35:17.397+0000 writing rocketchat.custom_emoji.chunks to
2019-01-13T15:35:17.451+0000 done dumping rocketchat.custom_emoji.chunks (10 documents)
2019-01-13T15:35:17.454+0000 writing rocketchat._raix_push_app_tokens to
2019-01-13T15:35:17.466+0000 done dumping rocketchat._raix_push_app_tokens (8 documents)
2019-01-13T15:35:17.466+0000 writing rocketchat.rocketchat_livechat_office_hour to
2019-01-13T15:35:17.473+0000 done dumping rocketchat.rocketchat__trash (68 documents)
2019-01-13T15:35:17.478+0000 writing rocketchat.users to
2019-01-13T15:35:17.478+0000 done dumping rocketchat.rocketchat_livechat_office_hour (7 documents)
2019-01-13T15:35:17.478+0000 writing rocketchat.rocketchat_avatars.chunks to
2019-01-13T15:35:17.482+0000 done dumping rocketchat.rocketchat_oembed_cache (60 documents)
2019-01-13T15:35:17.482+0000 writing rocketchat.rocketchat_avatars.files to
2019-01-13T15:35:17.483+0000 done dumping rocketchat.users (6 documents)
2019-01-13T15:35:17.485+0000 writing rocketchat.rocketchat_avatars to
2019-01-13T15:35:17.486+0000 done dumping rocketchat.rocketchat_avatars.chunks (5 documents)
2019-01-13T15:35:17.486+0000 writing rocketchat.custom_emoji.files to
2019-01-13T15:35:17.486+0000 done dumping rocketchat.rocketchat_avatars.files (5 documents)
2019-01-13T15:35:17.486+0000 writing rocketchat.rocketchat_custom_emoji to
2019-01-13T15:35:17.495+0000 done dumping rocketchat.custom_emoji.files (4 documents)
2019-01-13T15:35:17.496+0000 writing rocketchat.usersSessions to
2019-01-13T15:35:17.496+0000 done dumping rocketchat.rocketchat_custom_emoji (4 documents)
2019-01-13T15:35:17.496+0000 writing rocketchat.assets.files to
2019-01-13T15:35:17.496+0000 done dumping rocketchat.rocketchat_avatars (5 documents)
2019-01-13T15:35:17.496+0000 writing rocketchat.assets.chunks to
2019-01-13T15:35:17.497+0000 done dumping rocketchat.assets.files (1 document)
2019-01-13T15:35:17.497+0000 writing rocketchat.rocketchat_oauth_apps to
2019-01-13T15:35:17.498+0000 done dumping rocketchat.rocketchat_oauth_apps (1 document)
2019-01-13T15:35:17.499+0000 writing rocketchat.migrations to
2019-01-13T15:35:17.499+0000 done dumping rocketchat.assets.chunks (1 document)
2019-01-13T15:35:17.499+0000 writing rocketchat.instances to
2019-01-13T15:35:17.500+0000 done dumping rocketchat.migrations (1 document)
2019-01-13T15:35:17.500+0000 writing rocketchat.rocketchat_apps_persistence to
2019-01-13T15:35:17.502+0000 done dumping rocketchat.instances (1 document)
2019-01-13T15:35:17.502+0000 writing rocketchat.rocketchat_custom_sounds to
2019-01-13T15:35:17.502+0000 done dumping rocketchat.rocketchat_apps_persistence (0 documents)
2019-01-13T15:35:17.502+0000 writing rocketchat.rocketchat_message_read_receipt to
2019-01-13T15:35:17.502+0000 done dumping rocketchat.usersSessions (3 documents)
2019-01-13T15:35:17.502+0000 writing rocketchat.rocketchat_credential_tokens to
2019-01-13T15:35:17.503+0000 done dumping rocketchat.rocketchat_message_read_receipt (0 documents)
2019-01-13T15:35:17.503+0000 writing rocketchat.rocketchat_smarsh_history to
2019-01-13T15:35:17.504+0000 done dumping rocketchat.rocketchat_custom_sounds (0 documents)
2019-01-13T15:35:17.504+0000 writing rocketchat.rocketchat_apps to
2019-01-13T15:35:17.504+0000 done dumping rocketchat.rocketchat_smarsh_history (0 documents)
2019-01-13T15:35:17.504+0000 writing rocketchat.rocketchat_integration_history to
2019-01-13T15:35:17.505+0000 done dumping rocketchat.rocketchat_apps (0 documents)
2019-01-13T15:35:17.505+0000 writing rocketchat.rocketchat_export_operations to
2019-01-13T15:35:17.505+0000 done dumping rocketchat.rocketchat_credential_tokens (0 documents)
2019-01-13T15:35:17.506+0000 writing rocketchat.rocketchat_livechat_inquiry to
2019-01-13T15:35:17.506+0000 done dumping rocketchat.rocketchat_integration_history (0 documents)
2019-01-13T15:35:17.506+0000 writing rocketchat.rocketchat_livechat_external_message to
2019-01-13T15:35:17.507+0000 done dumping rocketchat.rocketchat_export_operations (0 documents)
2019-01-13T15:35:17.507+0000 writing rocketchat.rocketchat_import to
2019-01-13T15:35:17.507+0000 done dumping rocketchat.rocketchat_livechat_external_message (0 documents)
2019-01-13T15:35:17.507+0000 writing rocketchat.meteor_oauth_pendingCredentials to
2019-01-13T15:35:17.508+0000 done dumping rocketchat.rocketchat_livechat_inquiry (0 documents)
2019-01-13T15:35:17.508+0000 writing rocketchat.rocketchat_apps_logs to
2019-01-13T15:35:17.508+0000 done dumping rocketchat.meteor_oauth_pendingCredentials (0 documents)
2019-01-13T15:35:17.508+0000 writing rocketchat.rocketchat_livechat_custom_field to
2019-01-13T15:35:17.509+0000 done dumping rocketchat.rocketchat_livechat_custom_field (0 documents)
2019-01-13T15:35:17.509+0000 writing rocketchat.meteor_accounts_loginServiceConfiguration to
2019-01-13T15:35:17.510+0000 done dumping rocketchat.meteor_accounts_loginServiceConfiguration (0 documents)
2019-01-13T15:35:17.510+0000 writing rocketchat.rocketchat_livechat_page_visited to
2019-01-13T15:35:17.511+0000 done dumping rocketchat.rocketchat_import (0 documents)
2019-01-13T15:35:17.511+0000 writing rocketchat.rocketchat_livechat_department_agents to
2019-01-13T15:35:17.512+0000 done dumping rocketchat.rocketchat_livechat_page_visited (0 documents)
2019-01-13T15:35:17.512+0000 writing rocketchat.rocketchat_user_data_files to
2019-01-13T15:35:17.512+0000 done dumping rocketchat.rocketchat_livechat_department_agents (0 documents)
2019-01-13T15:35:17.512+0000 writing rocketchat.rocketchat_livechat_visitor to
2019-01-13T15:35:17.512+0000 done dumping rocketchat.rocketchat_apps_logs (0 documents)
2019-01-13T15:35:17.513+0000 writing rocketchat.rocketchat_livechat_trigger to
2019-01-13T15:35:17.513+0000 done dumping rocketchat.rocketchat_user_data_files (0 documents)
2019-01-13T15:35:17.513+0000 writing rocketchat.rocketchat_reports to
2019-01-13T15:35:17.513+0000 done dumping rocketchat.rocketchat_reports (0 documents)
2019-01-13T15:35:17.514+0000 writing rocketchat.rocketchat_webdav_accounts to
2019-01-13T15:35:17.514+0000 done dumping rocketchat.rocketchat_livechat_visitor (0 documents)
2019-01-13T15:35:17.514+0000 writing rocketchat.rocketchat_livechat_department to
2019-01-13T15:35:17.515+0000 done dumping rocketchat.rocketchat_webdav_accounts (0 documents)
2019-01-13T15:35:17.515+0000 writing rocketchat.rocketchat_integrations to
2019-01-13T15:35:17.516+0000 done dumping rocketchat.rocketchat_integrations (0 documents)
2019-01-13T15:35:17.516+0000 writing rocketchat.ufsTokens to
2019-01-13T15:35:17.516+0000 done dumping rocketchat.rocketchat_livechat_department (0 documents)
2019-01-13T15:35:17.516+0000 writing rocketchat.meteor_oauth_pendingRequestTokens to
2019-01-13T15:35:17.517+0000 done dumping rocketchat.ufsTokens (0 documents)
2019-01-13T15:35:17.517+0000 done dumping rocketchat.meteor_oauth_pendingRequestTokens (0 documents)
2019-01-13T15:35:17.518+0000 done dumping rocketchat.rocketchat_livechat_trigger (0 documents)
2019-01-13T15:35:18.927+0000 done dumping rocketchat.rocketchat_uploads.chunks (1980 documents)
$ kubectl -n rocketchat get jobs
NAME COMPLETIONS DURATION AGE
mongodb-backup-1547393700 1/1 34s 39s
$ kubectl -n rocketchat get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
mongodb-backup 35 * * * * False 0 51s 17m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment