Skip to content

Instantly share code, notes, and snippets.

@MerlinDMC
Created October 15, 2012 06:44
Show Gist options
  • Save MerlinDMC/3891107 to your computer and use it in GitHub Desktop.
Save MerlinDMC/3891107 to your computer and use it in GitHub Desktop.
recreate SmartOS imgadm database from cache
#!/usr/node/0.8/bin/node
var fs = require('fs');
var imgadm = require('/usr/img/node_modules/imgadm');
var db = require('/usr/img/node_modules/db');
var DB_PATH = '/var/db/imgadm';
db.list(function(err, uuids) {
uuids.forEach(function (uuid) {
try {
JSON.parse(fs.readFileSync(DB_PATH + '/' + uuid + '.json'));
} catch (err) {
// recreate
imgadm.show(uuid, function (err, manifest) {
if (manifest === null) {
console.log('error: manifest for ' + uuid + ' not in cache (maybe local imported dataset)');
return;
}
db.save(manifest, function(err) {
if (err) console.log('error: updating ' + uuid + ' failed');
});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment