Skip to content

Commit

Permalink
Added error handling for script
Browse files Browse the repository at this point in the history
  • Loading branch information
tjoost committed Oct 24, 2024
1 parent 09d86a6 commit 1fee67b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions scripts/local/backup_local_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ chmod -R 0777 "$to_path"
BACKUP_TEMP_FILE="$to_path/database_migration.sql"

mysqldump --no-tablespaces "$ignoredTables" -u "$user" -p"$password" -h"$host" -P"$port" "$database" > "$BACKUP_TEMP_FILE"

# Das hier ist der exit Code vom vorherigen Befehl
exitCode=$?
exit $exitCode
2 changes: 1 addition & 1 deletion src/Logic/Compressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function compress(string $directory, string $compressedFile, string $name
shell_exec("bash $archiveScriptPath -f \"$directory\" -t \"$compressedFile\" -n \"$name\"");
$this->_poller->pollFile( $this->_path. ConstantsTestStage::LOCAL_DIRECTORY. "/$name");
}catch (Exception $e) {
throw new Compress("Failed to compress to: \"$compressedFile\". $e");
throw new Compress("Failed to compress to: \"$compressedFile\".\nException message: $e");
}
}
}
12 changes: 8 additions & 4 deletions src/Logic/Database/Migrator/DatabaseMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ public function buildAndCopy(): string
}

/**
* @throws BuildDatabaseMigration
* @throws BuildDatabaseMigration|Exception
*/
private function createMigrationFile(): string
{
$ignoredTables = $this->getIgnoreTablesAsString();
$debugMessage = date("H:i:s:u") . " migration ignore tables: " . implode(",", $ignoredTables) . "\n";
shell_exec("bash " . $this->_path . ConstantsTestStage::BACKUP_LOCAL_DATABASE . " -i'".$ignoredTables."' -u'".$this->_testDatabaseConfig->getUsername()."' -p'".$this->_testDatabaseConfig->getPassword()."' -h'".$this->_testDatabaseConfig->getServer()."' -P'".$this->_testDatabaseConfig->getPort()."' -d'".$this->_testDatabaseConfig->getName()."' -t'" . $this->_path . ConstantsTestStage::DATABASE_MIGRATION_DIRECTORY . "' 2>&1");
$debugMessage .= date("H:i:s:u") . " backuped local database \n";
$debugMessage = date("H:i:s:u") . " migration ignore tables: " . $ignoredTables . "\n";
$exitCode = shell_exec("bash " . $this->_path . ConstantsTestStage::BACKUP_LOCAL_DATABASE . " -i'".$ignoredTables."' -u'".$this->_testDatabaseConfig->getUsername()."' -p'".$this->_testDatabaseConfig->getPassword()."' -h'".$this->_testDatabaseConfig->getServer()."' -P'".$this->_testDatabaseConfig->getPort()."' -d'".$this->_testDatabaseConfig->getName()."' -t'" . $this->_path . ConstantsTestStage::DATABASE_MIGRATION_DIRECTORY . "' 2>&1");
if($exitCode != 0) {
throw new Exception("Failed to create local database backup. Output: $exitCode");
} else {
$debugMessage .= date("H:i:s:u") . " backuped local database \n";
}
return $debugMessage;
}

Expand Down

0 comments on commit 1fee67b

Please sign in to comment.