Back Up a Shared Server in Mon­goDB

Con­tin­u­ing the se­ries on Mon­goDB, in this ar­ti­cle, read­ers learn how to set up a backup for the sharded en­vi­ron­ment that was set up over the pre­vi­ous two ar­ti­cles.

OpenSource For You - - DEVELOPERS LET’S TRY -

In the pre­vi­ous ar­ti­cle in this se­ries, we set up a sharded en­vi­ron­ment in Mon­goDB. This ar­ti­cle deals with one of the most in­trigu­ing and cru­cial topics in data­base ad­min­is­tra­tion—back­ups. The ar­ti­cle will demon­strate the Mon­goDB backup process and will make a backup of the sharded server that was con­fig­ured ear­lier. So, to pro­ceed, you must set up your sharded en­vi­ron­ment as per our pre­vi­ous ar­ti­cle as we’ll be us­ing the same con­fig­u­ra­tion.

Be­fore we move on with the backup, make sure that the bal­ancer is not run­ning. The bal­ancer is the process that en­sures that data is dis­trib­uted evenly in a sharded clus­ter. This is an au­to­mated process in Mon­goDB and at most times, you won’t be both­ered with it. In this case, though, it needs to be stopped so that no chunk mi­gra­tion takes place while we back up the server. If you’re won­der­ing what the term ‘chunk mi­gra­tion’ means, let me tell you that if one shard in a sharded Mon­goDB en­vi­ron­ment has more data stored than its peers, then the bal­ancer process mi­grates some data to other shards. Evenly dis­trib­uted data en­sures op­ti­mal per­for­mance in a sharded en­vi­ron­ment.

So now con­nect to a Mongo process by open­ing a com­mand prompt, go­ing to the Mon­goDB root di­rec­tory and typ­ing ‘Mongo’. Type sh.getBalancerS­tate() to find out the bal­ancer’s sta­tus. If you get true as the out­put, your bal­ancer is run­ning. Type sh.stopBalancer() to stop the bal­ancer.

The next step is to back up the con­fig server, which stores meta­data about shards. In the pre­vi­ous ar­ti­cle, we set up three con­fig servers for our shard. Since all the con­fig servers store the same meta­data and since we have three of them just to en­sure avail­abil­ity, we’ll be back­ing just one con­fig server for demon­stra­tion pur­poses. So open a com­mand prompt and type the fol­low­ing com­mand to back up the con­fig data­base of our con­fig server: C:\Users\viny\Desk­top\mon­godb-win32-i386-2.6.0\ bin>mon­go­dump ­­host lo­cal­host:59020 ­­db con­fig

This com­mand will dump your con­fig data­base un­der the dump di­rec­tory of your Mon­goDB root di­rec­tory.

Now let’s back up our ac­tual data by tak­ing back­ups of all of our shards. Is­sue the fol­low­ing com­mands, one by one, and take a backup of all the three replica sets of both the shards that we con­fig­ured ear­lier: mon­go­dump --host lo­cal­host:38020 --out .\shard1\replica1 mon­go­dump --host lo­cal­host:38021 --out .\shard1\replica2 mon­go­dump --host lo­cal­host:38022 --out .\shard1\replica3 mon­go­dump --host lo­cal­host:48020 --out .\shard2\replica1 mon­go­dump --host lo­cal­host:48021 --out .\shard2\replica2 mon­go­dump --host lo­cal­host:48022 --out .\shard2\replica3

The -- out pa­ram­e­ter de­fines the di­rec­tory where Mon­goDB will place the dumps. Now you can start the bal­ancer by is­su­ing the sh.startBalancer() com­mand and re­sume nor­mal op­er­a­tions. So we’re done with our backup op­er­a­tion.

If you want to explore a bit more about back­ups and re­stores in Mon­goDB, you can check Mon­goDB doc­u­men­ta­tion and the ar­ti­cle in http://www.thegeek­stuff. com/2013/09/mon­go­dump-mon­gore­store/ which will give you some good in­sights into Mon­go­dump and Mon­gore­store com­mands.

Fig­ure 1: Bal­ancer sta­tus

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.