private function getBackups($sort = 'name', $direction = 'asc', $offset = 0, $limit = null)
    {
        $directory = txpath . '/' . get_pref('rah_backup_path');

        if (!get_pref('rah_backup_path') || !file_exists($directory) || !is_dir($directory) || !is_readable($directory)) {
            throw new Rah_Backup_Exception(
                gTxt('rah_backup_dir_not_readable', array('{path}' => $directory))
            );
        }

        $order = $files = array();

        $sort_crit = array(
            'name' => SORT_REGULAR,
            'ext' => SORT_REGULAR,
            'date' => SORT_NUMERIC,
            'size' => SORT_NUMERIC,
            'type' => SORT_NUMERIC,
        );

        if (!is_string($sort) || !isset($sort_crit[$sort])) {
            $sort = 'name';
        }

        foreach (new DirectoryIterator($directory) as $file) {

            if (!$file->isFile() || !preg_match('/^[a-z0-9\-_\.]+\.(sql\.gz|tar\.gz)$/i', $file->getFilename())) {
                continue;
            }

            $backup = array(
                'path' => $file->getPathname(),
                'name' => $file->getFilename(),
                'ext' => $file->getExtension(),
                'date' => $file->getMTime(),
                'size' => $file->getSize(),
                'type' => self::BACKUP_FILESYSTEM,
                'readable' => $file->isReadable(),
                'writable' => $file->isWritable(),
            );

            if (preg_match('/\.sql\.gz$/i', $backup['name'])) {
                $backup['type'] = self::BACKUP_DATABASE;
            }

            $files[$backup['name']] = $backup;
            $order[$backup['name']] = $backup[$sort];
        }

        if (!$files) {
            return array();
        }

        array_multisort($order, $sort_crit[$sort], $files);

        if ($direction === 'desc') {
            $files = array_reverse($files);
        }

        return array_slice($files, $offset, $limit);
    }