-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.php
More file actions
46 lines (37 loc) · 1.19 KB
/
Copy pathbackup.php
File metadata and controls
46 lines (37 loc) · 1.19 KB
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
<?php
// Backup do site
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'ntiifceadmin';
$dbname = 'ordemservico';
// Seu e-mail aqui
$sendto = 'Willamys <willamys.araujo@ifce.edu.br>';
// O remetente. Pode ser backup@seusite.com
$sendfrom = 'Willamys <willamysaraujo7@gmail.com>';
// Assunto do e-mail
$sendsubject = 'Backup do site ' . date('d/m/Y');
// Corpo do e-mail
$bodyofemail = 'Backup diário do meu site';
$backupfile = 'Autobackup_' . date("Ymd") . '.sql';
$backupzip = $backupfile . '.tar.gz';
system("mysqldump -h $dbhost -u $dbuser -p$dbpass --lock-tables $dbname > $backupfile");
system("tar -czvf $backupzip $backupfile");
include('Mail.php');
include('Mail/mime.php');
$message = new Mail_mime();
$text = "$bodyofemail";
$message->setTXTBody($text);
$message->AddAttachment($backupzip);
$body = $message->get(array(
'head_charset' => 'utf-8',
'text_charset' => 'utf-8',
'html_charset' => 'utf-8'
));
$extraheaders = array("From"=>"$sendfrom", "Subject"=>"$sendsubject");
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send("$sendto", $headers, $body);
// Remover o arquivo do servidor (opcional)
unlink($backupzip);
unlink($backupfile);
?>