forked from YehudaEi/Telegram-Bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackupBot.php
76 lines (63 loc) · 1.97 KB
/
BackupBot.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
header('Content-Type: text/html; charset=utf-8');
date_default_timezone_set('Asia/Jerusalem');
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
define('CHANNEL_ID' "");
define('TOKEN' "");
function curlPost($method,$datas=[]==NULL){
$url = "https://api.telegram.org/bot".TOKEN."/".$method;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
curl_close($ch);
}else{
curl_close($ch);
return json_decode($res,true);
}
}
function compressFolder($path,$filename){
$rootPath = realpath($path);
// Initialize archive object
$zip = new ZipArchive();
$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
}
$date = date("d-m-y");
$time = date("h:i:s");
$folders = ["../public_html"];
for($i = 0; $i < count($folders); $i++){
$filename = "Domain name , ".$date." , ".$time.".zip";
compressFolder($folders[$i],$filename);
$postData = array(
'chat_id' => CHANNEL_ID,
'document' => new CURLFile(realpath($filename)),
'caption' => "The backup is send in date: ".date(DATE_RFC850),
);
echo curlPost("sendDocument",$postData);
unlink($filename);
}
?>