-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanting_backup.php
62 lines (52 loc) · 1.6 KB
/
planting_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
54
55
56
57
58
59
60
61
62
<?php
/**
* Backup FTP Daemon
*
* @category Daemons
* @package Automated Planting 1.0
* @author Marcin Polak <mapoart@gmail.com>
* @license http://MarcinPolak.eu
* @version Release: 1.0
* @link http://MarcinPolak.eu/AutomatedPlanting
*/
require_once "bootstrap.php";
use Mapos\Daemon\Daemon;
use Mapos\Ftp\Ftp;
$daemon = new Daemon("plantbackup");
$daemon->setDelay(1200); //20 minutes
$daemon->start();
$ftp = new Ftp();
$ftp->setHost(FTP_HOST);
$ftp->setPort(FTP_PORT);
$ftp->setLogin(FTP_USERNAME);
$ftp->setPassword(FTP_PASSWORD);
$counter = 0;
$copied = 0;
while (1) {
$daemon->info("run " . $counter++ . "x");
$ftp->setHost(FTP_HOST);
$ftp->setPort(FTP_PORT);
$ftp->setLogin(FTP_USERNAME);
$ftp->setPassword(FTP_PASSWORD);
if (!$ftp->connect()) {
echo "can't connect";
} else {
if (is_dir(FTP_BACKUP_FOLDER)) {
$openDir = opendir(FTP_BACKUP_FOLDER);
while ($file = readdir($openDir)) {
if ($file != "." && $file != ".." && $file != "thumb") {
$daemon->info("Copying file: " . $file);
if ($ftp->upload(FTP_BACKUP_FOLDER . $file, $file)) {
$daemon->info("done");
unlink(FTP_BACKUP_FOLDER . $file);
$copied++;
$daemon->info("Copied " . $copied . " files so far.");
} else {
$daemon->info(" ! Failed copy file '" . FTP_BACKUP_FOLDER . $file . "'");
}
}
}
}
}
$daemon->delay();
}