Skip to content

Commit 9ab3004

Browse files
committed
Added Demo
1 parent 6fa1ff6 commit 9ab3004

File tree

7 files changed

+376
-0
lines changed

7 files changed

+376
-0
lines changed

demos/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

demos/backup.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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>

demos/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"codexshaper/database-backup-restore": "^1.1"
4+
}
5+
}

demos/composer.lock

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demos/index.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
require_once 'vendor/autoload.php';
3+
$successMsg = false;
4+
$errorMsg = false;
5+
$message = "";
6+
if (isset($_GET['backup']) && $_GET['backup'] == 'success') {
7+
$successMsg = true;
8+
$message = "Database backedup successfully";
9+
}
10+
if (isset($_GET['backup']) && $_GET['backup'] == 'fail') {
11+
$errorMsg = true;
12+
$message = "Database backedup failed";
13+
}
14+
if (isset($_GET['restore']) && $_GET['restore'] == 'success') {
15+
$successMsg = true;
16+
$message = "Database restored successfully";
17+
}
18+
if (isset($_GET['restore']) && $_GET['restore'] == 'fail') {
19+
$errorMsg = true;
20+
$message = "Database restored failed";
21+
}
22+
if (isset($_GET['message'])) {
23+
$message = $_GET['message'];
24+
}
25+
?>
26+
<!DOCTYPE html>
27+
<html>
28+
<head>
29+
<title>Backup lists</title>
30+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
31+
</head>
32+
<body>
33+
<div class="container">
34+
<div class="card mt-5 mx-auto">
35+
<div class="card-body">
36+
<div class="success">
37+
<?php if ($successMsg): ?>
38+
<p class="alert alert-success"><?php echo $message; ?></p>
39+
<?php endif;?>
40+
</div>
41+
<div class="error">
42+
<?php if ($errorMsg): ?>
43+
<p class="alert alert-danger"><?php echo $message; ?></p>
44+
<?php endif;?>
45+
</div>
46+
<a href="backup.php" class="btn btn-success my-3">Create a new backup</a>
47+
<a href="index.php" class="btn btn-info my-3">Reload</a>
48+
<?php $files = glob(__DIR__ . '/backups/*');?>
49+
<?php if (count($files)): ?>
50+
<table class="table table-bordered">
51+
<thead>
52+
<tr>
53+
<th scope="col">#</th>
54+
<th scope="col">Name</th>
55+
<th scope="col">Directory</th>
56+
<th scope="col">Actions</th>
57+
</tr>
58+
</thead>
59+
<tbody>
60+
<?php foreach ($files as $key => $file): ?>
61+
<?php $info = pathinfo($file);?>
62+
<tr>
63+
<th scope="row"><?php echo $key + 1 ?></th>
64+
<td><?php echo $info['basename'] ?></td>
65+
<td><?php echo $info['dirname'] ?></td>
66+
<td class="d-flex">
67+
<form action="restore.php" method="GET" class="inline-flex mr-2">
68+
<input type="hidden" name="restore_path" value="<?php echo $file ?>">
69+
<input type="submit" name="restore" class="btn btn-success" value="Restore">
70+
</form>
71+
<form action="remove.php" method="POST" class="inline-flex">
72+
<input type="hidden" name="restore_path" value="<?php echo $file ?>">
73+
<input type="submit" name="remove" class="btn btn-danger" value="Remove">
74+
</form>
75+
</td>
76+
</tr>
77+
<?php endforeach;?>
78+
</tbody>
79+
</table>
80+
<?php else: ?>
81+
<p class="alert alert-danger">There is no backup</p>
82+
<?php endif;?>
83+
</div>
84+
</div>
85+
</div>
86+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
87+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
88+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
89+
</body>
90+
</html>

demos/remove.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
if (isset($_POST['remove'])) {
4+
$file = $_POST['restore_path'] ?? "";
5+
try {
6+
if (file_exists($file)) {
7+
unlink($file);
8+
header('Location: index.php?backup=success&message=Backup removed successfully');
9+
} else {
10+
header('Location: index.php?backup=error&message=There is no file that you requested');
11+
}
12+
} catch (Exception $ex) {
13+
header('Location: index.php?backup=fail&message=' . $ex->getMessage());
14+
}
15+
}

demos/restore.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
$restore_path = "";
4+
if (isset($_GET['restore_path'])) {
5+
$restore_path = $_GET['restore_path'];
6+
}
7+
if (isset($_POST['restore'])) {
8+
$options = [
9+
'host' => $_POST['host'],
10+
'port' => $_POST['port'],
11+
'dbName' => $_POST['dbname'],
12+
'username' => $_POST['username'],
13+
'password' => $_POST['password'],
14+
'restorePath' => $_POST['restore_path'], // /path/to/restores/mysql/dump
15+
];
16+
try {
17+
$dumper = new \CodexShaper\Dumper\Drivers\MysqlDumper($options);
18+
$dumper->restore();
19+
header('Location: index.php?restore=success&message=Database restored successfully');
20+
} catch (Exception $ex) {
21+
header('Location: index.php?restore=fail&message=' . $ex->getMessage());
22+
}
23+
}
24+
?>
25+
<!DOCTYPE html>
26+
<html>
27+
<head>
28+
<title>Database restore and Restore</title>
29+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
30+
</head>
31+
<body>
32+
<div class="container">
33+
<div class="card mt-5 mx-auto" style="width: 50rem;">
34+
<div class="card-body">
35+
<h3 class="card-title">Welcome to Database restore and restore</h3>
36+
<form method="POST" action="restore.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="restore_path">Restore file</label>
59+
<input type="text" name="restore_path" id="restore_path" class="form-control" value="<?php echo $restore_path ?>">
60+
</div>
61+
<div class="form-group">
62+
<input type="submit" name="restore" value="Restore" class="btn btn-success">
63+
<a href="index.php" class="btn btn-info">Home</a>
64+
</div>
65+
</form>
66+
</div>
67+
</div>
68+
</div>
69+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
70+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
71+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
72+
</body>
73+
</html>

0 commit comments

Comments
 (0)