From 0d8fbb87c86d9aeb82c9e05fda5d109904fd4290 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 20 Aug 2023 19:01:35 +0300 Subject: [PATCH] Clean tmp dir --- src/Appwrite/Platform/Tasks/Backup.php | 4 +--- src/Appwrite/Platform/Tasks/Restore.php | 26 +++++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Backup.php b/src/Appwrite/Platform/Tasks/Backup.php index 86102223bf..a3cc06fed3 100644 --- a/src/Appwrite/Platform/Tasks/Backup.php +++ b/src/Appwrite/Platform/Tasks/Backup.php @@ -17,7 +17,7 @@ class Backup extends Action { public const BACKUPS_PATH = '/backups'; public const BACKUP_INTERVAL_SECONDS = 60 * 60 * 4; // 4 hours; - 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 COMPRESS_ALGORITHM = 'zstd'; // https://www.percona.com/blog/get-your-backup-to-half-of-its-size-introducing-zstd-support-in-percona-xtrabackup/ protected string $filename; protected ?DSN $dsn = null; protected ?string $database = null; @@ -90,8 +90,6 @@ class Backup extends Action $this->setContainerId(); $this->setProcessors(); - //sleep(20); - Console::loop(function () { $this->start(); }, self::BACKUP_INTERVAL_SECONDS); diff --git a/src/Appwrite/Platform/Tasks/Restore.php b/src/Appwrite/Platform/Tasks/Restore.php index f45060561c..35cbd93a3f 100644 --- a/src/Appwrite/Platform/Tasks/Restore.php +++ b/src/Appwrite/Platform/Tasks/Restore.php @@ -47,6 +47,7 @@ class Restore extends Action try { $dsn = new DSN(App::getEnv('_APP_CONNECTIONS_BACKUPS_STORAGE', '')); $this->s3 = new DOSpaces('/' . $database . '/full', $dsn->getUser(), $dsn->getPassword(), $dsn->getPath(), $dsn->getParam('region')); + $this->s3->setTransferChunkSize(20 * 1024 * 1024); // 5MB is the minimum } catch (\Exception $e) { Console::error($e->getMessage() . 'Invalid DSN.'); Console::exit(); @@ -109,20 +110,25 @@ class Restore extends Action public function download(string $file, Device $local) { + $filename = basename($file); + + $tmp = $local->getRoot() . '/tmp_' . $filename; + if (file_exists($tmp)) { // todo: this should be taken care of in the lib, cleanup previous iteration + Console::error('Deleting: ' . $tmp); + $local->delete($tmp, true); + } + $this->log('Download start'); - $filename = basename($file); + $path = $this->s3->getPath($filename); + if (!$this->s3->exists($path)) { + Console::error('File: ' . $path . ' does not exist on cloud'); + Console::exit(); + } + try { - $path = $this->s3->getPath($filename); - - if (!$this->s3->exists($path)) { - Console::error('File: ' . $path . ' does not exist on cloud'); - Console::exit(); - } - if (!$this->s3->transfer($path, $file, $local)) { - Console::error('Error Downloading ' . $file); - Console::exit(); + throw new Exception('Transfer failed ' . $file); } } catch (Exception $e) { Console::error($e->getMessage());