diff --git a/lib/dbDump.js b/lib/dbDump.js index 6e80483..2fb526d 100644 --- a/lib/dbDump.js +++ b/lib/dbDump.js @@ -50,7 +50,7 @@ function dbDump(config, output_paths, noExec) { } }); - cmd = tpl_ssh + " \\ " + tpl_mysqldump; + cmd = tpl_ssh + " " + tpl_mysqldump; } if (!noExec) { diff --git a/lib/dbReplace.js b/lib/dbReplace.js index 41d0c37..0a090ac 100644 --- a/lib/dbReplace.js +++ b/lib/dbReplace.js @@ -11,20 +11,16 @@ function dbReplace(search, replace, output_path, noExec) { // avoids overwriting original backup grunt.file.copy(output_path.file, output_path["file-tmp"]); - // Perform Search and replace on the temp file (not original) - var cmd = grunt.template.process( tpls.search_replace, { - data: { - search: search, - replace: replace, - path: output_path["file-tmp"] - } - }); - if ( grunt.file.exists(output_path["file-tmp"])) { // Execute cmd if (!noExec) { grunt.log.writeln("Replacing '" + search + "' with '" + replace + "' in the export (.sql) path.file."); - shell.exec(cmd); + + var reg= new RegExp(search,"g"); //Create a global regexp w/ search string + var myFile=grunt.file.read(output_path["file-tmp"]); //Get file as a string + var result = myFile.replace(reg, replace); //Replace search string by replace string + grunt.file.write(output_path["file-tmp"], result); //Write in file + grunt.log.oklns("Database references succesfully updated."); } } else { @@ -32,7 +28,7 @@ function dbReplace(search, replace, output_path, noExec) { } // Return for reference and test suite purposes - return cmd; + return shell; } module.exports = dbReplace; \ No newline at end of file diff --git a/lib/tpls.js b/lib/tpls.js index ab12936..c00403c 100644 --- a/lib/tpls.js +++ b/lib/tpls.js @@ -5,8 +5,6 @@ */ var tpls = { - search_replace: "sed -i '' 's#<%= search %>#<%= replace %>#g' <%= path %>", - backup_path: "<%= backups_dir %>/<%= env %>/<%= date %>/<%= time %>", mysql: "mysql -h <%= host %> -u <%= user %> -p<%= pass %> -P<%= port %> <%= database %>", diff --git a/tasks/deployments.js b/tasks/deployments.js index 74cadb9..24b3ce2 100644 --- a/tasks/deployments.js +++ b/tasks/deployments.js @@ -55,7 +55,7 @@ module.exports = function(grunt) { dbDump(local_options, local_backup_paths); // Search and Replace database refs - dbReplace( local_options.url, target_options.url, local_backup_paths.file ); + dbReplace( local_options.url, target_options.url, local_backup_paths ); // Dump target DB dbDump(target_options, target_backup_paths);