[noSQL] Replication, backup multi databases with CouchDB script
Default, couchDB do not support replication for multi database. In a beautiful day, you want to move couchDB database to other server. What the solutions? Dump same a mysql dump? Not have. Copy all the file to new server, not good. You probably use replication function in couchDB, but if you have about 200 databases on old server now?
You can use curl command with this script, running for replication unlimited databases.
database_name1Step 2. Create perl file ckl.pl with contains:
database_name2
database_name199
#!/usr/bin/perlStep 3. Chmod for ckl.pl file
# ckl.pl
#!/usr/local/bin/perl
# Created by Chung.Pham
# Date: 11/26/2013
$src_address = "couchdb.example.com";
$src_user = "admin";
$src_passwd = "password";
$dest_address = "localhost:5984";
$dest_user = "admin";
$dest_passwd = "password";
# Do not edit here
open (script, 'source.txt');
while (<script>) {
$db_name = "$_";
chomp $db_name;
$string = "sudo curl -H \'Content-Type: application\/json\' -X POST http:\/\/" . $dest_user . ":" . $dest_passwd . "@" . $dest_address . "\/_replicate -d \'\{\"source\": \"http:\/\/" . $src_user . ":" . $src_passwd . "@" . $src_address . "\/" . $db_name . "\"" . "\, \"target\": \"" . $db_name . "\"\, \"create_target\": true}\'\n";
print $string;
}
close (script);
chmodStep 4. Running that perl file to generator a script+r ckl.pl
./ckl.pl > script.shStep 5. Copy file script.sh to server couchDB and run it:
chmod + r script.shRecommend:
./script.sh
You should try to run 1 line curl in script.sh file, if it show that bollow, meaning is working ok:
{"ok":true,"session_id":"9721d9991f47c84409cfb2951b466ef6","source_last_seq":2,"replication_id_version":3,"history":[{"session_id":"9721d9991f47c84409cfb2951b466ef6","start_time":"Wed, 27 Nov 2013 01:14:35 GMT","end_time":"Wed, 27 Nov 2013 01:14:38 GMT","start_last_seq":0,"end_last_seq":2,"recorded_seq":2,"missing_checked":2,"missing_found":0,"docs_read":0,"docs_written":0,"doc_write_failures":0}]}