Created
July 26, 2016 08:41
-
-
Save oliverlundquist/b3e2ac8170870493c26334f7fdb01f47 to your computer and use it in GitHub Desktop.
Database Migrator
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
<?php | |
$host = 'chips_'; | |
$db_dump = 'test2.sql'; | |
$sql_dump = 'sqlite3.db'; | |
$ssh_host = ''; | |
$ssh_user = ''; | |
$ssh_pass = ''; | |
$db_host = ''; | |
$db_user = ''; | |
$db_pass = ''; | |
$db_name = ''; | |
$ssh = "sshpass -p $ssh_pass ssh $ssh_user@$ssh_host"; | |
// $ssh = "ssh -i $ssh_key $ssh_user@$ssh_host"; | |
// 1. get all tables for given host | |
$tables = str_replace(PHP_EOL, ' ', trim(`$ssh "MYSQL_PWD='$db_pass' mysql --host=$db_host --user=$db_user --database=$db_name --batch --silent --execute='SHOW TABLES LIKE \"${host}%\"'"`)); | |
// 2. make MySQL database dump | |
`$ssh "MYSQL_PWD=$db_pass mysqldump --host=$db_host --user=$db_user --no-data $db_name $tables" > $db_dump`; | |
// 3. convert to SQLite3 | |
`./mysql2sqlite $db_dump | sqlite3 $sql_dump`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment