Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 506 Bytes

mongodb_dump.md

File metadata and controls

18 lines (14 loc) · 506 Bytes

将服务器上 mongodb 所有库的数据同步到本地的脚步(或者用 ssh -L 隧道反向代理服务器上数据库端口到本地)

set -u

remote="[email protected]"

dbs=("user" "orders" "trades")
for db in "${dbs[@]}"
do
    echo "dump $db from remote and restore to local"
    ssh $remote "mongodump --db $db --archive=$db.archive"
    scp "$remote:~/$db.archive" .
    mongorestore --stopOnError --drop --db $db --archive=$db.archive
done