[php] create dump by tables

 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
<?php
ini_set("memory_limit","-1");
set_time_limit(0);
error_reporting(E_ALL);
$DOCUMENT_ROOT = '/home/r/ru1cbit5/portal/public_html';
$DB_NAME = "ru1cbit4_test";
$DB_LOGIN = "ru1cbit4_test";
$DB_PASS = "i}q7GvBe";
$HOST = "5.101.152.33";
$link = mysqli_connect($HOST,$DB_LOGIN,$DB_PASS,$DB_NAME) or die("Error " . mysqli_error($link));
//consultation:
$query = "SHOW TABLES" or die("Error in the consult.." . mysqli_error($link));
//execute the query.
$result = $link->query($query);
//display information:
$dir = $DOCUMENT_ROOT . "/dumps/";
$c = 0;
while($row = mysqli_fetch_array($result)) {
//if($c==2) break;
$table = $row[0];
$sql = "mysqldump -u $DB_LOGIN -p$DB_PASS -h $HOST $DB_NAME $table > $dir" . "$table.sql";
exec($sql, $output);
echo $table . " created<br />";
$c++;
}