-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpm-migrate.js
45 lines (40 loc) · 1.97 KB
/
wpm-migrate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const modules = require('./lib/modules');
const config = modules.config;
eval(`migrate_${process.argv[2].trim()}()`);
modules.spawn(`echo "[client]
user=${config.mysql.local.username}
password=${config.mysql.local.password}
host=${config.mysql.local.host}" > ~/.my.cnf && chmod 0600 ~/.my.cnf`)
async function migrate_files() {
await modules.spawn(`rsync -avz ${config.local} ${config.user}@${config.host}:${config.remote};`)
modules.ssh
.exec(`cd ${config.remote} && sed -i 's/${config.mysql.local.username}/${config.mysql.remote.username}/g' wp-config.php`, {
out: console.log.bind(console)
})
.exec(`cd ${config.remote} && sed -i 's/${config.mysql.local.password}/${config.mysql.remote.password}/g' wp-config.php`, {
out: console.log.bind(console)
})
.exec(`cd ${config.remote} && sed -i 's/${config.mysql.local.host}/${config.mysql.remote.host}/g' wp-config.php`, {
out: console.log.bind(console)
})
.start();
modules.reset(`Files migrated!`);
}
async function migrate_db() {
await modules.spawn(`mysqldump --defaults-extra-file='~/.my.cnf' -h ${config.mysql.local.host} -u ${config.mysql.local.username} --databases ${config.mysql.local.database} > ${config.mysql.local.database}.sql;`)
modules.ssh
.exec(`echo "[client]
user=${config.mysql.remote.username}
password=${config.mysql.remote.password}
host=${config.mysql.remote.host}" > ~/.my.cnf && chmod 0600 ~/.my.cnf`, {
out: console.log.bind(console)
})
.exec(`rsync -a ${process.cwd()}/${config.mysql.local.database}.sql ${config.user}@${config.host}:~/${config.mysql.remote.database}.sql;`, {
out: console.log.bind(console)
})
.exec(`mysql --defaults-extra-file='~/.my.cnf' -h ${config.mysql.remote.host} -u ${config.mysql.remote.username} --max_allowed_packet=2147483648 ${config.mysql.remote.database} < ~/${config.mysql.remote.database}.sql;`, {
out: console.log.bind(console)
})
.start();
modules.reset(`DB migrated!`);
}