Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to automate backup script and recovery by mysql and mongoDB

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following content mainly brings you mysql, mongoDB is how to automate backup scripts and recovery, the knowledge, different from books, are summed up by professional and technical personnel in the process of contact with users, have a certain experience sharing value, hope to bring help to the majority of readers.

Mysql automatic backup script

Vim / var/tool/mysqlbackup.sh #! / bin/bashshijie= `date +% Y% m% d% H`backDatabaseDB = database$shijie.sqlbackDatabaseFile=database$shijie.tar.gzcd / var/mysql/back/ / usr/local/mysql/bin/mysqldump-uroot-p123456-- default-character-set=utf8-- opt-- extended-insert=false-- triggers-R-- hex-blob-- single-transaction database > $backDatabaseDBtar czf $backDatabaseFile $backDatabaseDBrm $backDatabaseDB-rf scheduled task 00 * root / var/tool/mysql/backup.sh # 0 minutes per hour Execute 00 5 * root find / var/mysql/back/-mtime + 0-type f-exec rm-f {}\ # delete files 24 hours ago at 5: 00 every day mongo automatic backup script #! / bin/bashshijie= `date +% Y% m% d% H`backmongodbFile = mongodb$shijie.tar.gzcd / var/mongo/back//usr/local/mongo/bin/mongodump-h 127.0.0.1-- port 27017-u mongo-p 123456-d my_mongodb-o my_mongodb_dump/tar czf $backmongodbFile my_mongodb_dump/rm my_mongodb_dump-rf scheduled execution and deletion similar to mysql Restore after backup mysql restore: mysql-uroot-p 123456 database < database.sqlmongo restore: / usr/local/mongo/bin/mongorestore-d my_mongodb my_mongodb_dump/my_mongodb/* points to each file / usr/local/mongo/bin/mongorestore-h 127.0.0.1-- port 27017-- drop-- directoryperdb my_mongodb_dump/my_mongodb points to a directory

Explanation: adding-- drop parameter will empty the data before importing it.

For the above about mysql, mongoDB how to automate the backup script and recovery, if you need to know more, you can continue to follow our industry promotion, if you need professional answers, you can contact the pre-sales and after-sales on the official website. I hope this article can bring you some knowledge updates.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report