This commit is contained in:
Bozhidar 2024-05-10 17:13:25 +03:00
parent e82d70fb3a
commit aef89cc325
2 changed files with 14 additions and 6 deletions

View file

@ -10,13 +10,14 @@ class HostingSubscriptionBackupLog extends Component
public $backupLog; public $backupLog;
public $backupLogFile = '';
public function pullBackupLog() public function pullBackupLog()
{ {
$findHsb = \App\Models\HostingSubscriptionBackup::where('id', $this->hostingSubscriptionBackupId)->first(); if ($this->backupLogFile) {
if ($findHsb) { if (file_exists($this->backupLogFile)) {
$backupLog = $findHsb->path . '/backup.log';
if (file_exists($backupLog)) { $backupLogContent = shell_exec('tail -n 1000 ' . $this->backupLogFile);
$backupLogContent = file_get_contents($backupLog);
// Get last 1000 lines of the log // Get last 1000 lines of the log
$backupLogContent = substr($backupLogContent, -5000, 5000); $backupLogContent = substr($backupLogContent, -5000, 5000);
$backupLogContent = str_replace("\n", "<br>", $backupLogContent); $backupLogContent = str_replace("\n", "<br>", $backupLogContent);
@ -25,9 +26,16 @@ class HostingSubscriptionBackupLog extends Component
} }
} }
} }
public function mount($hostingSubscriptionBackupId) public function mount($hostingSubscriptionBackupId)
{ {
$this->hostingSubscriptionBackupId = $hostingSubscriptionBackupId; $this->hostingSubscriptionBackupId = $hostingSubscriptionBackupId;
$findHsb = \App\Models\HostingSubscriptionBackup::where('id', $this->hostingSubscriptionBackupId)->first();
if ($findHsb) {
$this->backupLogFile = $findHsb->path . '/backup.log';
$this->pullBackupLog();
}
} }
public function render() public function render()

View file

@ -227,7 +227,7 @@ class HostingSubscriptionBackup extends Model
} }
// With find, we can search for all files,directories (including hidden) in the current directory and zip them // With find, we can search for all files,directories (including hidden) in the current directory and zip them
$shellFileContent .= 'cd '.$backupTempPath .' && find . -exec zip -r '.$backupFilePath.' {} \;'. PHP_EOL; $shellFileContent .= 'cd '.$backupTempPath .' && find . -exec zip --symlinks -r '.$backupFilePath.' {} \;'. PHP_EOL;
$shellFileContent .= 'rm -rf '.$backupTempPath.PHP_EOL; $shellFileContent .= 'rm -rf '.$backupTempPath.PHP_EOL;
$shellFileContent .= 'echo "Backup complete"' . PHP_EOL; $shellFileContent .= 'echo "Backup complete"' . PHP_EOL;