Last active
August 29, 2015 14:04
WordPress Database Sync with Grunt. See http://cfxdesign.com/wordpress-database-sync-with-grunt
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
sshexec: { | |
dump_remote_db: { | |
options: { | |
host: '<%= mysql.remote.host %>', | |
username: '<%= mysql.remote.username %>', | |
agent: process.env.SSH_AUTH_SOCK | |
}, | |
command: [ | |
'cd <%= mysql.remote.save_path %>', | |
'mysqldump <%= mysql.remote.dbname %> -u <%= mysql.remote.dbuser %> -p<%= mysql.remote.dbpass %> > remote-<%= timestamp %>.sql' | |
].join(' && ') | |
}, | |
cleanup_remote: { | |
options: { | |
host: '<%= mysql.remote.host %>', | |
username: '<%= mysql.remote.username %>', | |
agent: process.env.SSH_AUTH_SOCK | |
}, | |
command: [ | |
'cd <%= mysql.remote.save_path %>', | |
'rm remote-<%= timestamp %>.sql' | |
].join(' && ') | |
} | |
}, | |
exec: { | |
wget_remote_dump: { | |
command: 'wget -nv <%= mysql.remote.save_url %>/remote-<%= timestamp %>.sql' | |
}, | |
import_migrated_remote_dump: { | |
command: 'mysql -u <%= mysql.local.dbuser %> -p<%= mysql.local.dbpass %> <%= mysql.local.dbname %> < remote_migrated-<%= timestamp %>.sql' | |
}, | |
cleanup_local: { | |
command: 'rm -rf remote-<%= timestamp %>.sql remote_migrated-<%= timestamp %>.sql' | |
} | |
}, | |
peach: { | |
search_replace_remote_dump: { | |
options: { | |
force: true | |
}, | |
src: 'remote-<%= timestamp %>.sql', | |
dest: 'remote_migrated-<%= timestamp %>.sql', | |
from: '<%= mysql.remote.site_url %>', | |
to: '<%= mysql.local.site_url %>' | |
}, | |
} |
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
mysql: grunt.file.readJSON('mysql.json'), | |
timestamp: grunt.template.today('mm-dd-yyyy_HH-MM-ss') |
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
grunt.registerTask('sync_local_db', [ | |
'sshexec:dump_remote_db', //dump remote database | |
'exec:wget_remote_dump', //download remote dump | |
'sshexec:cleanup_remote', //delete remote dump | |
'peach:search_replace_remote_dump', //search and replace URLs in database | |
'exec:import_migrated_remote_dump', //import the migrated database | |
'exec:cleanup_local' //delete local database dump files | |
]); |
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
{ | |
"remote": { | |
"site_url": "http://example.com", | |
"dbname": "example_db", | |
"dbuser": "example_user", | |
"dbpass": "password", | |
"dbhost": "localhost", | |
"host": "ssh_example.com", | |
"username": "ssh_user", | |
"save_path": "/home5/ssh_user/public_html/example.com", | |
"save_url": "http://example.com" | |
}, | |
"local": { | |
"site_url": "http://example.dev", | |
"dbname": "example_local", | |
"dbuser": "local_dbuser", | |
"dbpass": "password", | |
"dbhost": "localhost" | |
} | |
} |
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
$ npm install grunt-exec grunt-peach grunt-ssh --save-dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment