|
|
@@ -19,51 +19,52 @@ class SnapshotVmJob extends BaseJob {
|
|
|
|
|
|
public function handle($text = null) {
|
|
|
openlog("ProxmoxSnapshot", LOG_PID,LOG_SYSLOG);
|
|
|
- syslog(LOG_NOTICE,"Snapshot Create for " . $this->model->id );
|
|
|
$this->initParams();
|
|
|
$this->setHostingId($this->getWhmcsParamByKey("serviceid"));
|
|
|
if ($this->isDone()) {
|
|
|
return true;
|
|
|
} elseif ($this->isTaskRunning()) {
|
|
|
//sleep
|
|
|
- $this->sleep(5);
|
|
|
+ $this->sleep(25);
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ syslog(LOG_NOTICE,"Snapshot Create for " . $this->model->id );
|
|
|
$snapshot = new Snapshot();
|
|
|
$snapshot->setApi($this->api());
|
|
|
$snapshot->setPath($this->vm()->getPath() . "/snapshot");
|
|
|
$snapshot->setAttributes([
|
|
|
// Changed by Roland at 2021-08-28 because duplicate snappshot names which causes the error: TASK ERROR: snapshot name 'Secure_280' already used
|
|
|
- // Added ' "_" . date("m") . "_" . date("d") . "_" . date("H"),' to make the snapshot-name more unique
|
|
|
- "name" => $this->getSnapshotJob()->name . "_" . $this->model->id . "_" . date("m") . "_" . date("d") . "_" . date("H"),
|
|
|
+ // Added ' "_" . date("m") . "_" . date("d") . "_" . date("H") . "_" . date("i"),' to make the snapshot-name more unique
|
|
|
+ "name" => $this->getSnapshotJob()->name . "_" . date("m") . "_" . date("d") . "_" . date("H") . "_" . date("i"),
|
|
|
"description" => $this->snapshotJob->description,
|
|
|
]);
|
|
|
syslog(LOG_NOTICE," Creating Snapshot for " . $this->getSnapshotJob()->name . "_" . $this->model->id . "_" . date("m") . "_" . date("d") . "_" . date("H"));
|
|
|
if (!is_null($this->snapshotJob->vmstate ) && $this->vm() instanceof Kvm) {
|
|
|
$snapshot->setVmstate($this->snapshotJob->vmstate );
|
|
|
}
|
|
|
+
|
|
|
try {
|
|
|
$taskId = $snapshot->create();
|
|
|
} catch(\Exception $ex) {
|
|
|
$message = $ex->getMessage();
|
|
|
+ syslog(LOG_NOTICE,"!!Snapshot throw Exception: " . $message );
|
|
|
if (strpos($message,"snapshot") === false && strpos($message,"already") === false && strpos($message,"used") === false ) {
|
|
|
throw $ex;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ sleep(25);
|
|
|
+ $this->clean();
|
|
|
+ $this->sleep(5);
|
|
|
+
|
|
|
//save task id
|
|
|
$this->putModelDataAndSave(["taskId" => $taskId, "node" => $this->vm()->getNode()]);
|
|
|
|
|
|
- //sleep
|
|
|
- $this->sleep(25);
|
|
|
- $this->clean();
|
|
|
- $this->sleep(5);
|
|
|
-
|
|
|
- $stackTrace = implode("\n", debug_backtrace());
|
|
|
- syslog(LOG_NOTICE,"Stack Trace " . $stackTrace );
|
|
|
+ syslog(LOG_NOTICE,"Snapshot Processing DONE" );
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @return SnapshotJob
|
|
|
*/
|
|
|
@@ -97,9 +98,26 @@ class SnapshotVmJob extends BaseJob {
|
|
|
if($toDelete <=0){
|
|
|
break;
|
|
|
}
|
|
|
- syslog(LOG_NOTICE," ->Delete Snapshot: " . $entity->getName() . " (" . $entity->getPath() . ")" );
|
|
|
- $entity->delete();
|
|
|
+ $errorCount = 0;
|
|
|
+ $errorMessage = "NOT EMPTY";
|
|
|
+ while(!empty($errorMessage) && $errorCount < 18) {
|
|
|
+ syslog(LOG_NOTICE," ->Delete Snapshot: " . $entity->getName() );
|
|
|
+ try {
|
|
|
+ $result = $entity->delete();
|
|
|
+ //syslog(LOG_NOTICE," ->RESULT " . print_r($result,true) );
|
|
|
+
|
|
|
+ $errorMessage = "";
|
|
|
+ syslog(LOG_NOTICE," ->SUCCESS " . $result );
|
|
|
+ sleep(45);
|
|
|
+ } catch(\Exception $ex) {
|
|
|
+ $errorMessage = $ex->getMessage();
|
|
|
+ syslog(LOG_NOTICE," ->ERROR " . $errorCount . ": " . $errorMessage );
|
|
|
+ $errorCount ++;
|
|
|
+ sleep(45);
|
|
|
+ }
|
|
|
+ }
|
|
|
$toDelete --;
|
|
|
}
|
|
|
+ syslog(LOG_NOTICE,"Snapshot Clean DONE" );
|
|
|
}
|
|
|
}
|