From a7c6674a83b7264e5827667ff47a4c98745ea31f Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 6 Sep 2023 17:15:07 +0300 Subject: [PATCH] Upload attempts --- src/Appwrite/Platform/Tasks/Backup.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Backup.php b/src/Appwrite/Platform/Tasks/Backup.php index 18f3c87644..dd44691f05 100644 --- a/src/Appwrite/Platform/Tasks/Backup.php +++ b/src/Appwrite/Platform/Tasks/Backup.php @@ -16,12 +16,12 @@ use Utopia\Validator\Text; class Backup extends Action { public const BACKUPS_PATH = '/backups'; - public const BACKUP_INTERVAL_SECONDS = 60 * 60 * 4; // 4 hours; - //public const BACKUP_INTERVAL_SECONDS = 100; + //public const BACKUP_INTERVAL_SECONDS = 60 * 60 * 4; // 4 hours; + public const BACKUP_INTERVAL_SECONDS = 100; public const COMPRESS_ALGORITHM = 'zstd'; // https://www.percona.com/blog/get-your-backup-to-half-of-its-size-introducing-zstd-support-in-percona-xtrabackup/ public const CLEANUP_LOCAL_FILES_SECONDS = 60 * 60 * 24 * 1; // 2 days? public const CLEANUP_CLOUD_FILES_SECONDS = 60 * 60 * 24 * 1; // 14 days?; - public const UPLOAD_CHUNK_SIZE = 20 * 1024 * 1024; // Must be greater than 5MB; + public const UPLOAD_CHUNK_SIZE = 5 * 1024 * 1024; // Must be greater than 5MB; protected string $filename; protected ?DSN $dsn = null; protected ?string $database = null; @@ -113,7 +113,7 @@ class Backup extends Action $local = new Local(self::BACKUPS_PATH . '/' . $this->database . '/full'); $local->setTransferChunkSize(self::UPLOAD_CHUNK_SIZE); - //$this->fullBackup($local); + $this->fullBackup($local); $max = 1; $i = 0; @@ -121,11 +121,10 @@ class Backup extends Action $i++; try { $this->upload($local); - break; // exit while + break; } catch (Exception $e) { if ($i <= $max) { Console::warning($e->getMessage() . ' (' . $i . ' attempt)'); - sleep(1); } else { throw new Exception($e->getMessage()); } @@ -286,14 +285,13 @@ class Backup extends Action return false; } - $now = new \DateTime(); [$year, $month, $day, $hour, $minute, $second] = explode('_', $item); $date = $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second; try { + $now = new \DateTime(); $backupDate = new \DateTime($date); - $difference = $now->getTimestamp() - $backupDate->getTimestamp(); - if ($difference > $seconds) { + if (($now->getTimestamp() - $backupDate->getTimestamp()) > $seconds) { return true; } } catch (Exception $e) {