Skip to content

Instantly share code, notes, and snippets.

@cllovatto
Created November 1, 2022 19:59
Show Gist options
  • Save cllovatto/faba1185accb721b7da7206ac400fde0 to your computer and use it in GitHub Desktop.
Save cllovatto/faba1185accb721b7da7206ac400fde0 to your computer and use it in GitHub Desktop.
Perform a MongoDB Logical Backup and Restore on k8s cluster
Backup
- Create a volume and attach to control plane instance (for example, attached to /dev/vdb)
- Login to instance and:
fdisk /dev/vdb
n
p
<enter> 3x
w
mkfs.ext4 /dev/vdb1
mkdir /mnt/backup
mount /dev/vdb1 /mnt/backup
nohup kubectl exec deployment.apps/mongo -n <namespace> -- sh -c 'mongodump --archive' > mongo_dump.mongo.gz 2> command_out &
Restore
- Bring only mongo instance from scratch
- Login to instance, then:
nohup cat <db-dump-file> | kubectl exec -i deployment.apps/mongo -n <namespace> -- mongorestore -vvvvv --archive --drop 2> command_out &
Follow progress tailing command_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment