In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Percona MongoDB HotBackup Hot backup tool
Foreword:
Currently, the official MongoDB Community Edition does not support Hot Backup hot backup. We can only export bson files through logical backup tools such as mongodump, and then import them with mongorestore, which is similar to MySQL's mysqldump tool.
When backing up the replica set, we need to specify the-- oplog option to record the incremental data generated between backups, similar to mysqldump-- single-transaction-- master-data=2 (take a consistent snapshot and record the current binlog point).
To restore the members of the replica set, you need to first cut it into a stand-alone version. Mongorestore must specify the-- oplogReplay option to restore the snapshot at a certain time, and finally you need to fill in oplog (where the incremental data starts to resume from the breakpoint), mongorestore-d local-c oplog.rs dump/oplog.bson, and then restart for the replica set members.
Small and medium-sized databases are easy and fast to back up, and it will be painful if they exceed the amount of data at the TB level.
If your oplog setting is too small, it is likely that the oplog will be overwritten during the backup recovery period, and you will never be able to join the replica set cluster.
Overview:
The Percona MongoDB3.2 version starts to support online hot backup of the WiredTiger engine by default, which solves the problem that the official version can only be backed up through mongodump logic.
References:
Https://www.percona.com/doc/percona-server-for-mongodb/LATEST/hot-backup.html#hot-backup
Note:
1. To make a hot backup of the database in the current dbpath, run the createBackup command as an administrator on the admin database and specify the backup directory.
2. You can replace a slave library with Percona MongoDB for backup. (the actual measurement here is Percona MongoDB version 3.4)
The principle of Percona MongoDB HotBackup hot backup:
You can imagine it as a xtrabackup tool.
Backup:
1. First, a background detection process will be started to detect the changes of MongoDB Oplog in real time. As soon as new log writes are found in oplog, the log will be written to the log file WiredTiger.backup (you can strings WiredTiger.backup to check the changes of oplog operation logs)
2. Copy the data files and index files of MongoDB dbpath to the specified backup directory.
.
Restore:
1. Playback the WiredTiger.backup log, apply the operation log changes to the WiredTiger engine, and finally get a consistent snapshot recovery.
2. Copy the data files in the backup directory directly to your dbpath, and then start MongoDB, which will be automatically connected to the replica set cluster.
Here I encapsulate a PHP script that can be run directly in SHELL.
1. Environmental preparation:
Shell > yum install-y php-pear php-devel php gcc openssl openssl-devel cyrus-sasl cyrus-sasl-devel
2. Php-mongo driver installation:
Shell > pecl install mongo
Add extension=mongo.so to the last line of / etc/php.ini.
3. Create mongodb superuser permissions (used when backing up)
Db.createUser ({user: "admin", pwd: "123456", roles: [{role: "root", db: "admin"}]})
4. Modify pmongo_bak.php configuration information
/ / modify the following configuration information * / /
$user = "admin"; / / use root user rights
$pwd = '123456'
$host = '192.168.180.26standby; / / Hot backup on slave library
$port = '27017'
$authdb = 'admin'; / / privilege authentication database
$BAKDIR = "/ data/bak/"
$BAKDIR. = date ('Yoshimachdhi')
/ / the following code does not need to be modified * /
M = new MongoBak ($user,$pwd,$host,$port,$authdb,$BAKDIR)
.
5. Front desk operation:
Shell > php pmongo_bak.php (run with root privileges)
6. Write it to the system crontab
00 01 * / usr/bin/php / root/php_mongodb/pmongo_bak.php > / root/php_mongodb/bak_status.log 2 > & 1
7. Remote backup is not supported. You need to deploy the backup script in the slave library. If you want to back up your data remotely, you can mount it using a file system such as NFS mount.
Download address:
Https://github.com/hcymysql/PMongo-HotBackup
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.