This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-files.php
77 lines (68 loc) · 1.74 KB
/
backup-files.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
77
<?php
// the configuration file
require "backup-files.cfg.php";
// check the security keys
if($_GET['KEY_GET1'] != KEY_GET1 || $_GET['KEY_GET2'] != KEY_GET2){
die;
}
// set errors & time limit
error_reporting(E_ALL);
set_time_limit(240);
/* *****************************************
The File Backup
***************************************** */
echo "START FILE BACKUP \n ";
class Utils
{
public static function listDirectory($dir)
{
$result = array();
$root = scandir($dir);
foreach($root as $value) {
if($value === '.' || $value === '..') {
continue;
}
if(is_file("$dir$value")) {
$result[] = "$dir$value";
continue;
}
if(is_dir("$dir$value")) {
$result[] = "$dir$value/";
}
foreach(self::listDirectory("$dir$value/") as $value)
{
$result[] = $value;
}
}
return $result;
}
}
foreach($BACKUPDIRS as $backupInfo){
// $backupInfo[0]; // the Name
// $backupInfo[1]; // the Directory
$source_dir = $backupInfo[1];
$zip_file = $backupInfo[0].'.zip';
$file_list = Utils::listDirectory($source_dir);
$zip = new ZipArchive();
if ($zip->open($zip_file, ZIPARCHIVE::CREATE) === true) {
foreach ($file_list as $file) {
if ($file !== $zip_file) {
$zip->addFile($file, substr($file, strlen($source_dir)));
}
}
$zip->close();
}
if(METHOD == "ftp"){
// upload the .zip to ftp
require_once "classes/ftp-upload.php";
ftpSend($backupInfo[0].'.zip');
}elseif(METHOD == "ftps"){
// upload the .zip to ftp
require_once "classes/ftp-upload.php";
ftpSend($backupInfo[0].'.zip', true);
}elseif(METHOD == "email"){
// send the .zip file via mail
require_once "classes/email-send.php";
emailSend($backupInfo[0].'.zip');
}
}