From 3515a98e551b2d8ce423bc1689d71f34aebcd875 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 14 Dec 2021 20:08:44 -0700 Subject: [PATCH] Add Cloud Backups, a command to store backups on S3 or compatible filesystems --- app/Console/Commands/BackupToCloud.php | 76 ++++++++++++++++++++++++++ config/filesystems.php | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/BackupToCloud.php diff --git a/app/Console/Commands/BackupToCloud.php b/app/Console/Commands/BackupToCloud.php new file mode 100644 index 000000000..815e23ac3 --- /dev/null +++ b/app/Console/Commands/BackupToCloud.php @@ -0,0 +1,76 @@ +error('Backup disk not configured.'); + $this->error('See https://docs.pixelfed.org/technical-documentation/env.html#filesystem for more information.'); + return Command::FAILURE; + } + + $newest = $backupDestination->newestBackup(); + $name = $newest->path(); + $parts = explode('/', $name); + $fileName = array_pop($parts); + $storagePath = 'backups'; + $path = storage_path('app/'. $name); + $file = $cloudDisk->putFileAs($storagePath, new File($path), $fileName, 'private'); + $this->info("Backup file successfully saved!"); + $url = $cloudDisk->url($file); + $this->table( + ['Name', 'URL'], + [ + [$fileName, $url] + ], + ); + return Command::SUCCESS; + } +} diff --git a/config/filesystems.php b/config/filesystems.php index 0df7cf308..a43e5b470 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -82,7 +82,7 @@ return [ ], 'backup' => [ - 'driver' => env('PF_BACKUP_DRIVER', 'local'), + 'driver' => env('PF_BACKUP_DRIVER', 's3'), 'visibility' => 'private', 'root' => env('PF_BACKUP_DRIVER', 'local') == 'local' ? storage_path('app/backups/') :