Advertisement
Guest User

Untitled

a guest
Sep 13th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////
  2. // Run: 'gulp download-db' to get latest SQL dump from production //
  3. // File will be put under the 'dumps' folder //
  4. ////////////////////////////////////////////////////////////////////
  5.  
  6. // Load stuff
  7. 'use strict'
  8. var gulp = require('gulp')
  9. var GulpSSH = require('gulp-ssh')
  10. var fs = require('fs');
  11. // Function to get home path
  12. function getUserHome() {
  13. return process.env.HOME || process.env.USERPROFILE;
  14. }
  15. var homepath = getUserHome();
  16.  
  17. ///////////////////////////////////////
  18. // SETTINGS (change if needed) //
  19. ///////////////////////////////////////
  20.  
  21.  
  22. var config = {
  23.  
  24. // SSH connection
  25. host: '1.2.3.4',
  26. port: 22,
  27. username: 'ubuntu',
  28. //password: '1337p4ssw0rd', // Uncomment if needed
  29. privateKey: fs.readFileSync( homepath + '/certs/somecert.pem'), // Uncomment if needed
  30.  
  31. // MySQL connection
  32. db_host: 'localhost',
  33. db_name: 'clients_db',
  34. db_username: 'root',
  35. db_password: 'dbp4ssw0rd',
  36.  
  37. }
  38.  
  39. ////////////////////////////////////////////////
  40. // Core script, don't need to touch from here //
  41. ////////////////////////////////////////////////
  42.  
  43.  
  44. // Set up SSH connector
  45. var gulpSSH = new GulpSSH({
  46. ignoreErrors: true,
  47. sshConfig: config
  48. })
  49.  
  50. // Run the mysqldump
  51. gulp.task('download-db', function(){
  52. return gulpSSH
  53. // runs the mysql dump
  54. .exec(['mysqldump -u '+config.db_username+' -p\''+config.db_password+'\' -h '+config.db_host+' '+config.db_name+''], {filePath: 'dump.sql'})
  55. // pipes output into local folder
  56. .pipe(gulp.dest('dumps'))
  57. })
  58.  
  59. // Run search/replace "optional"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement