diff --git a/.env b/.env index 228b7f39d4..5a96c3c45f 100644 --- a/.env +++ b/.env @@ -32,7 +32,7 @@ _APP_CONNECTIONS_DB_CONSOLE=db_fra1_01=mariadb://user:password@mariadb:3306/appw _APP_CONNECTIONS_CACHE=redis_fra1_01=redis://redis:6379 _APP_CONNECTIONS_QUEUE=redis_fra1_01=redis://redis:6379 _APP_CONNECTIONS_PUBSUB=redis_fra1_01=redis://redis:6379 -_APP_CONNECTIONS_STORAGE=local://localhost +_APP_CONNECTIONS_STORAGE=DOSpaces://JFFSCKTIMLOG2GBVA2IA:oPNeHob8TXVYtq68gQ0DiIbp9qPTJRRAO2LL4qDzTYI@null:0/utopia-storage-tests?region=nyc3 _APP_STORAGE_ANTIVIRUS=disabled _APP_STORAGE_ANTIVIRUS_HOST=clamav _APP_STORAGE_ANTIVIRUS_PORT=3310 diff --git a/Dockerfile b/Dockerfile index 12a7ae5c19..df77b6976f 100755 --- a/Dockerfile +++ b/Dockerfile @@ -132,7 +132,8 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/worker-mails && \ chmod +x /usr/local/bin/worker-messaging && \ chmod +x /usr/local/bin/worker-webhooks && \ - chmod +x /usr/local/bin/worker-usage + chmod +x /usr/local/bin/worker-usage && \ + chmod +x /usr/local/bin/folder-backup # Letsencrypt Permissions RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ diff --git a/bin/folder-backup b/bin/folder-backup new file mode 100644 index 0000000000..372b6a1139 --- /dev/null +++ b/bin/folder-backup @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php folder-backup $@ \ No newline at end of file diff --git a/composer.json b/composer.json index 5ea57253c5..b2efb80ee1 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,7 @@ "utopia-php/logger": "0.3.*", "utopia-php/messaging": "0.1.*", "utopia-php/registry": "0.5.*", - "utopia-php/storage": "0.13.*", + "utopia-php/storage": "dev-feat-transfer as 0.13.2", "utopia-php/swoole": "0.5.*", "utopia-php/websocket": "0.1.*", "resque/php-resque": "1.3.6", diff --git a/docker-compose.yml b/docker-compose.yml index f137187c55..7462ea5b56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -581,6 +581,23 @@ services: - _APP_MAINTENANCE_RETENTION_AUDIT - _APP_MAINTENANCE_RETENTION_SCHEDULES + appwrite-folder-backup: + entrypoint: folder-backup + <<: *x-logging + container_name: appwrite-folder-backup + image: appwrite-dev + networks: + - appwrite + volumes: + - ./app:/usr/src/code/app + - ./src:/usr/src/code/src + - appwrite-certificates:/storage/certificates:rw + - ./vendor/utopia-php/cli:/usr/src/code/vendor/utopia-php/cli + environment: + - _APP_ENV + - _APP_MAINTENANCE_INTERVAL + - _APP_CONNECTIONS_STORAGE + appwrite-worker-usage: entrypoint: worker-usage <<: *x-logging diff --git a/src/Appwrite/Platform/Services/Tasks.php b/src/Appwrite/Platform/Services/Tasks.php index 635722452e..ddf4caf335 100644 --- a/src/Appwrite/Platform/Services/Tasks.php +++ b/src/Appwrite/Platform/Services/Tasks.php @@ -15,6 +15,7 @@ use Appwrite\Platform\Tasks\SSL; use Appwrite\Platform\Tasks\Vars; use Appwrite\Platform\Tasks\Version; use Appwrite\Platform\Tasks\VolumeSync; +use Appwrite\Platform\Tasks\FolderBackup; class Tasks extends Service { @@ -33,6 +34,7 @@ class Tasks extends Service ->addAction(Migrate::getName(), new Migrate()) ->addAction(SDKs::getName(), new SDKs()) ->addAction(VolumeSync::getName(), new VolumeSync()) - ->addAction(Specs::getName(), new Specs()); + ->addAction(Specs::getName(), new Specs()) + ->addAction(FolderBackup::getName(), new FolderBackup()); } } diff --git a/src/Appwrite/Platform/Tasks/FolderBackup.php b/src/Appwrite/Platform/Tasks/FolderBackup.php new file mode 100644 index 0000000000..1aec95b35f --- /dev/null +++ b/src/Appwrite/Platform/Tasks/FolderBackup.php @@ -0,0 +1,77 @@ +desc('Folder backup and restore process') + ->callback(fn () => $this->action()); + } + + public function action(): void + { + Console::title('Folder backup V1'); + Console::success(APP_NAME . ' folder backup process v1 has started'); + + $interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400'); + Console::loop(function () use ($interval) { + $folders = [ + 'cert' => APP_STORAGE_CERTIFICATES, + ]; + + foreach ($folders as $key => $folder) { + $root = new Local($folder); + $filename = $key . '-' . date("Y-m-d") . '.tar.gz'; + $source = $root->getRoot() . '/' . $filename; + $destination = '/' . $key . '/' . $filename; + $content = $root->getRoot() . '/*'; + +// for ($i = 0; $i < 1000; $i++) { +// file_put_contents($root->getRoot() . '/' . $i . '.txt', ''); +// } + + $stdout = ''; + $stderr = ''; + Console::execute( + 'tar --exclude ' . $filename . ' -zcf ' . $source . ' ' . $content, + '', + $stdout, + $stderr + ); + + try { + $connection = App::getEnv('_APP_CONNECTIONS_STORAGE', ''); + $dsn = new DSN($connection); + $remote = new DOSpaces( + '/', + $dsn->getUser(), + $dsn->getPassword(), + $dsn->getPath(), + $dsn->getParam('region') + ); + $result = $root->transfer($source, $destination, $remote); + var_dump($result); + Console::log('done'); + } catch (\Exception $e) { + Console::error($e->getMessage()); + } + } + }, $interval); + } +}