Mongo

mongo 备份

mongo backup

qwding

1 minute read

mongo 备份 秉承方便简单,易搭建原则,还是用docker来实现,镜像地址(https://hub.docker.com/r/carlding/mongobackup/) docker hub找到一个镜像,istepanov/mongodump可以实现本地monogo的备份,查阅其内部脚本,并没有开放传入远程数据库的接口,于是在此基础上改进 Dockerfile FROM istepanov/mongodump ​MAINTAINER qwding ADD backup.sh backup.sh ADD start.sh start.sh backup.sh #!/bin/bash set -e echo "Job started: $(date)" DATE=$(date +%Y%m%d_%H%M%S) FILE="/backup/backup-$DATE.tar.gz" echo "mongodump -h $MONGO_PORT_27017_TCP_ADDR -p $MONGO_PORT_27017_TCP_PORT -u $MONGO_USER -p $MONGO_PASSWORD -d $MONGO_DB" mongodump -h $MONGO_PORT_27017_TCP_ADDR -u $MONGO_USER -p $MONGO_PASSWORD -d $MONGO_DB tar -zcvf $FILE dump/ rm -rf dump/ echo "Job finished: $(date)" start.sh #!/bin/bash set -e CRON_SCHEDULE=${CRON_SCHEDULE:-0 1 * * *} if [[ "$1" == ‘no-cron’ ]]; then exec /backup.

shell execute mongo/mysql which start by docker.

在实例方法内修改实例地址

1 minute read

#问题初衷 打算一键部署带权限验证的mongo。但是docker hub官方镜像创建mongo步骤为: docker run –name mongodb -d -p 27017:27017 mongo:3.3 –auth docker exec -it mongodb mongo admin db.createUser({ user: ‘root’, pwd: ‘root’, roles: [ { role: "root", db: "admin" } ] }); 打算将其做成脚本 #用shell实现 经过查阅,发现shell的 <<EOF 可以实现,查阅资料 http://my.oschina.net/u/1032146/blog/146941 应该可以实现,于是写了脚本 #!/bin/bash mongo admin << EOF db.createUser({ user: ‘root’, pwd: ‘root’, roles: [ { role: "root", db: "admin" } ] }); exit; EOF 在mongo 启动的容器内执行脚本,成功! #直接写脚本启动容器(error) !/bin/bash docker run –name mongodb -d -p 27017:27017 dhub.