Created
November 23, 2015 10:04
-
-
Save eduwass/ecd333ae1ea64d57d2c5 to your computer and use it in GitHub Desktop.
Gulp task to SSH into production server and retrieve mysqldump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////// | |
// 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment