.htaccess
1 year ago
Automation.php
10 months ago
General.php
3 months ago
Integrations.php
4 months ago
Logging.php
4 months ago
Maintenance.php
4 months ago
Notifications.php
4 months ago
Performance.php
3 months ago
Restore.php
1 year ago
Security.php
1 day ago
Settings.php
4 months ago
Updates.php
4 months ago
index.html
1 year ago
web.config
1 year ago
Performance.php
194 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Settings; |
| 4 | |
| 5 | use JetBackup\BackupJob\BackupJob; |
| 6 | use JetBackup\Config\System; |
| 7 | use JetBackup\Exception\FieldsValidationException; |
| 8 | use JetBackup\Exception\IOException; |
| 9 | use ReflectionException; |
| 10 | |
| 11 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 12 | |
| 13 | class Performance extends Settings { |
| 14 | |
| 15 | const SECTION = 'performance'; |
| 16 | |
| 17 | const EXECUTION_TIME = 'PERFORMANCE_EXECUTION_TIME'; |
| 18 | const READ_CHUNK_SIZE = 'READ_CHUNK_SIZE'; |
| 19 | const SQL_CLEANUP_REVISIONS = 'SQL_CLEANUP_REVISIONS'; |
| 20 | const USE_DEFAULT_EXCLUDES = 'USE_DEFAULT_EXCLUDES'; |
| 21 | const EXCLUDE_NESTED_SITES = 'EXCLUDE_NESTED_SITES'; |
| 22 | |
| 23 | const USE_DEFAULT_DB_EXCLUDES = 'USE_DEFAULT_DB_EXCLUDES'; |
| 24 | const GZIP_COMPRESS_ARCHIVE = 'GZIP_COMPRESS_ARCHIVE'; |
| 25 | const GZIP_COMPRESS_DB = 'GZIP_COMPRESS_DB'; |
| 26 | const DEFAULT_EXCLUDES = 'DEFAULT_EXCLUDES'; |
| 27 | const DEFAULT_DB_EXCLUDES = 'DEFAULT_DB_EXCLUDES'; |
| 28 | const EXECUTION_TIMES = [0, 10, 20, 30, 40, 50, 60, 120, 300, 600]; |
| 29 | const CHUNK_SIZES = [1, 2, 3, 4, 5 ,6 ,8, 10, 12, 14, 16, 20, 24, 32, 64]; |
| 30 | /** |
| 31 | * @throws IOException |
| 32 | * @throws ReflectionException |
| 33 | */ |
| 34 | public function __construct() { |
| 35 | parent::__construct(self::SECTION); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @return int |
| 40 | */ |
| 41 | public function getExecutionTime():int { return (int) $this->get(self::EXECUTION_TIME, 0); } |
| 42 | |
| 43 | /** |
| 44 | * @param int $value |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public function setExecutionTime(int $value):void { $this->set(self::EXECUTION_TIME, $value); } |
| 49 | |
| 50 | /** |
| 51 | * |
| 52 | * @return int |
| 53 | */ |
| 54 | public function getReadChunkSize():int { return (int) $this->get(self::READ_CHUNK_SIZE, 1); } // used for GUI only |
| 55 | |
| 56 | public function getReadChunkSizeBytes():int { return $this->getReadChunkSize() * 1024 * 1024; } |
| 57 | |
| 58 | /** |
| 59 | * @param int $value |
| 60 | * |
| 61 | * @return void |
| 62 | */ |
| 63 | public function setReadChunkSize(int $value):void { $this->set(self::READ_CHUNK_SIZE, $value); } |
| 64 | |
| 65 | /** |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function isSQLCleanupRevisionsEnabled():bool { return (bool) $this->get(self::SQL_CLEANUP_REVISIONS, false); } |
| 69 | |
| 70 | /** |
| 71 | * @param bool $value |
| 72 | * |
| 73 | * @return void |
| 74 | */ |
| 75 | public function setSQLCleanupRevisionsEnabled(bool $value):void { $this->set(self::SQL_CLEANUP_REVISIONS, $value); } |
| 76 | |
| 77 | /** |
| 78 | * @return bool |
| 79 | */ |
| 80 | public function isUseDefaultExcludes():bool { return (bool) $this->get(self::USE_DEFAULT_EXCLUDES, true); } |
| 81 | |
| 82 | /** |
| 83 | * @param bool $value |
| 84 | * |
| 85 | * @return void |
| 86 | */ |
| 87 | public function setUseDefaultExcludes(bool $value):void { $this->set(self::USE_DEFAULT_EXCLUDES, $value); } |
| 88 | |
| 89 | /** |
| 90 | * @return bool |
| 91 | */ |
| 92 | public function isExcludeNestedSitesEnabled():bool { return (bool) $this->get(self::EXCLUDE_NESTED_SITES, true); } |
| 93 | |
| 94 | /** |
| 95 | * @param bool $value |
| 96 | * |
| 97 | * @return void |
| 98 | */ |
| 99 | public function setExcludeNestedSites(bool $value):void { $this->set(self::EXCLUDE_NESTED_SITES, $value); } |
| 100 | |
| 101 | /** |
| 102 | * @return bool |
| 103 | */ |
| 104 | public function isUseDefaultDBExcludes():bool { return (bool) $this->get(self::USE_DEFAULT_DB_EXCLUDES, true); } |
| 105 | |
| 106 | /** |
| 107 | * @param bool $value |
| 108 | * |
| 109 | * @return void |
| 110 | */ |
| 111 | public function setUseDefaultDBExcludes(bool $value):void { $this->set(self::USE_DEFAULT_DB_EXCLUDES, $value); } |
| 112 | |
| 113 | /** |
| 114 | * @return bool |
| 115 | */ |
| 116 | public function isGzipCompressArchive():bool { return (bool) $this->get(self::GZIP_COMPRESS_ARCHIVE, true); } |
| 117 | |
| 118 | /** |
| 119 | * @param bool $value |
| 120 | * |
| 121 | * @return void |
| 122 | */ |
| 123 | public function setGzipCompressArchive(bool $value):void { $this->set(self::GZIP_COMPRESS_ARCHIVE, $value); } |
| 124 | |
| 125 | /** |
| 126 | * @return bool |
| 127 | */ |
| 128 | public function isGzipCompressDB():bool { return (bool) $this->get(self::GZIP_COMPRESS_DB, true); } |
| 129 | |
| 130 | /** |
| 131 | * @param bool $value |
| 132 | * |
| 133 | * @return void |
| 134 | */ |
| 135 | public function setGzipCompressDB(bool $value):void { $this->set(self::GZIP_COMPRESS_DB, $value); } |
| 136 | |
| 137 | /** |
| 138 | * @return array |
| 139 | */ |
| 140 | public function getDisplay():array { |
| 141 | |
| 142 | return [ |
| 143 | self::READ_CHUNK_SIZE => $this->getReadChunkSize(), |
| 144 | self::EXECUTION_TIME => $this->getExecutionTime(), |
| 145 | self::SQL_CLEANUP_REVISIONS => $this->isSQLCleanupRevisionsEnabled() ? 1 : 0, |
| 146 | self::USE_DEFAULT_EXCLUDES => $this->isUseDefaultExcludes() ? 1 : 0, |
| 147 | self::EXCLUDE_NESTED_SITES => $this->isExcludeNestedSitesEnabled() ? 1 : 0, |
| 148 | self::USE_DEFAULT_DB_EXCLUDES => $this->isUseDefaultDBExcludes() ? 1 : 0, |
| 149 | self::GZIP_COMPRESS_ARCHIVE => $this->isGzipCompressArchive() ? 1 : 0, |
| 150 | self::GZIP_COMPRESS_DB => $this->isGzipCompressDB() ? 1 : 0, |
| 151 | self::DEFAULT_EXCLUDES => BackupJob::getDefaultExcludes(null, null), |
| 152 | self::DEFAULT_DB_EXCLUDES => BackupJob::DEFAULT_DATABASE_EXCLUDES, |
| 153 | ]; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @return array |
| 158 | */ |
| 159 | public function getDisplayCLI():array { |
| 160 | |
| 161 | return [ |
| 162 | 'Read Chunk Size' => $this->getReadChunkSize(), |
| 163 | 'Max Execution Time' => $this->getExecutionTime(), |
| 164 | 'SQL Cleanup Revisions' => $this->isSQLCleanupRevisionsEnabled() ? "Yes" : "No", |
| 165 | 'Use Default Excludes' => $this->isUseDefaultExcludes() ? "Yes" : "No", |
| 166 | 'Exclude Nested Sites' => $this->isExcludeNestedSitesEnabled() ? "Yes" : "No", |
| 167 | 'Use Default Database Excludes' => $this->isUseDefaultDBExcludes() ? "Yes" : "No", |
| 168 | 'Compress Backup Files' => $this->isGzipCompressArchive() ? "Yes" : "No", |
| 169 | 'Compress Backup Database' => $this->isGzipCompressDB() ? "Yes" : "No", |
| 170 | ]; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * @throws FieldsValidationException |
| 175 | */ |
| 176 | public function validateFields():void { |
| 177 | |
| 178 | $changedFields = self::getChangedFields($this->getData(), (new Performance())->getData()); |
| 179 | |
| 180 | if(in_array(self::READ_CHUNK_SIZE, $changedFields)) { |
| 181 | if(!in_array($this->getReadChunkSize(), self::CHUNK_SIZES)) |
| 182 | throw new FieldsValidationException('Chunk size '. $this->getReadChunkSize() . ' is not allowed'); |
| 183 | } |
| 184 | |
| 185 | if(in_array(self::EXECUTION_TIME, $changedFields)) { |
| 186 | if(!in_array($this->getExecutionTime(), self::EXECUTION_TIMES)) |
| 187 | throw new FieldsValidationException('Execution time of '. $this->getExecutionTime() . ' is not allowed'); |
| 188 | |
| 189 | $serverExecutionTime = System::getServerExecutionTime(); |
| 190 | if ($serverExecutionTime > 0 && $this->getExecutionTime() > $serverExecutionTime) |
| 191 | throw new FieldsValidationException( 'Execution time of ' . $this->getExecutionTime() . ' seconds cannot be higher than server defaults: ' . $serverExecutionTime); |
| 192 | } |
| 193 | } |
| 194 | } |