MangoDB 容器备份一看就懂,一学就会!

#!/bin/bash
#backup mongoDB
#option
day=$(date +%Y_%m_%d)
delDay=$(date -d '1 day ago' +%Y_%m_%d)
delMon=$(date -d '1 month ago' +%Y_%m_%d)
containerID='44d320454502'

#backup in backup
dcDelFile="/backup/mongo/${delDay}.sql"
dcBackFile="/backup/mongo/${day}.sql"
docker exec ${containerID} rm -rf ${dcDelFile} > /dev/null
docker exec ${containerID} mongodump -o ${dcBackFile} > /dev/null


#backup in server
delFile="/backup/mongo/${delMon}.tar.gz"
backFile="/backup/mongo/${day}.sql"
rm -rf ${delFile}
docker cp ${containerID}:${backFile} ${backFile}

cd /backup/mongo && tar -czf ${day}.tar.gz ./${day}.sql && rm -rf ./${day}.sql

echo "success"

上一篇:MangoDB


下一篇:七十二、MangoDB安装,基础连接和查询