-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup.php
45 lines (38 loc) · 1.1 KB
/
backup.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
<!DOCTYPE html>
<html lang="de">
<body>
<?php
date_default_timezone_set('CET');
// Get real path for our folder
$rootPath = realpath('../s1ck');
// Initialize archive object
$zip = new ZipArchive();
$zip->open('backup/Backup '.date("r").'.zip', 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();
if($zip->close()){
echo "Backup succesfull!";
} else {
echo "Backup failed";
}
?>
</body>
</html>