title: Gulp task to SSH and then mysqldump
body: <p>So I've got this scenario where I have separate Web server and MySQL server, and I can only connect to the MySQL server from the web server.</p>
  
  <p>So basically everytime I have to go like:</p>
  
  <ul>
  <li>step 1: 'ssh -i ~/somecert.pem ubuntu@1.2.3.4'</li>
  <li>step 2: 'mysqldump -u root -p'password' -h 6.7.8.9 database_name > output.sql'</li>
  </ul>
  
  <p>I'm new to gulp and my aim was to create a task that could automate all this, so running one gulp task would automatically deliver me the SQL file.</p>
  
  <p>This would make the developer life a lot easier since it would just take a command to download the latest db dump.</p>
  
  <p>This is where I got so far (gulpfile.js):</p>
  
  <pre><code>////////////////////////////////////////////////////////////////////
  // Run: 'gulp download-db' to get latest SQL dump from production //
  // File will be put under the 'dumps' folder                      //
  ////////////////////////////////////////////////////////////////////
  
  // Load stuff
  'use strict'
  var gulp = require('gulp')
  var GulpSSH = require('gulp-ssh')
  var fs = require('fs');
  // Function to get home path
  function getUserHome() {
    return process.env.HOME || process.env.USERPROFILE;
  }
  var homepath = getUserHome();
  
  ///////////////////////////////////////
  // SETTINGS (change if needed)       //
  ///////////////////////////////////////
  
  
  var config = {
  
    // SSH connection
    host: '1.2.3.4',
    port: 22,
    username: 'ubuntu',
    //password: '1337p4ssw0rd', // Uncomment if needed
    privateKey: fs.readFileSync( homepath + '/certs/somecert.pem'), // Uncomment if needed
  
    // MySQL connection
    db_host: 'localhost',
    db_name: 'clients_db',
    db_username: 'root',
    db_password: 'dbp4ssw0rd',
  
  }
  
  ////////////////////////////////////////////////
  // Core script, don't need to touch from here //
  ////////////////////////////////////////////////
  
  
  // Set up SSH connector
  var gulpSSH = new GulpSSH({
    ignoreErrors: true,
    sshConfig: config
  })
  
  // Run the mysqldump
  gulp.task('download-db', function(){
    return gulpSSH
      // runs the mysql dump
      .exec(['mysqldump -u '+config.db_username+' -p\''+config.db_password+'\' -h '+config.db_host+' '+config.db_name+''], {filePath: 'dump.sql'})
      // pipes output into local folder
      .pipe(gulp.dest('dumps'))
  })
  
  // Run search/replace "optional"
  </code></pre>
  
  <p>SSH into the web server runs fine, but I have an issue when trying to get the mysqldump, I'm getting this message:</p>
  
  <pre><code>events.js:85
    throw er; // Unhandled 'error' event
          ^
  Error: Warning: 
  </code></pre>
  
  <p>If I try the same mysqldump command manually from the server SSH, I get:</p>
  
  <pre><code>Warning: mysqldump: unknown variable 'loose-local-infile=1'
  </code></pre>
  
  <p>Followed by the correct mylsql dump info.</p>
  
  <p>So I think this warning message is messing up my script, I would like to ignore warnings in cases like this, but don't know how to do it or if it's possible.</p>
  
  <p>Also I read that using the password directly in the command line is not really good practice.</p>
  
  <p>Ideally, I would like to have all the config vars loaded from another file, but this is my first gulp task and not really familiar with how I would do that.</p>
  
  <p>Can someone with experience in Gulp orient me towards a good way of getting this thing done? Or do you think I shouldn't be using Gulp for this at all?</p>
  
  <p>Thanks!</p>