Scalr\System\Zmq\Cron\Task\Rotate::rotateBackup PHP Method

rotateBackup() private method

Rotates backup for the table using regexp mask
private rotateBackup ( string $regexp, string $numberBackups = null, string $service = 'adodb' )
$regexp string The regular expression
$numberBackups string The number of the archive files to persist
$service string optional The service name
    private function rotateBackup($regexp, $numberBackups = null, $service = 'adodb')
    {
        $db = \Scalr::getContainer()->{$service};
        //Persists only recent seven backups by default
        $numberBackups = $numberBackups ?: 7;
        $tables = $db->GetCol("\n            SELECT `TABLE_NAME`\n            FROM `INFORMATION_SCHEMA`.`TABLES`\n            WHERE `TABLE_SCHEMA` = DATABASE()\n            AND `TABLE_NAME` REGEXP '" . $regexp . "'\n            ORDER BY `CREATE_TIME`\n       ");
        if (!empty($tables) && ($cnt = count($tables)) > $numberBackups) {
            for ($i = 0; $i + $numberBackups < $cnt; ++$i) {
                $this->getLogger()->info("Removing %s from archive", $tables[$i]);
                $db->Execute("DROP TABLE `" . $tables[$i] . "`");
            }
        }
    }