forked from oraoto/pib
-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathbackup.php
55 lines (42 loc) · 1.08 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
46
47
48
49
50
51
52
53
<?php // {"autorun":true, "persist":false, "single-expression": false, "render-as": "html"}
$stdErr = fopen('php://stderr', 'w');
set_error_handler(function(...$args) use($stdErr, &$errors){
fwrite($stdErr, print_r($args,1));
});
$docroot = '/persist';
$configroot = '/config';
$files = [];
$itA = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($docroot, FilesystemIterator::SKIP_DOTS));
$itB = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configroot, FilesystemIterator::SKIP_DOTS));
$zip = new \ZipArchive;
if($zip->open('/persist/backup.zip', ZipArchive::CREATE) === TRUE)
{
foreach ($itA as $name => $entry)
{
if(is_dir($name)) continue;
$files[] = $name;
}
foreach ($itB as $name => $entry)
{
if(is_dir($name)) continue;
$files[] = $name;
}
}
$i = $percent = 0;
foreach($files as $name)
{
if($name === '/persist/backup.zip')
{
continue;
++$i;
}
$zip->addFile($name);
$newPercent = (++$i / count($files));
if($newPercent - $percent >= 0.01)
{
print $newPercent . PHP_EOL;
$percent = $newPercent;
}
}
$zip->close();
exit;