GithubHelp home page GithubHelp logo

shuttle-export's Introduction

PHP based MySQL dump library

The library provides easy way to create MySQL dumps files. It will try to create dump through:

  1. mysqldump shell utility
  2. native PHP code

For native dumps(on hosts without shell access), it works with mysqli php extension by default, and fallbacks to old-fashioned mysql whenever mysqli isn't available.

The aim of the library is to work on as many web-hosts as possible: it requires PHP 5.2 and requires just one mysql or mysqli libraries to be available.

Features:

  • support for plain text and gzip output(whenever the dump file has .gz extension, a gzip archive will be produced)
  • support for including just particular tables from the database, excluding tables, and dumping just tables with particular prefix

ToDo:

  • add support for views and triggers
  • try how things work with databases with foreign keys constraints

Examples

Dump all tables in world database:

$world_dumper = Shuttle_Dumper::create(array(
    'host' => '',
    'username' => 'root',
    'password' => '',
    'db_name' => 'world',
));
// dump the database to plain text file
$world_dumper->dump('world.sql');

// send the output to gziped file:
$world_dumper->dump('world.sql.gz');

Dump only the tables with wp_ prefix:

$wp_dumper = Shuttle_Dumper::create(array(
    'host' => '',
    'username' => 'root',
    'password' => '',
    'db_name' => 'wordpress',
));
$wp_dumper->dump('wordpress.sql', 'wp_');

Dump only country and city tables:

$countries_dumper = Shuttle_Dumper::create(array(
    'host' => '',
    'username' => 'root',
    'password' => '',
    'db_name' => 'world',
    'include_tables' => array('country', 'city'),
));
$countries_dumper->dump('world.sql.gz');

Dump all tables except for city:

$world_dumper = Shuttle_Dumper::create(array(
    'host' => '',
    'username' => 'root',
    'password' => '',
    'db_name' => 'world',
    'exclude_tables' => array('city'),
));
$world_dumper->dump('world-no-cities.sql.gz');

shuttle-export's People

Contributors

cvipul avatar emohamed avatar tocreatedev avatar trevorprinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shuttle-export's Issues

"VIEWS" in the database cause errors while iterating through '$tables'

In line 228 of 'dumper.php'
$tables = $this->db->fetch_numeric(' SHOW TABLES LIKE "' . $this->db->escape_like($table_prefix) . '%" ');
$tables includes all the tables and the views of the database.

$tables when finally being used in the function "get_create_table_sql" (line 334), causes the subsequent SQL Query to have a very different output than expected. Hence
return $create_table_sql[0]['Create Table'] . ';'; throws an error.

To rectify this, line 228 should be edited to :
$tables = $this->db->fetch_numeric(' SHOW FULL TABLES WHERE Table_Type = "BASE TABLE" AND Tables_in_'.$this->db->name.' LIKE "' . $this->db->escape_like($table_prefix) . '%" ');
This is only return the tables and not views.

Alternatively, one can change the "get_create_table_sql" code to handle views also..

Error in W8.1 running xammp servr

Couldn't dump database: Couldn't export database: 'mysqldump' is not recognized as an internal or external command, o

perable program or batch file.

Special Characters Export

Hi there!

First: Awesome script. its really handy.

I have an issue regarding special characters. When I export, and then check the sql (and want to import), i see all questionmarks (?) for special characters.

Question: How can I export also the special characters? Thanks

Custom port

Is there any way to use custom ports, since some budget hosts have not localhost but something like 'remote_server_bla_bla:3313' ? Thanks in advance)

When tables names contain special characters, fetch_numeric fails

When tables names contain special characters ('-' in my case), the line 230 fails, you need to escape the name with `, the ligne should then be :

$tables = $this->db->fetch_numeric('SHOW FULL TABLES WHERE Table_Type = "BASE TABLE" AND Tables_in_'.$this->db->name.' LIKE "' . $this->db->escape_like($table_prefix) . '%"
');

Improvement if you run out of memory

Line 469:
From:
$res = $this->connection->query($q);
To:
$res = $this->connection->query($q, MYSQLI_USE_RESULT);

You will be able to store MUCH MUCH MUCH more before runing out of memory.

File name and export directory

Thanks a lot for the nice script. I'm using your script for hourly backups where I need to change the dump file name manually so the new dump file won't overwrite the old file.

I usually use the below command in cron jobs and I get file name with date and time.
/usr/bin/mysqldump -u username -ppassword database_name | gzip > /path/filename-date +\%Y-\%m-\%d-\%H.\%M.\%S.sql.gz

1- How can I get file name with date and time using your script?
2- How to choose the different export location instead of storing the dumped files in same directory as where is the script is?

Thank you very much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.