In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you about the realization of automatic backup of MongoDB, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Install expect
Yum install-y expect
Write expect scripts
The expect syntax is very simple, almost the same as Shell. The author's script is as follows:
#! / bin/expect # spawn is a statement of expect. Before executing the command, you need to add the word set DATE [exec date "+% Y-%m-%d"] set DIR / xxxxx/dbbak-$DATE spawn rm-rf $DIR spawn echo 'removing...$DIR' spawn mongodump-h {host:port}-u {user}-d {dbname}-o $DIR # Interactive get whether password is returned: the key expect "password:" # send the password, and note that the final line feeds cannot be reduced. Otherwise, you will have to enter enter manually. Send "password\ r" # stays on the remote console. Without this line, it will directly return to the local console without waiting for shell to execute interact.
The notes are very comprehensive, and if you are smart, there will be no pressure to read. The final backed up files will be stored in the / xxxxx/dbbak- backup date directory.
Automatic backup
The author uses Linux timing task to realize automatic execution.
Crontab-e
Add the following to the new window:
The full path of expect shell on 0 01 * *? / usr/bin/expect
It was thought that it could be carried out regularly, but it could not be carried out normally.
After Baidu, modify the script to the following, finally can be executed normally.
#! / bin/expect # spawn is a statement of expect. Before executing the command, you need to add the word set DATE [exec date "+% Y-%m-%d"] set DIR / xxxxx/dbbak-$DATE spawn rm-rf $DIR spawn echo 'removing...$DIR' spawn mongodump-h {host:port}-u {user}-d {dbname}-o $DIR # Interactive get whether password is returned: the key expect "password:" # send the password, and note that the final line feeds cannot be reduced. Otherwise, you will have to enter enter manually. Send "password" set timeout 120expect eof exit or above is the automatic backup of MongoDB. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.