-
Notifications
You must be signed in to change notification settings - Fork 977
/
mysqlRestore.php
45 lines (36 loc) · 1.11 KB
/
mysqlRestore.php
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
<?php
//streamer config
$global['createDatabase'] = 1;
$doNotIncludeConfig = 1;
require_once __DIR__ . '/../videos/configuration.php';
if (php_sapi_name() !== 'cli') {
die('Command Line only');
}
ob_end_flush();
// Example usage
$globPattern = "{$global['systemRootPath']}videos/mysqldump-*.sql";
echo "Searching [{$globPattern}]" . PHP_EOL;
$glob = glob($globPattern);
foreach ($glob as $key => $file) {
echo "($key) {$file} " . humanFileSize(filesize($file)) . PHP_EOL;
}
// Select the file to restore
if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == '-1') {
$filename = end($glob);
} else {
echo "Type the number of the file you want to restore, or press Enter to restore the latest file" . PHP_EOL;
$option = trim(readline());
if ($option === '') {
$filename = end($glob);
} else {
$option = intval($option);
$filename = $glob[$option];
}
}
// Restore the selected file
if (restoreMySQLBackup($filename)) {
echo "Database restored successfully from {$filename}" . PHP_EOL;
} else {
echo "Failed to restore the database from {$filename}" . PHP_EOL;
}
?>