Skip to content
backup.inc.php 98.2 KiB
Newer Older
                if ($app->system->is_installed('pigz')) {
                    //use pigz
                    if ($backup_mode == 'user_zip') {
                        $app->system->exec_safe($find_user_files . ' | ' . $tar_input . ' | pigz > ?', $web_path, $web_user, $web_group, $http_server_user, $web_path, $web_backup_dir . '/' . $web_backup_file);
                    } else {
                        //Standard casual behaviour of ISPConfig
                        $app->system->exec_safe($tar_dir . ' | pigz > ?', $web_path, $web_backup_dir . '/' . $web_backup_file);
                    }
                    $exit_code = $app->system->last_exec_retcode();
                    return $exit_code == 0;
                } else {
                    //use gzip
                    if ($backup_mode == 'user_zip') {
                        $app->system->exec_safe($find_user_files . ' | tar pczf ? --null -T -', $web_path, $web_user, $web_group, $http_server_user, $web_backup_dir . '/' . $web_backup_file);
                    } else {
                        //Standard casual behaviour of ISPConfig
                        $app->system->exec_safe('tar pczf ? ' . $excludes . ' --directory ? .', $web_backup_dir . '/' . $web_backup_file, $web_path);
                    }
                    $exit_code = $app->system->last_exec_retcode();
                    // tar can return 1 and still create valid backups
                    return ($exit_code == 0 || $exit_code == 1);
                }
            case 'zip':
            case 'zip_bzip2':
                $zip_options = ($format === 'zip_bzip2') ? ' -Z bzip2 ' : '';
                if (!empty($password)) {
                    $zip_options .= ' --password ' . escapeshellarg($password);
                }
                $excludes = self::generateExcludeList($backup_excludes, '-x ');
                $excludes .= " " . self::generateExcludeList($backup_excludes, '-x ', '', '/*');
                if ($backup_mode == 'user_zip') {
                    //Standard casual behaviour of ISPConfig
                    $app->system->exec_safe($find_user_files . ' | zip ' . $zip_options . ' -b ? --symlinks ? -@ ' . $excludes, $web_path, $web_user, $web_group, $http_server_user, $backup_tmp, $web_backup_dir . '/' . $web_backup_file);
                    //Use cd to have a correct directory structure inside the archive, zip  current directory "." to include hidden (dot) files
                    $app->system->exec_safe('cd ? && zip ' . $zip_options . ' -b ? --symlinks -r ? . ' . $excludes, $web_path, $backup_tmp, $web_backup_dir . '/' . $web_backup_file);
                }
                $exit_code = $app->system->last_exec_retcode();
                // zip can return 12(due to harmless warnings) and still create valid backups
                return ($exit_code == 0 || $exit_code == 12);
            case 'tar_bzip2':
                if ($backup_mode == 'user_zip') {
                    $app->system->exec_safe($find_user_files . ' | tar pcjf ? --null -T -', $web_path, $web_user, $web_group, $http_server_user, $web_backup_dir . '/' . $web_backup_file);
                } else {
                    $app->system->exec_safe('tar pcjf ? ' . $excludes . ' --directory ? .', $web_backup_dir . '/' . $web_backup_file, $web_path);
                }
                $exit_code = $app->system->last_exec_retcode();
                // tar can return 1 and still create valid backups
                return ($exit_code == 0 || $exit_code == 1);
            case 'tar_xz':
                if ($backup_mode == 'user_zip') {
                    $app->system->exec_safe($find_user_files . ' | tar pcJf ? --null -T -', $web_path, $web_user, $web_group, $http_server_user, $web_backup_dir . '/' . $web_backup_file);
                } else {
                    $app->system->exec_safe('tar pcJf ? ' . $excludes . ' --directory ? .', $web_backup_dir . '/' . $web_backup_file, $web_path);
                }
                $exit_code = $app->system->last_exec_retcode();
                // tar can return 1 and still create valid backups
                return ($exit_code == 0 || $exit_code == 1);
            case 'rar':
                $options = self::getRarOptions($backup_tmp,$password);
                if ($backup_mode != 'user_zip') {
                    //Recurse subfolders, otherwise we will pass a list of files to compress
                    $options .= ' -r';
                }
                $excludes = self::generateExcludeList($backup_excludes, '-x');
                $zip_command = 'rar a ' . $options . ' '.$excludes.' ?';
                if ($backup_mode == 'user_zip') {
                    $app->system->exec_safe($find_user_files . ' | ' . $zip_command . ' ? @', $web_path, $web_user, $web_group, $http_server_user, $web_path, $web_backup_dir . '/' . $web_backup_file);
                } else {
                    $app->system->exec_safe('cd ? && ' . $zip_command . ' .', $web_path, $web_backup_dir . '/' . $web_backup_file);
                }
                $exit_code = $app->system->last_exec_retcode();
                return ($exit_code == 0 || $exit_code == 1);
        }
        if (strpos($format, "tar_7z_") === 0) {
            $options = self::get7zCompressOptions($format, $password);
            $zip_command = '7z a ' . $options . ' -si ?';
            if ($backup_mode == 'user_zip') {
                $app->system->exec_safe($find_user_files . ' | ' . $tar_input . ' | '. $zip_command, $web_path, $web_user, $web_group, $http_server_user, $web_path, $web_backup_dir . '/' . $web_backup_file);
            } else {
                $app->system->exec_safe($tar_dir . ' | ' . $zip_command, $web_path, $web_backup_dir . '/' . $web_backup_file);
            }
            $exit_code = $app->system->last_exec_retcode();
            return $exit_code == 0;
        }
        return false;
    }

    /**
     * Runs a database compression routine
     * @param string $format
     * @param string $db_backup_dir
     * @param string $db_backup_file
     * @param string $compressed_backup_file
     * @param string $backup_tmp
     * @param string|null $password
     * @return bool true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     */
    protected static function runDatabaseCompression($format, $db_backup_dir, $db_backup_file, $compressed_backup_file, $backup_tmp, $password)
    {
        global $app;

        $app->log('Performing database backup to file ' . $compressed_backup_file . ' in format ' . $format, LOGLEVEL_DEBUG);
        switch ($format) {
            case 'gzip':
                if ($app->system->is_installed('pigz')) {
                    //use pigz
                    $zip_cmd = 'pigz';
                } else {
                    //use gzip
                    $zip_cmd = 'gzip';
                }
                $app->system->exec_safe($zip_cmd . " -c ? > ?", $db_backup_dir . '/' . $db_backup_file, $db_backup_dir . '/' . $compressed_backup_file);
                $exit_code = $app->system->last_exec_retcode();
                return $exit_code == 0;
            case 'zip':
            case 'zip_bzip2':
                $zip_options = ($format === 'zip_bzip2') ? ' -Z bzip2 ' : '';
                if (!empty($password)) {
                    $zip_options .= ' --password ' . escapeshellarg($password);
                }
                $app->system->exec_safe('zip ' . $zip_options . ' -j -b ? ? ?', $backup_tmp, $db_backup_dir . '/' . $compressed_backup_file, $db_backup_dir . '/' . $db_backup_file);
                $exit_code = $app->system->last_exec_retcode();
                // zip can return 12(due to harmless warnings) and still create valid backups
                return ($exit_code == 0 || $exit_code == 12);
            case 'bzip2':
                $app->system->exec_safe("bzip2 -q -c ? > ?", $db_backup_dir . '/' . $db_backup_file, $db_backup_dir . '/' . $compressed_backup_file);
                $exit_code = $app->system->last_exec_retcode();
                return $exit_code == 0;
            case 'xz':
                $app->system->exec_safe("xz -q -q -c ? > ?", $db_backup_dir . '/' . $db_backup_file, $db_backup_dir . '/' . $compressed_backup_file);
                $exit_code = $app->system->last_exec_retcode();
                return $exit_code == 0;
            case 'rar':
                $options = self::getRarOptions($backup_tmp, $password);
                $zip_command = 'rar a ' . $options . ' ? ?';
                $app->system->exec_safe($zip_command, $db_backup_dir . '/' . $compressed_backup_file, $db_backup_dir . '/' . $db_backup_file);
                $exit_code = $app->system->last_exec_retcode();
                return ($exit_code == 0 || $exit_code == 1);
        }
        if (strpos($format, "7z_") === 0) {
            $options = self::get7zCompressOptions($format, $password);
            $zip_command = '7z a ' . $options . ' ? ?';
            $app->system->exec_safe($zip_command, $db_backup_dir . '/' . $compressed_backup_file, $db_backup_dir . '/' . $db_backup_file);
            $exit_code = $app->system->last_exec_retcode();
            return $exit_code == 0;
        }
        return false;
    }

    /**
     * Mounts the backup directory if required
     * @param int $server_id
     * @return bool true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     * @see backup_plugin::unmount_backup_dir()
     */
    public static function mount_backup_dir($server_id)
    {
        global $app;

        $server_config = $app->getconf->get_server_config($server_id, 'server');
        if ($server_config['backup_dir_is_mount'] == 'y')
            return $app->system->mount_backup_dir($server_config['backup_dir']);
        return true;
    }

    /**
     * Unmounts the backup directory if required
     * @param int $server_id
     * @return bool true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     * @see backup_plugin::mount_backup_dir()
     */
    public static function unmount_backup_dir($server_id)
    {
        global $app;

        $server_config = $app->getconf->get_server_config($server_id, 'server');
        if ($server_config['backup_dir_is_mount'] == 'y')
            return $app->system->umount_backup_dir($server_config['backup_dir']);
        return true;
    }

    /**
     * Makes backup of database.
     * The backup directory must be mounted before calling this method.
     * This method is for private use only, don't call this method unless you know what you're doing.
     * @param array $web_domain
     * @param string $backup_job type of backup job: manual or auto
     * @return bool true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     * @see backup_plugin::run_backup() recommeneded to use if you need to make backups
     */
    protected static function make_database_backup($web_domain, $backup_job)
    {
        global $app;

        $server_id = intval($web_domain['server_id']);
        $domain_id = intval($web_domain['domain_id']);
        $server_config = $app->getconf->get_server_config($server_id, 'server');
        $backup_dir = trim($server_config['backup_dir']);
        $backup_tmp = trim($server_config['backup_tmp']);
        $db_backup_dir = $backup_dir . '/web' . $domain_id;
        $success = false;

        if (empty($backup_job))
            $backup_job = "auto";

        $records = $app->dbmaster->queryAllRecords("SELECT * FROM web_database WHERE server_id = ? AND parent_domain_id = ?", $server_id, $domain_id);
        if (empty($records)){
            $app->log('Skipping database backup for domain ' . $web_domain['domain_id'] . ', because no related databases found.', LOGLEVEL_DEBUG);
            return true;
        }

        self::prepare_backup_dir($server_id, $web_domain);

        include '/usr/local/ispconfig/server/lib/mysql_clientdb.conf';

        //* Check mysqldump capabilities
        exec('mysqldump --help', $tmp);
        $mysqldump_routines = (strpos(implode($tmp), '--routines') !== false) ? '--routines' : '';
        unset($tmp);

        foreach ($records as $rec) {
            $password = ($web_domain['backup_encrypt'] == 'y') ? trim($web_domain['backup_password']) : '';
            $backup_format_db = $web_domain['backup_format_db'];
            if (empty($backup_format_db)) {
                $backup_format_db = 'gzip';
            }
            $backup_extension_db = self::getBackupDbExtension($backup_format_db);

            if (!empty($backup_extension_db)) {
                //* Do the mysql database backup with mysqldump
                $db_name = $rec['database_name'];
                $db_file_prefix = 'db_' . $db_name . '_' . date('Y-m-d_H-i');
                $db_backup_file = $db_file_prefix . '.sql';
                $db_compressed_file = ($backup_job == 'manual' ? 'manual-' : '') . $db_file_prefix . $backup_extension_db;
                $command = "mysqldump -h ? -u ? -p? -c --add-drop-table --create-options --quick --max_allowed_packet=512M " . $mysqldump_routines . " --result-file=? ?";
                /** @var string $clientdb_host */
                /** @var string $clientdb_user */
                /** @var string $clientdb_password */
                $app->system->exec_safe($command, $clientdb_host, $clientdb_user, $clientdb_password, $db_backup_dir . '/' . $db_backup_file, $db_name);
                $exit_code = $app->system->last_exec_retcode();

                //* Compress the backup
                if ($exit_code == 0) {
                    $exit_code = self::runDatabaseCompression($backup_format_db, $db_backup_dir, $db_backup_file, $db_compressed_file, $backup_tmp, $password) ? 0 : 1;
                    if ($exit_code !== 0)
                        $app->log('Failed to make backup of database ' . $rec['database_name'], LOGLEVEL_ERROR);
                } else {
                    $app->log('Failed to make backup of database ' . $rec['database_name'] . ', because mysqldump failed', LOGLEVEL_ERROR);
                }

                if ($exit_code == 0) {
                    if (is_file($db_backup_dir . '/' . $db_compressed_file)) {
                        chmod($db_backup_dir . '/' . $db_compressed_file, 0750);
                        chown($db_backup_dir . '/' . $db_compressed_file, fileowner($db_backup_dir));
                        chgrp($db_backup_dir . '/' . $db_compressed_file, filegroup($db_backup_dir));

                        //* Insert web backup record in database
                        $file_size = filesize($db_backup_dir . '/' . $db_compressed_file);
                        $sql = "INSERT INTO web_backup (server_id, parent_domain_id, backup_type, backup_mode, backup_format, tstamp, filename, filesize, backup_password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
                        //Making compatible with previous versions of ISPConfig:
                        $sql_mode = ($backup_format_db == 'gzip') ? 'sqlgz' : ('sql' . $backup_format_db);
                        $app->db->query($sql, $server_id, $domain_id, 'mysql', $sql_mode, $backup_format_db, time(), $db_compressed_file, $file_size, $password);
                        if ($app->db->dbHost != $app->dbmaster->dbHost)
                            $app->dbmaster->query($sql, $server_id, $domain_id, 'mysql', $sql_mode, $backup_format_db, time(), $db_compressed_file, $file_size, $password);
                        $success = true;
                    }
                } else {
                    if (is_file($db_backup_dir . '/' . $db_compressed_file)) unlink($db_backup_dir . '/' . $db_compressed_file);
                }
                //* Remove the uncompressed file
                if (is_file($db_backup_dir . '/' . $db_backup_file)) unlink($db_backup_dir . '/' . $db_backup_file);

                //* Remove old backups
                self::backups_garbage_collection($server_id, 'mysql', $domain_id);
                $prefix_list = array(
                            "db_${db_name}_",
                            "manual-db_${db_name}_",
                        );
                self::clearBackups($server_id, $domain_id, intval($rec['backup_copies']), $db_backup_dir, $prefix_list);
            } else {
                $app->log('Failed to process mysql backup format ' . $backup_format_db . ' for database ' . $rec['database_name'], LOGLEVEL_ERROR);
            }
        }

        unset($clientdb_host);
        unset($clientdb_user);
        unset($clientdb_password);

        return $success;
    }

    /**
     * Makes backup of web files.
     * The backup directory must be mounted before calling this method.
     * This method is for private use only, don't call this method unless you know what you're doing
     * @param array $web_domain info about domain to backup, SQL record of table 'web_domain'
     * @param string $backup_job type of backup job: manual or auto
     * @return bool true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     * @see backup_plugin::mount_backup_dir()
     * @see backup_plugin::run_backup() recommeneded to use if you need to make backups
     */
    protected static function make_web_backup($web_domain, $backup_job)
    {
        global $app;

        $server_id = intval($web_domain['server_id']);
        $domain_id = intval($web_domain['domain_id']);
        $server_config = $app->getconf->get_server_config($server_id, 'server');
        $global_config = $app->getconf->get_global_config('sites');
        $backup_dir = trim($server_config['backup_dir']);
        $backup_mode = $server_config['backup_mode'];
        $backup_tmp = trim($server_config['backup_tmp']);
        if (empty($backup_mode))
            $backup_mode = 'userzip';

        $web_config = $app->getconf->get_server_config($server_id, 'web');
        $http_server_user = $web_config['user'];

        if (empty($backup_dir)) {
            $app->log('Failed to make backup of web files for domain id ' . $domain_id . ' on server id ' . $server_id . ', because backup directory is not defined', LOGLEVEL_ERROR);
            return false;
        }
        if (empty($backup_job))
            $backup_job = "auto";

        $backup_format_web = $web_domain['backup_format_web'];
        //Check if we're working with data saved in old version of ISPConfig
        if (empty($backup_format_web)) {
            $backup_format_web = 'default';
        }
        if ($backup_format_web == 'default') {
            $backup_format_web = self::getDefaultBackupFormat($backup_mode, 'web');
        }
        $password = ($web_domain['backup_encrypt'] == 'y') ? trim($web_domain['backup_password']) : '';
        $backup_extension_web = self::getBackupWebExtension($backup_format_web);
        if (empty($backup_extension_web)) {
            $app->log('Failed to make backup of web files, because of unknown backup format ' . $backup_format_web . ' for website ' . $web_domain['domain'], LOGLEVEL_ERROR);
            return false;
        }

        $web_path = $web_domain['document_root'];
        $web_user = $web_domain['system_user'];
        $web_group = $web_domain['system_group'];
        $web_id = $web_domain['domain_id'];

        self::prepare_backup_dir($server_id, $web_domain);
        $web_backup_dir = $backup_dir . '/web' . $web_id;

	# default exclusions
	$backup_excludes = array(
		'./bin', './dev', './etc', './lib', './lib32', './lib64', './opt', './sys', './usr', './var', './proc', './run', './tmp',
		);

        $b_excludes = explode(',', trim($web_domain['backup_excludes']));
        if (is_array($b_excludes) && !empty($b_excludes)) {
            foreach ($b_excludes as $b_exclude) {
                $b_exclude = trim($b_exclude);
                if ($b_exclude != '') {
                    array_push($backup_excludes, escapeshellarg($b_exclude));
                }
            }
        }

        $web_backup_file = ($backup_job == 'manual' ? 'manual-' : '') . 'web' . $web_id . '_' . date('Y-m-d_H-i') . $backup_extension_web;
        $full_filename = $web_backup_dir . '/' . $web_backup_file;
        if (self::runWebCompression($backup_format_web, $backup_excludes, $backup_mode, $web_path, $web_backup_dir, $web_backup_file, $web_user, $web_group, $http_server_user, $backup_tmp, $password)) {
            if (is_file($full_filename)) {
                $backup_username = ($global_config['backups_include_into_web_quota'] == 'y') ? $web_user : 'root';
                $backup_group = ($global_config['backups_include_into_web_quota'] == 'y') ? $web_group : 'root';
                chown($full_filename, $backup_username);
                chgrp($full_filename, $backup_group);
                chmod($full_filename, 0750);

                //Insert web backup record in database
                $file_size = filesize($full_filename);
                $sql = "INSERT INTO web_backup (server_id, parent_domain_id, backup_type, backup_mode, backup_format, tstamp, filename, filesize, backup_password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
                $app->db->query($sql, $server_id, $web_id, 'web', $backup_mode, $backup_format_web, time(), $web_backup_file, $file_size, $password);
                if ($app->db->dbHost != $app->dbmaster->dbHost)
                    $app->dbmaster->query($sql, $server_id, $web_id, 'web', $backup_mode, $backup_format_web, time(), $web_backup_file, $file_size, $password);
                unset($file_size);
                $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' completed successfully to file ' . $full_filename, LOGLEVEL_DEBUG);
            } else {
                $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' reported success, but the resulting file ' . $full_filename . ' not found.', LOGLEVEL_ERROR);
            }

        } else {
            if (is_file($full_filename))
                unlink($full_filename);
            $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' failed using path ' . $web_path . ' failed.', LOGLEVEL_ERROR);
        }

	$prefix_list = array(
		    'web',
		    'manual-web',
		);
        self::clearBackups($server_id, $web_id, intval($web_domain['backup_copies']), $web_backup_dir, $prefix_list);
        return true;
    }

    /**
     * Creates and prepares a backup dir
     * @param int $server_id
     * @param array $domain_data
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     */
    protected static function prepare_backup_dir($server_id, $domain_data)
    {
        global $app;

        $server_config = $app->getconf->get_server_config($server_id, 'server');
        $global_config = $app->getconf->get_global_config('sites');

        if (isset($server_config['backup_dir_ftpread']) && $server_config['backup_dir_ftpread'] == 'y') {
            $backup_dir_permissions = 0755;
        } else {
            $backup_dir_permissions = 0750;
        }

        $backup_dir = $server_config['backup_dir'];

        if (!is_dir($backup_dir)) {
            mkdir($backup_dir, $backup_dir_permissions, true);
        } else {
            chmod($backup_dir, $backup_dir_permissions);
        }

        $web_backup_dir = $backup_dir . '/web' . $domain_data['domain_id'];
        if (!is_dir($web_backup_dir))
            mkdir($web_backup_dir, 0750);
        chmod($web_backup_dir, 0750);

        $backup_username = 'root';
        $backup_group = 'root';

        if ($global_config['backups_include_into_web_quota'] == 'y') {
            $backup_username = $domain_data['system_user'];
            $backup_group = $domain_data['system_group'];
        }
        chown($web_backup_dir, $backup_username);
        chgrp($web_backup_dir, $backup_group);
    }

    /**
     * Makes a backup of website files or database.
     * @param string|int $domain_id
     * @param string $type backup type: web or mysql
     * @param string $backup_job how the backup is initiated: manual or auto
     * @param bool $mount if true, then the backup dir will be mounted and unmounted automatically
     * @return bool returns true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     */
    public static function run_backup($domain_id, $type, $backup_job, $mount = true)
    {
        global $app, $conf;

        $domain_id = intval($domain_id);

        $sql = "SELECT * FROM web_domain WHERE (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND domain_id = ?";
        $rec = $app->dbmaster->queryOneRecord($sql, $domain_id);
        if (empty($rec)) {
            $app->log('Failed to make backup of type ' . $type . ', because no information present about requested domain id ' . $domain_id, LOGLEVEL_ERROR);
            return false;
        }
        $server_id = intval($conf['server_id']);

        if ($mount && !self::mount_backup_dir($server_id)) {
            $app->log('Failed to make backup of type ' . $type . ' for domain id ' . $domain_id . ', because failed to mount backup directory', LOGLEVEL_ERROR);
            return false;
        }
        $ok = false;

        switch ($type) {
            case 'web':
Jorge Muñoz's avatar
Jorge Muñoz committed
                //$ok = self::make_web_backup($rec, $backup_job);
                /** The next changes are for repository specific backup method selection */
                if (self::formatIsRepos($rec['backup_format_web'], 'web')) {
                    $ok = self::make_web_backup_repos($rec, $backup_job);
                } else {
                    $ok = self::make_web_backup($rec, $backup_job);
                }
                /** END */
                $rec['server_id'] = $server_id;
Jorge Muñoz's avatar
Jorge Muñoz committed
                //$ok = self::make_database_backup($rec, $backup_job);
                /** The next changes are for repository specific backup method selection */
                if (self::formatIsRepos($rec['backup_format_db'], 'mysql')) {
                    $ok = self::make_database_backup_repos($rec, $backup_job);
                } else {
                    $ok = self::make_database_backup($rec, $backup_job);
                }
                /** END */
                break;
            default:
                $app->log('Failed to make backup, because backup type is unknown: ' . $type, LOGLEVEL_ERROR);
                break;
        }
        if ($mount)
            self::unmount_backup_dir($server_id);
        return $ok;
    }

    /**
     * Runs backups of all websites that have backups enabled with respect to their backup interval settings
     * @param int $server_id
     * @param string $backup_job backup tupe: auto or manual
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     */
    public static function run_all_backups($server_id, $backup_job = "auto")
    {
        global $app;

        $server_id = intval($server_id);

        $sql = "SELECT * FROM web_domain WHERE server_id = ? AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND active = 'y' AND backup_interval != 'none' AND backup_interval != ''";
        $domains = $app->dbmaster->queryAllRecords($sql, $server_id);

        if (!self::mount_backup_dir($server_id)) {
            $app->log('Failed to run regular backups routine because failed to mount backup directory', LOGLEVEL_ERROR);
            return;
        }
        self::backups_garbage_collection($server_id);

        $date_of_week = date('w');
        $date_of_month = date('d');
        foreach ($domains as $domain) {
            if (($domain['backup_interval'] == 'daily' or ($domain['backup_interval'] == 'weekly' && $date_of_week == 0) or ($domain['backup_interval'] == 'monthly' && $date_of_month == '01'))) {
                self::run_backup($domain['domain_id'], 'web', $backup_job, false);
	$sql = "SELECT DISTINCT d.*, db.server_id as `server_id` FROM web_database as db INNER JOIN web_domain as d ON (d.domain_id = db.parent_domain_id) WHERE db.server_id = ? AND db.active = 'y' AND d.backup_interval != 'none' AND d.backup_interval != ''";
        $databases = $app->dbmaster->queryAllRecords($sql, $server_id);

        foreach ($databases as $database) {
            if (($database['backup_interval'] == 'daily' or ($database['backup_interval'] == 'weekly' && $date_of_week == 0) or ($database['backup_interval'] == 'monthly' && $date_of_month == '01'))) {
                self::run_backup($database['domain_id'], 'mysql', $backup_job, false);
            }
        }
        self::unmount_backup_dir($server_id);
    }

Jorge Muñoz's avatar
Jorge Muñoz committed
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
    /**** The following lines are additions for special borg format repos ******/
    /**
     * Makes a web backup for a repository type backup
     **/
    protected static function make_web_backup_repos($web_domain, $backup_job)
    {
        global $app;

        $server_id = intval($web_domain['server_id']);
        $domain_id = intval($web_domain['domain_id']);
        $server_config = $app->getconf->get_server_config($server_id, 'server');
        $global_config = $app->getconf->get_global_config('sites');
        $backup_dir = trim($server_config['backup_dir']);
        $backup_mode = $server_config['backup_mode'];
        $backup_tmp = trim($server_config['backup_tmp']);
        $web_config = $app->getconf->get_server_config($server_id, 'web');
        $http_server_user = $web_config['user'];

        if (empty($backup_dir)) {
            $app->log('Failed to make backup of web files for domain id ' . $domain_id . ' on server id ' . $server_id . ', because backup directory is not defined', LOGLEVEL_ERROR);
            return false;
        }
        if (empty($backup_job))
            $backup_job = "auto";

        $backup_format_web = $web_domain['backup_format_web'];
        //Check if we're working with data saved in old version of ISPConfig
        if (empty($backup_format_web)) {
            $backup_format_web = 'default';
        }
        if ($backup_format_web == 'default') {
            $backup_format_web = 'borg';
        }
        $password = ($web_domain['backup_encrypt'] == 'y') ? trim($web_domain['backup_password']) : '';
        $backup_repos_folder = self::getBackupReposFolder($backup_format_web, 'web');
        if (empty($backup_repos_folder)) {
            $app->log('Failed to make backup of web files, because of unknown backup format ' . $backup_format_web . ' for website ' . $web_domain['domain'], LOGLEVEL_ERROR);
            return false;
        }

        $web_path = $web_domain['document_root'];
        $web_user = $web_domain['system_user'];
        $web_group = $web_domain['system_group'];
        $web_id = $web_domain['domain_id'];

        backup::prepare_backup_dir($server_id, $web_domain);
        $web_backup_dir = $backup_dir . '/web' . $web_id;

        # default exclusions
        $backup_excludes = array(
            './backup*',
            './bin', './dev', './etc', './lib', './lib32', './lib64', './opt', './sys', './usr', './var', './proc', './run', './tmp',
        );

        $b_excludes = explode(',', trim($web_domain['backup_excludes']));
        if (is_array($b_excludes) && !empty($b_excludes)) {
            foreach ($b_excludes as $b_exclude) {
                $b_exclude = trim($b_exclude);
                if ($b_exclude != '') {
                    array_push($backup_excludes, escapeshellarg($b_exclude));
                }
            }
        }

        $web_backup_archive = ($backup_job == 'manual' ? 'manual-' : '') . 'web' . $web_id . '_' . date('Y-m-d_H-i');
        $backup_repos_path = $web_backup_dir . '/' . $backup_repos_folder;
        $full_archive_path = $backup_repos_path . '::' . $web_backup_archive;
        $archives = self::prepareRepos($backup_format_web, $backup_repos_path, $password);

        if ($archives === FALSE) {
            $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' using path ' . $web_path . ' failed.', LOGLEVEL_ERROR);
            return FALSE;
        }

        if (self::runBackupRepos($backup_format_web, $backup_excludes, $backup_mode, $web_path, $backup_repos_path, $web_backup_archive, $web_user, $web_group, $http_server_user, $backup_tmp, $password)) {
            $backup_username = ($global_config['backups_include_into_web_quota'] == 'y') ? $web_user : 'root';
            $backup_group = ($global_config['backups_include_into_web_quota'] == 'y') ? $web_group : 'root';

            //Insert web backup record in database
            $archive_size = self::getArchiveSize($backup_format_web, $backup_repos_path, $web_backup_archive, $password);
            $sql = "INSERT INTO web_backup (server_id, parent_domain_id, backup_type, backup_mode, backup_format, tstamp, filename, filesize, backup_password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
            $app->db->query($sql, $server_id, $web_id, 'web', $backup_mode, $backup_format_web, time(), $web_backup_archive, $archive_size, $password);
            if ($app->db->dbHost != $app->dbmaster->dbHost)
                $app->dbmaster->query($sql, $server_id, $web_id, 'web', $backup_mode, $backup_format_web, time(), $web_backup_archive, $archive_size, $password);
            unset($archive_size);
            $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' completed successfully to archive ' . $full_archive_path, LOGLEVEL_DEBUG);
        } else {
            if ($archives && in_array($web_backup_archive, $archives)) {
                self::deleteArchive($backup_format_web, $backup_repos_path, $web_backup_archive, $password);
            }
            $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' using path ' . $web_path . ' failed.', LOGLEVEL_ERROR);
        }

        $prefix_list = array(
            'web',
            'manual-web',
        );
        self::cleanup_repository($backup_format_web, $server_id, $web_id, intval($web_domain['backup_copies']), $backup_repos_path, $prefix_list, 'web', $password);
        return true;
    }
    protected static function cleanup_repository($format, $server_id, $web_id, $backup_copies, $backup_repos_path, $prefix_list, $backup_type, $password)
    {
        global $app;
        self::pruneRepos($format, $backup_repos_path, $prefix_list, $backup_copies, $password);
        $archives = self::getReposArchives($format, $backup_repos_path, $password);
        if ($archives === false) {
            $app->log('Error trying to access list of repos ' . $backup_repos_path . ' to prune', LOGLEVEL_ERROR);
            return false;
        }
        $sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ? AND backup_type = ? AND backup_format = ? ";
        if ($archives) {
            $sql .= "AND filename NOT IN ('" . implode("','", $archives) . "')";
        }
        #var_export(['sql' => $sql, 'binds' => [$server_id, $web_id, $backup_type, $format]]);
        $app->db->query($sql, $server_id, $web_id, $backup_type, $format);
        if ($app->db->dbHost != $app->dbmaster->dbHost)
            $app->dbmaster->query($sql, $server_id, $web_id, $backup_type, $format);
        return true;
    }
    protected static function getBackupReposFolder($backup_format, $backup_type)
    {
        switch ($backup_format) {
            case 'borg': return 'borg_' . $backup_type;
        }
        return null;
    }
    protected static function runBackupRepos($format, $backup_excludes, $backup_mode, $web_path, $backup_repos_path, $web_backup_archive, $web_user, $web_group, $http_server_user, $backup_tmp, $password)
    {
        global $app;
        #we wont use tar to be able to speed up things and extract specific files easily
        #$find_user_files = 'cd ? && find . -group ? -or -user ? -print 2> /dev/null';
        $excludes = backup::generateExcludeList($backup_excludes, '--exclude ');

        $app->log('Performing web files backup of ' . $web_path . ' in format ' . $format . ', mode ' . $backup_mode, LOGLEVEL_DEBUG);
        switch ($format) {
            case 'borg':
                $password_cmd = self::getPasswordCommand($format, $password);
                $app->system->exec_safe(
                    'cd ? && ' . $password_cmd . 'borg create -C zlib --exclude-caches ' . $excludes . ' ? .',
                    $web_path, $backup_repos_path . '::' . $web_backup_archive
                );
                $exit_code = $app->system->last_exec_retcode();
                return $exit_code == 0;
        }
        return FALSE;
    }
    protected static function getPasswordCommand($format, $password, $is_new = false)
    {
        switch ($format) {
            case 'borg':
                if ($password) {
                    $password = str_replace("'", "'\"'\"'", $password);
                    if ($is_new) {
                        return "BORG_NEW_PASSPHRASE='{$password}' ";
                    }
                    return "BORG_PASSPHRASE='{$password}' ";
                }
                return '';
        }
        return NULL;
    }
    protected static function prepareRepos($backup_format, $repos_path, $password)
    {
        global $app;
        if (is_dir($repos_path)) {
            $archives = self::getReposArchives($backup_format, $repos_path, $password);
            if ($app->system->last_exec_retcode() == 0) {
                return $archives;
            }
            if ($app->system->last_exec_retcode() == 2 && preg_match('/passphrase supplied in.*is incorrect/', $app->system->last_exec_out()[0])) {
                //Password was updated, so we rename folder and alert the event.
                $repos_stat = stat($repos_path);
                $mtime = $repos_stat['mtime'];
                $new_repo_path = $repos_path . '_' . date('Y-m-d_H-i', $mtime);
                rename($repos_path, $new_repo_name);
                $app->log('Backup of web files for domain ' . $web_domain['domain'] . ' are encrypted under a different password. Original repos was moved to ' . $new_repo_name, LOGLEVEL_WARN);
            } else {
                return false;
            }
        }
        switch ($backup_format) {
            case 'borg':
                if ($password) {
                    $password_cmd = self::getPasswordCommand($backup_format, $password, TRUE);
                    $app->system->exec_safe($password_cmd . 'borg init --make-parent-dirs -e authenticated ?', $repos_path);
                } else {
                    $app->system->exec_safe('borg init --make-parent-dirs -e none ?', $repos_path);
                }
                return $app->system->last_exec_retcode() == 0;
        }
        return false;
    }
    protected static function getReposArchives($backup_format, $repos_path, $password)
    {
        global $app;
        if ( ! is_dir($repos_path)) {
            return FALSE;
        }
        switch ($backup_format) {
            case 'borg':
                $password_cmd = self::getPasswordCommand($backup_format, $password);
                $app->system->exec_safe($password_cmd . "borg list --short ?", $repos_path);
                if ($app->system->last_exec_retcode() == 0) {
                    return $app->system->last_exec_out();
                }
                break;
        }
        return FALSE;
    }
    protected static function getArchiveSize($backup_format, $backup_repos_path, $backup_archive, $password)
    {
        global $app;
        switch ($backup_format) {
            case 'borg':
                $password_cmd = self::getPasswordCommand($backup_format, $password);
                $ret = $app->system->exec_safe(
                    $password_cmd . 'borg info --json ? | awk -F \'[ ,]*\' \'/compressed_size/{print $3}\'',
                    $backup_repos_path . '::' . $backup_archive
                );
                if ($app->system->last_exec_retcode() == 0) {
                    return (int)$ret;
                }
        }
        return NULL;
    }
    protected static function deleteArchive($format, $backup_repos_path, $backup_archive, $password)
    {
        global $app;
        switch ($format) {
            case 'borg':
                $password_cmd = self::getPasswordCommand($format, $password);
                $app->system->exec_safe($password_cmd . 'borg delete ?', $backup_repos_path . '::' . $backup_archive);
                return $app->system->last_exec_retcode() == 0;
            default:
                $app->log("Unknown repos format " . $format, LOGLEVEL_ERROR);
        }
        return FALSE;
    }
    protected static function pruneRepos($format, $backup_repos_path, $prefix_list, $backup_copies, $password)
    {
        global $app;
        switch ($format) {
            case 'borg':
                $password_cmd = self::getPasswordCommand($format, $password);
                foreach ($prefix_list as $prefix) {
                    $app->system->exec_safe(
                        $password_cmd . 'borg prune --keep-last ? -P ? ?',
                        $backup_copies,
                        $prefix,
                        $backup_repos_path
                    );
                    $ret_val = $app->system->last_exec_retcode();
                    if ($ret_val != 0) {
                        break;
                    }
                }
                return $ret_val == 0;
        }
        return FALSE;
    }
    /**
     * Makes backup of database into a repository type format.
     * The backup directory must be mounted before calling this method.
     * This method is for private use only, don't call this method unless you know what you're doing.
     * @param array $web_domain
     * @param string $backup_job type of backup job: manual or auto
     * @return bool true if success
     * @author Ramil Valitov <ramilvalitov@gmail.com>
     * @see backup_plugin::run_backup() recommeneded to use if you need to make backups
     */
    protected static function make_database_backup_repos($web_domain, $backup_job)
    {
        global $app;

        $server_id = intval($web_domain['server_id']);
        $domain_id = intval($web_domain['domain_id']);
        $server_config = $app->getconf->get_server_config($server_id, 'server');
        $backup_dir = trim($server_config['backup_dir']);
        $backup_tmp = trim($server_config['backup_tmp']);
        $db_backup_dir = $backup_dir . '/web' . $domain_id;
        $success = false;
        $web_user = $web_domain['system_user'];
        $web_group = $web_domain['system_group'];

        if (empty($backup_job))
            $backup_job = "auto";

        $records = $app->dbmaster->queryAllRecords("SELECT * FROM web_database WHERE server_id = ? AND parent_domain_id = ?", $server_id, $domain_id);
        if (empty($records)){
            $app->log('Skipping database backup for domain ' . $web_domain['domain_id'] . ', because no related databases found.', LOGLEVEL_DEBUG);
            return true;
        }

        self::prepare_backup_dir($server_id, $web_domain);

        include '/usr/local/ispconfig/server/lib/mysql_clientdb.conf';

        //* Check mysqldump capabilities
        exec('mysqldump --help', $tmp);
        $mysqldump_routines = (strpos(implode($tmp), '--routines') !== false) ? '--routines' : '';
        unset($tmp);
        $backup_dir .= DIRECTORY_SEPARATOR . 'web' . $domain_id;

        foreach ($records as $rec) {
            $password = ($web_domain['backup_encrypt'] == 'y') ? trim($web_domain['backup_password']) : '';
            $backup_format_db = $web_domain['backup_format_db'];
            if (empty($backup_format_db)) {
                $backup_format_db = 'borg';
            }

            if (!empty($backup_format_db)) {
                //* Do the mysql database backup with mysqldump
                $db_name = $rec['database_name'];
                $db_repos_folder = self::getBackupReposFolder($backup_format_db, 'mysql') . '_' . $db_name;
                $backup_repos_path = $backup_dir . DIRECTORY_SEPARATOR . $db_repos_folder;
                $archives = self::prepareRepos($backup_format_db, $backup_repos_path, $password);
                if ($archives === false) {
                    $app->log('Backup of database '  . $rec['database_name'] . ' failed.', LOGLEVEL_ERROR);
                    return false;
                }

                $db_backup_archive = ($backup_job == 'manual' ? 'manual-' : '') . 'db_' . $db_name . '_' . date('Y-m-d_H-i');
                $full_archive_path = $backup_repos_path . '::' . $db_backup_archive;
                $dump_command = "mysqldump -h ? -u ? -p? -c --add-drop-table --create-options --quick --max_allowed_packet=512M " . $mysqldump_routines . " ?";
                switch ($backup_format_db) {
                    case 'borg':
                        $password_cmd = self::getPasswordCommand($backup_format_db, $password);
                        $command = $dump_command . ' | ' . $password_cmd . 'borg create -C zlib ? -';
                        /** @var string $clientdb_host */
                        /** @var string $clientdb_user */
                        /** @var string $clientdb_password */
                        $app->system->exec_safe($command,
                            $clientdb_host, $clientdb_user, $clientdb_password, $db_name, #mysqldump command part
                            $full_archive_path #borg command part
                        );
                        $exit_code = $app->system->last_exec_retcode();
                        break;
                    default:
                        $app->log('Failed to make backup of database ' . $rec['database_name'] . ', because format ' . $backup_format_db . ' is unknown', LOGLEVEL_ERROR);
                        return false;
                }

                if ($exit_code == 0) {
                    $archive_size = self::getArchiveSize($backup_format_db, $backup_repos_path, $db_backup_archive, $password);
                    if ($archive_size !== false) {
                        //* Insert web backup record in database
                        $sql = "INSERT INTO web_backup (server_id, parent_domain_id, backup_type, backup_mode, backup_format, tstamp, filename, filesize, backup_password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
                        //Making compatible with previous versions of ISPConfig:
                        $sql_mode = 'sql' . $backup_format_db;
                        $app->db->query($sql, $server_id, $domain_id, 'mysql', $sql_mode, $backup_format_db, time(), $db_backup_archive, $archive_size, $password);
                        if ($app->db->dbHost != $app->dbmaster->dbHost)
                            $app->dbmaster->query($sql, $server_id, $domain_id, 'mysql', $sql_mode, $backup_format_db, time(), $db_backup_archive, $archive_size, $password);
                        $success = true;
                    } else {
                        $app->log('Failed to obtain backup size of ' . $full_archive_path . ' for database ' . $rec['database_name'], LOGLEVEL_ERROR);
                        return false;
                    }
                } else {
                    rename($backup_repos_path, $new_path = $backup_repos_path . '_failed_' . uniqid());
                    $app->log('Failed to process mysql backup format ' . $backup_format_db . ' for database ' . $rec['database_name'] . ' repos renamed to ' . $new_path, LOGLEVEL_ERROR);
                }

                //* Remove old backups
                $prefix_list = array(
                    "db_${db_name}_",
                    "manual-db_${db_name}_",
                );
                self::cleanup_repository($backup_format_db, $server_id, $domain_id, intval($rec['backup_copies']), $backup_repos_path, $prefix_list, 'mysql', $password);
            } else {
                $app->log('Failed to process mysql backup format ' . $backup_format_db . ' for database ' . $rec['database_name'], LOGLEVEL_ERROR);
            }
        }

        unset($clientdb_host);
        unset($clientdb_user);
        unset($clientdb_password);

        return $success;
    }

    public static function restoreBackupDatabaseRepos($backup_format, $password, $backup_dir, $backup_archive, $backup_mode, $backup_type)
Jorge Muñoz's avatar
Jorge Muñoz committed
    {
        global $app;

        //* Load sql dump into db
        include 'lib/mysql_clientdb.conf';

        if (empty($backup_format)) {
            $backup_format = 'borg';
        }
        $success = false;
        preg_match('@^(manual-)?db_(?P<db>.+)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$@', $backup_archive, $matches);
Jorge Muñoz's avatar
Jorge Muñoz committed
        if (!isset($matches['db']) || empty($matches['db'])) {
            $app->log('Failed to detect database name during restore of ' . $backup_archive, LOGLEVEL_ERROR);
Jorge Muñoz's avatar
Jorge Muñoz committed
            return false;
        }
        $db_name = $matches['db'];

        $backup_repos_folder = self::getBackupReposFolder($backup_format, 'mysql') . '_' . $db_name;
        $backup_repos_path = $backup_dir . DIRECTORY_SEPARATOR . $backup_repos_folder;
        $full_archive_path = $backup_repos_path . '::' . $backup_archive;
Jorge Muñoz's avatar
Jorge Muñoz committed

        $app->log('Restoring MySQL backup ' . $full_archive_path . ', backup format "' . $backup_format . '", backup mode "' . $backup_mode . '"', LOGLEVEL_DEBUG);

        $archives = self::getReposArchives($backup_format, $backup_repos_path, $password);
        if (is_array($archives) && in_array($backup_archive, $archives)) {
Jorge Muñoz's avatar
Jorge Muñoz committed
            switch ($backup_format) {
                case "borg":
                    $password_cmd = self::getPasswordCommand($backup_format, $password);
                    $command = $password_cmd . "borg extract --stdout ? stdin | mysql -h ? -u ? -p? ?";
                    break;
            }
            if (!empty($command)) {
                /** @var string $clientdb_host */
                /** @var string $clientdb_user */
                /** @var string $clientdb_password */
                $app->system->exec_safe($command, $full_archive_path, $clientdb_host, $clientdb_user, $clientdb_password, $db_name);
                $retval = $app->system->last_exec_retcode();
                if ($retval == 0) {
                    $app->log('Restored MySQL backup ' . $full_archive_path, LOGLEVEL_DEBUG);
                    $success = true;
                } else {
                    $app->log('Failed to restore web backup ' . $full_archive_path . ', exit code ' . $retval, LOGLEVEL_ERROR);
                }
            } else {
                $app->log('Archive test failed for ' . $full_archive_path, LOGLEVEL_DEBUG);
            }
        } else {
            $app->log('Failed to process MySQL backup ' . $full_archive_path . ' because it does not exist', LOGLEVEL_ERROR);
        }
        unset($clientdb_host);
        unset($clientdb_user);
        unset($clientdb_password);

        return $success;
    }

    public static function restoreBackupWebFilesRepos($backup_format, $password, $backup_dir, $backup_archive, $backup_mode, $backup_type, $web_root, $web_user, $web_group)
Jorge Muñoz's avatar
Jorge Muñoz committed
    {
        global $app;

        if (empty($backup_format) || $backup_format == 'default') {
            $backup_format = 'borg';
        }
        $backup_repos_folder = self::getBackupReposFolder($backup_format, 'web');
        $backup_repos_path = $backup_dir . DIRECTORY_SEPARATOR . $backup_repos_folder;
        $full_archive_path = $backup_repos_path . '::' . $backup_archive;
Jorge Muñoz's avatar
Jorge Muñoz committed
        $result = false;

        $app->log('Restoring web backup ' . $full_archive_path . ', backup format "' . $backup_format . '", backup mode "' . $backup_mode . '"', LOGLEVEL_DEBUG);