Skip to content

Instantly share code, notes, and snippets.

@mertonium
Created April 19, 2011 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mertonium/926717 to your computer and use it in GitHub Desktop.
Save mertonium/926717 to your computer and use it in GitHub Desktop.
Little php script to install the same couch app on a bunch of dbs in the same instance
<?php
// Configure control variables
$couch_url = "http://yourcouchinstance.com";
$path_to_couchapp = "/local_path_to/couchapp/";
// Counter
$db_count = 0;
// Time check (we'll use this later)
$start_ts = time();
// Get all the dbs
$all_dbs_str = `curl -X GET {$couch_url}/_all_dbs`;
$all_dbs = explode('","', trim(str_replace(array('["','"]'), '', $all_dbs_str)));
// Loop through the dbs, injecting the app into each one
foreach($all_dbs as $db) {
// Only copy the ones with the "phl_" prefix
if(strpos($db, 'phl_') !== false) {
$db = trim($db); // Extra cleaning
echo "Pushing couchapp to {$db}\n";
echo `couchapp push {$path_to_couchapp} {$couch_url}/{$db}`;
echo "\n";
$db_counter++;
}
}
// Final time check
$end_ts = time();
// Figure time spent
$run_time = $end_ts - $start_ts;
// Print out summary
echo "====================\n";
echo 'Run finished in ' . $run_time .' seconds.' . "\n";
echo $db_counter . ' databases replicated.' . "\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment