1
0
Fork 0
mirror of synced 2024-09-04 03:42:32 +12:00
appwrite/app/tasks/volume-sync.php

46 lines
1.5 KiB
PHP
Raw Normal View History

2022-11-03 03:56:03 +13:00
<?php
global $cli;
use Utopia\CLI\Console;
use Utopia\Database\DateTime;
use Utopia\Validator\Integer;
use Utopia\Validator\Text;
$cli
->task('volume-sync')
2022-11-03 03:56:03 +13:00
->desc('Runs rsync to sync certificates between the storage mount and traefik.')
->param('source', null, new Text(255), 'Source path to sync from.', false)
->param('destination', null, new Text(255), 'Destination path to sync to.', false)
->param('interval', null, new Integer(true), 'Interval to run rsync', false)
->action(function ($source, $destination, $interval) {
Console::title('RSync V1');
Console::success(APP_NAME . ' rsync process v1 has started');
2022-11-08 00:47:51 +13:00
if (!file_exists($source)) {
Console::error('Source directory does not exist. Exiting ... ');
2022-11-08 01:06:42 +13:00
Console::exit(0);
2022-11-08 00:47:51 +13:00
}
2022-11-03 03:56:03 +13:00
Console::loop(function () use ($interval, $source, $destination) {
$time = DateTime::now();
Console::info("[{$time}] Executing rsync every {$interval} seconds");
Console::info("Syncing between $source and $destination");
if (!file_exists($source)) {
Console::error('Source directory does not exist. Skipping ... ');
return;
}
$stdin = "";
$stdout = "";
$stderr = "";
Console::execute("rsync -av $source $destination", $stdin, $stdout, $stderr);
Console::success($stdout);
Console::error($stderr);
}, $interval);
});