mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
folder backup
This commit is contained in:
+1
-1
Submodule app/console updated: 5e2a40c1e3...39727607a0
@@ -20,41 +20,39 @@ class Backup extends Action
|
||||
->callback(fn() => $this->action());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function action(): void
|
||||
{
|
||||
Console::title('Backup V1');
|
||||
Console::success(APP_NAME . ' backup process v1 has started');
|
||||
|
||||
gc_enable();
|
||||
$time = 0;
|
||||
while (!connection_aborted() || PHP_SAPI == "cli") {
|
||||
$now = new \DateTime();
|
||||
$now->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
$next = new \DateTime($now->format("Y-m-d 16:0.0"));
|
||||
$next->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
$sleep = $next->getTimestamp() - $now->getTimestamp();
|
||||
$now = new \DateTime();
|
||||
$now->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
$next = new \DateTime($now->format("Y-m-d 17:25.0"));
|
||||
$next->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
$delay = $next->getTimestamp() - $now->getTimestamp();
|
||||
|
||||
/**
|
||||
* If time passed the target time
|
||||
*/
|
||||
if ($sleep <= 0) {
|
||||
$next->add(\DateInterval::createFromDateString('1 days'));
|
||||
$sleep = $next->getTimestamp() - $now->getTimestamp();
|
||||
}
|
||||
/**
|
||||
* If time passed for the target day.
|
||||
*/
|
||||
if ($delay <= 0) {
|
||||
$next->add(\DateInterval::createFromDateString('1 days'));
|
||||
$delay = $next->getTimestamp() - $now->getTimestamp();
|
||||
}
|
||||
|
||||
Console::log('[' . $now->format("Y-m-d H:i:s.v") . '] Sleeping for ' . $sleep . ' seconds next run will be at [' . $next->format("Y-m-d H:i:s.v") . ']');
|
||||
$folders = [
|
||||
'cert' => APP_STORAGE_CERTIFICATES,
|
||||
'config' => APP_STORAGE_CONFIG,
|
||||
];
|
||||
|
||||
sleep($sleep);
|
||||
$sleep = 86400; //24 hours
|
||||
$sleep = 60;
|
||||
$remote = getDevice('/');
|
||||
|
||||
$total = 0;
|
||||
$start = \microtime(true);
|
||||
|
||||
$folders = [
|
||||
'cert' => APP_STORAGE_CERTIFICATES,
|
||||
'config' => APP_STORAGE_CONFIG,
|
||||
];
|
||||
|
||||
$remote = getDevice('/');
|
||||
Console::log('[' . $now->format("Y-m-d H:i:s.v") . '] Delaying for ' . $delay . ' setting loop to [' . $next->format("Y-m-d H:i:s.v") . ']');
|
||||
Console::loop(function () use ($delay, $sleep, $folders, $remote) {
|
||||
|
||||
foreach ($folders as $key => $folder) {
|
||||
$local = new Local($folder);
|
||||
@@ -62,19 +60,20 @@ class Backup extends Action
|
||||
$source = $local->getRoot() . '/' . $filename;
|
||||
$destination = '/' . $key . '/' . $filename;
|
||||
|
||||
for ($i = 0; $i < 1000; $i++) {
|
||||
file_put_contents($local->getRoot() . '/' . $i . '.txt', '');
|
||||
}
|
||||
// for ($i = 0; $i < 1000; $i++) {
|
||||
// file_put_contents($local->getRoot() . '/' . $i . '.txt', '');
|
||||
// }
|
||||
|
||||
$stdout = '';
|
||||
$stderr = '';
|
||||
|
||||
Console::execute(
|
||||
'cd ' . $folder . ' && tar --exclude ' . $filename . ' -zcf ' . $source . ' *',
|
||||
'',
|
||||
$stdout,
|
||||
$stderr
|
||||
);
|
||||
var_dump($local->exists($source));
|
||||
|
||||
try {
|
||||
if (!$local->exists($source)) {
|
||||
continue;
|
||||
@@ -84,7 +83,7 @@ class Backup extends Action
|
||||
Console::info("Backing up local $source to {$remote->getName()} $destination");
|
||||
|
||||
/**
|
||||
* Remote storage old backup files clean-up
|
||||
* Backup folder, long tail cleanup.
|
||||
*/
|
||||
$now = new \DateTime();
|
||||
$now->setTimezone(new \DateTimeZone(date_default_timezone_get()));
|
||||
@@ -99,15 +98,7 @@ class Backup extends Action
|
||||
} catch (\Exception $e) {
|
||||
Console::error($e->getMessage());
|
||||
}
|
||||
|
||||
if (PHP_SAPI == "cli") {
|
||||
if ($time >= 60 * 5) {
|
||||
$time = 0;
|
||||
gc_collect_cycles();
|
||||
}
|
||||
}
|
||||
}
|
||||
$total = (microtime(true) - $start);
|
||||
}
|
||||
}, $sleep, $delay);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user