且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何备份和还原Mongodb数据库

更新时间:2022-11-02 21:37:48

如果您只想要自动备份,则有一种比采用成熟的编程语言更简单的方法:

If you just want automated backups, there is an easier way than resorting to a full-fledged programming language:

http://docs.mongodb.org/manual /tutorial/backup-databases-with-filesystem-snapshots/

如链接中所示,以下命令就足够了.您可以将其放在statup-script/daemon中以常规频率执行:

As shown in the link, the below command would suffice. You may put it in a statup-script/daemon to execute it at regular frequencies:

备份:

lvcreate --size 100M --snapshot --name mdb-snap01 /dev/vg0/mongodb

还原:

lvcreate --size 1G --name mdb-new vg0
gzip -d -c mdb-snap01.gz | dd of=/dev/vg0/mdb-new
mount /dev/vg0/mdb-new /srv/mongodb