Skip to content

Commit

Permalink
Update HostingSubscriptionBackup.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 26, 2024
1 parent ed4798b commit f7291eb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions web/app/Models/HostingSubscriptionBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static function boot()
});

static::deleting(function ($model) {
if (is_dir($model->path)) {
shell_exec('rm -rf ' . $model->path);
if (is_file($model->filepath)) {
shell_exec('rm -rf ' . $model->filepath);
}
});
}
Expand Down Expand Up @@ -82,13 +82,14 @@ public function checkBackup()

if ($this->status == BackupStatus::Processing) {

$backupDoneFile = $this->path.'/backup.done';
$backupDoneFile = $this->path.'/backup-'.$this->id.'.done';
if (file_exists($backupDoneFile)) {
$this->size = Helpers::checkPathSize($this->path);
$this->status = 'completed';
$this->completed = true;
$this->completed_at = now();
$this->save();
shell_exec('rm -rf ' . $backupDoneFile);
return [
'status' => 'completed',
'message' => 'Backup completed'
Expand Down Expand Up @@ -158,7 +159,8 @@ public function startBackup()
$backupLogFileName = 'backup.log';
$backupLogFilePath = $backupPath.'/'.$backupLogFileName;

$backupTargetPath = $findMainDomain->domain_root . '/backups/'.$backupFileName;
$backupTargetPath = $findMainDomain->domain_root . '/backups';
$backupTargetFilePath = $backupTargetPath.'/'.$backupFileName;

$backupTempScript = '/tmp/backup-script-'.$this->id.'.sh';
$shellFileContent = '';
Expand All @@ -170,11 +172,11 @@ public function startBackup()

$shellFileContent .= 'rm -rf '.$backupTempPath.PHP_EOL;
$shellFileContent .= 'echo "Backup complete"' . PHP_EOL;
$shellFileContent .= 'touch ' . $backupPath. '/backup.done' . PHP_EOL;
$shellFileContent .= 'touch ' . $backupTargetPath. '/backup-'.$this->id.'.done' . PHP_EOL;
$shellFileContent .= 'rm -rf ' . $backupTempScript . PHP_EOL;

$shellFileContent .= 'mkdir -p '. $findMainDomain->domain_root . '/backups'.PHP_EOL;
$shellFileContent .= 'mv '.$backupFilePath.' '. $backupTargetPath.PHP_EOL;
$shellFileContent .= 'mkdir -p '. $backupTargetPath.PHP_EOL;
$shellFileContent .= 'mv '.$backupFilePath.' '. $backupTargetFilePath.PHP_EOL;

file_put_contents($backupTempScript, $shellFileContent);

Expand Down

0 comments on commit f7291eb

Please sign in to comment.