-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
61 lines (45 loc) · 1.54 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require __DIR__ . '/vendor/autoload.php';
use Spatie\DbDumper\Databases\MySql;
class DatabaseBackup
{
protected $host, $username, $password, $database, $email;
function __construct($host, $username, $password, $database, $email)
{
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->email = $email;
$this->initMySQLDBBackup();
$this->sendEmail();
}
public function initMySQLDBBackup()
{
$file_name = $this->database . '_' . date('Y_m_d', time()) . '.sql';
MySql::create()
->setDbName($this->database)
->setUserName($this->username)
->setPassword($this->password)
->dumpToFile($file_name);
}
public function sendEmail()
{
$transport = (new Swift_SmtpTransport('smtp.example.org', 25))
->setUsername('your username')
->setPassword('your password');
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message())
->setSubject('Database Backup Notification')
->setFrom(['support@yourdomain.com' => 'Support'])
->setTo([$this->email])
->setBody('Database Backup executed successfully!');;
return $mailer->send($message);
}
}
$host = 'localhost';
$username = 'USERNAME';
$password = 'PASSWORD';
$database = 'DATABASE_NAME';
$email = 'YOUR_EMAIL_ADDRESS';
(new DatabaseBackup($host, $username, $password, $database, $email));