Last active
August 15, 2016 19:09
-
-
Save ivanproskuryakov/ad6955b8a4daef8d06b0cb7246159a08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
local_directory=$PWD | |
db_name="database" | |
host="domain.com" | |
#create backup on remote machine | |
ssh -p 22 root@${host} "cd /tmp && mongodump -o ${db_name}" | |
#copy to local machine in backup directory | |
scp -r root@${host}:/tmp/${db_name} "${local_directory}/backup/" | |
#restore db to local machine | |
mongorestore --host 127.0.0.1 --db ${db_name} "${local_directory}/backup/${db_name}/" | |
#remove backup from remote & local machines | |
ssh -p 22 root@${host} "rm -rf /tmp/${db_name}" | |
rm -rf "${local_directory}/backup/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment