|
| 1 | +<?php |
| 2 | +require_once 'vendor/autoload.php'; |
| 3 | +if (isset($_POST['backup'])) { |
| 4 | + $filename = 'backup_' . date('G_a_m_d_y_h_i_s') . ".sql"; |
| 5 | + $directory = $_POST['destination'] ?? ''; |
| 6 | + $destinationPath = $directory . DIRECTORY_SEPARATOR . $filename; |
| 7 | + $options = [ |
| 8 | + 'host' => $_POST['host'], |
| 9 | + 'port' => $_POST['port'], |
| 10 | + 'dbName' => $_POST['dbname'], |
| 11 | + 'username' => $_POST['username'], |
| 12 | + 'password' => $_POST['password'], |
| 13 | + 'destinationPath' => $destinationPath, // /path/to/backups/mysql/dump |
| 14 | + ]; |
| 15 | + try { |
| 16 | + $dumper = new \CodexShaper\Dumper\Drivers\MysqlDumper($options); |
| 17 | + $dumper->dump(); |
| 18 | + header('Location: index.php?backup=success&message=Database backedup successfully'); |
| 19 | + } catch (Exception $ex) { |
| 20 | + header('Location: index.php?backup=fail&message=' . $ex->getMessage()); |
| 21 | + } |
| 22 | +} |
| 23 | +?> |
| 24 | +<!DOCTYPE html> |
| 25 | +<html> |
| 26 | +<head> |
| 27 | + <title>Database Backup and Restore</title> |
| 28 | + <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> |
| 29 | +</head> |
| 30 | +<body> |
| 31 | + <div class="container"> |
| 32 | + <div class="card mt-5 mx-auto" style="width: 50rem;"> |
| 33 | + <div class="card-body"> |
| 34 | + <h3 class="card-title">Welcome to Database backup and restore</h3> |
| 35 | + <a href="index.php" class="btn btn-info">Home</a> |
| 36 | + <form method="POST" action="backup.php"> |
| 37 | + <div class="form-group"> |
| 38 | + <label for="host">Host</label> |
| 39 | + <input type="text" name="host" id="host" class="form-control" value="localhost"> |
| 40 | + </div> |
| 41 | + <div class="form-group"> |
| 42 | + <label for="port">Port</label> |
| 43 | + <input type="text" name="port" id="port" class="form-control" value="3306"> |
| 44 | + </div> |
| 45 | + <div class="form-group"> |
| 46 | + <label for="dbname">Database Name</label> |
| 47 | + <input type="text" name="dbname" id="dbname" class="form-control" value="laravel"> |
| 48 | + </div> |
| 49 | + <div class="form-group"> |
| 50 | + <label for="username">User Name</label> |
| 51 | + <input type="text" name="username" id="username" class="form-control" value="root"> |
| 52 | + </div> |
| 53 | + <div class="form-group"> |
| 54 | + <label for="password">Password</label> |
| 55 | + <input type="password" id="password" name="password" class="form-control"> |
| 56 | + </div> |
| 57 | + <div class="form-group"> |
| 58 | + <label for="destination">Destination path</label> |
| 59 | + <input type="text" name="destination" id="destination" class="form-control"> |
| 60 | + </div> |
| 61 | + <div class="form-group"> |
| 62 | + <input type="submit" name="backup" value="Backup" class="btn btn-success"> |
| 63 | + </div> |
| 64 | + </form> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | +<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script> |
| 69 | +<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script> |
| 70 | +<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script> |
| 71 | +</body> |
| 72 | +</html> |
0 commit comments