boom-deploy
Advanced tools
Comparing version 0.1.10 to 0.1.11
@@ -87,3 +87,3 @@ | ||
new Task('dump:mongo', function(import_env){ | ||
new Task('mongo:dump', function(import_env){ | ||
mongoDump(import_env, { | ||
@@ -98,3 +98,3 @@ collections: [ | ||
new Task('dump:mysql:devroles', function(){ | ||
new Task('mysql:devroles', function(){ | ||
setDevRolesInMysql([ | ||
@@ -138,3 +138,3 @@ 'jiexa', | ||
switchEnv(import_env); | ||
task('dump:mysql:devroles'); | ||
task('mysql:devroles'); | ||
@@ -141,0 +141,0 @@ }, 'dump mysql tables from env to env') |
@@ -148,2 +148,3 @@ | ||
new Task('memcached:flush', function(){ | ||
if (!get('memcached.host') || !get('memcached.port')) exit('Has no memcached settings.'); | ||
ssh('(echo flush_all; echo quit) | nc {{memcached.host}} {{memcached.port}}'); | ||
@@ -180,6 +181,4 @@ }, 'flush memcached'); | ||
new Helper(function mysqlDumpOld(import_env, options){ | ||
new Helper(function mongoDump(import_env, options){ | ||
console.time('dump duration'); | ||
var import_env = import_env || 'local'; | ||
@@ -201,46 +200,30 @@ var export_env = get('env'); | ||
var exportMysql = exportConfig.mysql; | ||
var importMysql = get('mysql'); | ||
var exportMongo = exportConfig.mongodb.slave || exportConfig.mongodb.master; | ||
var importMongo = get('mongodb.master'); | ||
var collections = get('collections') ? get('collections').split(/\s+/) : options.collections; | ||
set('dumpName', ['dump', export_env, get('timestamp'), exportMysql.dbname, md5()].join('_') + '.sql'); | ||
var all = get('all'); | ||
var tables_only = get('tables_only'); | ||
var tables_ignore = get('tables_ignore') ? get('tables_ignore').split(/\s+/) : options.tables_ignore; | ||
var table_options = ''; | ||
if (all) { | ||
table_options = exportMysql.dbname; | ||
} else if (tables_only) { | ||
table_options = [exportMysql.dbname, tables_only].join(' '); | ||
} else { | ||
table_options = [exportMysql.dbname].concat(tables_ignore).join(' --ignore-table=' + exportMysql.dbname + '.') | ||
function getMongoParams(mongo){ | ||
var opts = [ | ||
'--host=' + mongo.host, | ||
'--db=' + mongo.database | ||
] | ||
if (mongo.username) opts.push('--username=' + mongo.username); | ||
if (mongo.password) opts.push('--password=' + mongo.password); | ||
return opts.join(' '); | ||
} | ||
function getMysqlParams(mysql){ | ||
return [ | ||
'--force', | ||
'--host=' + mysql.host, | ||
'--user=' + mysql.username, | ||
'--password=' + mysql.password | ||
].join(' ') | ||
function removeDump(dump_name){ | ||
lazySsh('rm -f ~/dumps/mongo/' + dump_name); | ||
} | ||
function removeDump(){ | ||
lazySsh('rm -f ~/dumps/mysql/{{dumpName}}') | ||
} | ||
lazySsh('mkdir -p ~/dumps/mongo'); | ||
lazySsh('mkdir -p ~/dumps/mysql'); | ||
try { | ||
lazySsh('mysqldump --disable-keys ' + getMysqlParams(exportMysql) + ' ' + table_options + ' > ~/dumps/mysql/{{dumpName}}'); | ||
lazySsh('mysql ' + getMysqlParams(importMysql) + ' ' + importMysql.dbname + ' < ~/dumps/mysql/{{dumpName}}'); | ||
} catch(err) { | ||
removeDump(); | ||
throw err; | ||
} | ||
console.timeEnd('dump duration'); | ||
removeDump(); | ||
collections.forEach(function(collection){ | ||
var dump_name = ['dump', export_env, exportMongo.database, collection, 'bson'].join('.'); | ||
console.log('\n##### DUMP %s #####', collection); | ||
lazySsh('cd ~/dumps/mongo && mongodump ' + getMongoParams(exportMongo) + ' --collection ' + collection + ' --out - > ' + dump_name); | ||
lazySsh('cd ~/dumps/mongo && mongorestore --drop ' + getMongoParams(importMongo) + ' --collection ' + collection + ' ' + dump_name); | ||
removeDump(dump_name); | ||
}) | ||
}); | ||
@@ -275,13 +258,7 @@ | ||
// преключаем окружение на import_env, все операции будем делать с него | ||
// switchEnv(import_env); | ||
var exportConfig = getConfig(export_env); | ||
var importConfig = getConfig(import_env); | ||
var exportMysql = exportConfig.mysql; | ||
var importMysql = importConfig.mysql; | ||
var dumpDir = '~/boom-tmp/dumps/mysql/'; | ||
var dumpName = ['dump', export_env, get('timestamp'), exportMysql.dbname/*, md5()*/].join('_') + '.sql.bz2'; | ||
var dumpName = ['dump', export_env, get('timestamp'), exportConfig.mysql.dbname].join('_') + '.sql.bz2'; | ||
@@ -294,7 +271,7 @@ var all = get('all'); | ||
if (all) { | ||
table_options = exportMysql.dbname; | ||
table_options = exportConfig.mysql.dbname; | ||
} else if (tables_only) { | ||
table_options = [exportMysql.dbname, tables_only].join(' '); | ||
table_options = [exportConfig.mysql.dbname, tables_only].join(' '); | ||
} else { | ||
table_options = [exportMysql.dbname].concat(tables_ignore).join(' --ignore-table=' + exportMysql.dbname + '.') | ||
table_options = [exportConfig.mysql.dbname].concat(tables_ignore).join(' --ignore-table=' + exportConfig.mysql.dbname + '.') | ||
} | ||
@@ -319,3 +296,3 @@ | ||
makeDumpDir(); | ||
lazySsh('mysqldump --disable-keys ' + getMysqlParams(exportMysql) + ' ' + table_options + ' | bzip2 > ' + dumpDir + dumpName); | ||
lazySsh('mysqldump --disable-keys ' + getMysqlParams(exportConfig.mysql) + ' ' + table_options + ' | bzip2 > ' + dumpDir + dumpName); | ||
@@ -325,15 +302,34 @@ switchEnv(import_env); | ||
console.time('##### SCP DURATION'); | ||
local('mkdir -p {{userBoomDir}}/dumps/mysql'); | ||
console.time('##### COPY DURATION'); | ||
local('scp -c blowfish -P ' + exportConfig.port + | ||
' ' + exportConfig.user + '@' + exportConfig.server + ':' + dumpDir + dumpName + ' {{userBoomDir}}/dumps/mysql'); | ||
if (import_env == 'dev') { | ||
lazySsh('cp /home/' + exportConfig.user + '/boom-tmp/dumps/mysql/' + dumpName + ' ' + dumpDir); | ||
} else if (import_env == 'local') { | ||
// local('scp -c blowfish -P ' + exportConfig.port + | ||
// ' ' + exportConfig.user + '@' + exportConfig.server + ':' + dumpDir + dumpName + ' ' + dumpDir); | ||
local('scp -c blowfish -P ' + importConfig.port + | ||
' {{userBoomDir}}/dumps/mysql/' + dumpName + ' ' + importConfig.user + '@' + importConfig.server + ':' + dumpDir); | ||
local('rsync -av --progress -e \'ssh -p ' + exportConfig.port +'\' ' + | ||
exportConfig.user + '@' + exportConfig.server + ':' + dumpDir + dumpName + ' ' + dumpDir); | ||
local('rm -f {{userBoomDir}}/dumps/mysql/' + dumpName); | ||
console.timeEnd('##### SCP DURATION'); | ||
} else { | ||
local('mkdir -p {{userBoomDir}}/dumps/mysql'); | ||
lazySsh('bunzip2 < ' + dumpDir + dumpName + ' | mysql ' + getMysqlParams(importMysql) + ' ' + importMysql.dbname); | ||
// local('scp -c blowfish -P ' + exportConfig.port + | ||
// ' ' + exportConfig.user + '@' + exportConfig.server + ':' + dumpDir + dumpName + ' {{userBoomDir}}/dumps/mysql'); | ||
local('rsync -av --progress -e \'ssh -p ' + exportConfig.port + '\' ' + | ||
exportConfig.user + '@' + exportConfig.server + ':' + dumpDir + dumpName + ' {{userBoomDir}}/dumps/mysql'); | ||
// local('scp -c blowfish -P ' + importConfig.port + | ||
// ' {{userBoomDir}}/dumps/mysql/' + dumpName + ' ' + importConfig.user + '@' + importConfig.server + ':' + dumpDir); | ||
local('rsync -av --progress -e \'ssh -p ' + importConfig.port + '\' ' + | ||
'{{userBoomDir}}/dumps/mysql/' + dumpName + ' ' + importConfig.user + '@' + importConfig.server + ':' + dumpDir); | ||
local('rm -f {{userBoomDir}}/dumps/mysql/' + dumpName); | ||
} | ||
console.timeEnd('##### COPY DURATION'); | ||
lazySsh('bunzip2 < ' + dumpDir + dumpName + ' | mysql ' + getMysqlParams(importConfig.mysql) + ' ' + importConfig.mysql.dbname); | ||
removeDump(); | ||
@@ -340,0 +336,0 @@ |
{ | ||
"name": "boom-deploy", | ||
"main": "boom.js", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "deploy your app", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49160
1392