-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncer.php
More file actions
executable file
·51 lines (40 loc) · 1.25 KB
/
syncer.php
File metadata and controls
executable file
·51 lines (40 loc) · 1.25 KB
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
#!/usr/bin/env php
<?php
declare(strict_types=1);
include 'vendor/autoload.php';
try {
$config = new config('/etc/syncer/config.ini');
$config->checkGlobal();
$config->defaultsGlobal();
} catch (Exception $e) {
log::emergency($e->getMessage());
die(1);
}
try {
log::info(sprintf("Setting log level: %s", log::lvl2text((int)$config->getValue('global', 'log_level'))));
log::setLevel((int)$config->getValue('global', 'log_level'));
} catch (Exception $e) {
die($e->getMessage());
}
$syncer = new syncer($config);
// initial scan
$syncer->addNewFilesToDb();
$syncer->syncNewFiles(true);
// attach inotify watches
$syncer->attachInotifyWatches();
while(true) {
// scan new files if new inotify event occurs
$syncer->checkInotifyAndAddNewFiles();
// remove old files
$syncer->removeExpiredFiles();
// retry failed => if there are some
if($syncer->syncFailedFiles()) {
// copy new files to the temp dir
$syncer->enqueueNewFiles();
log::info("All new files enqueued -> going to sync");
// run rsync
$syncer->syncNewFiles();
}
log::info("Sleeping for " . $config->getValue('global', 'folder_check_period'));
sleep((int)$config->getValue('global', 'folder_check_period'));
}