美文网首页Ovirt
【Ovirt 笔记】engine-backup 的实现原理

【Ovirt 笔记】engine-backup 的实现原理

作者: 58bc06151329 | 来源:发表于2017-05-18 10:53 被阅读21次

    文前说明

    作为码农中的一员,需要不断的学习,我工作之余将一些分析总结和学习笔记写成博客与大家一起交流,也希望采用这种方式记录自己的学习之旅。

    本文仅供学习交流使用,侵权必删。
    不用于商业目的,转载请注明出处。

    分析整理的版本为 Ovirt 3.4.5 版本。

    命令使用方式:engine-backup [--mode=MODE] [--scope=SCOPE] [--file=FILE] [--log=FILE]

    MODE is one of the following:
        backup                          backup system into FILE
        restore                         restore system from FILE
     SCOPE is one of the following:
        all                             complete backup/restore (default)
        files                           files only
        db                              engine database only
        dwhdb                           dwh database only
        reportsdb                       reports database only
     --file=FILE                        file to use during backup or restore
     --log=FILE                         log file to use
     --change-db-credentials            activate the following options, to restore
                                        the Engine database to a different location
                        etc. If used, existing credentials are ignored.
     --db-host=host                     set database host
     --db-port=port                     set database port
     --db-user=user                     set database user
     --db-passfile=file                 set database password - read from file
     --db-password=pass                 set database password
     --db-password                      set database password - interactively
     --db-name=name                     set database name
     --db-secured                       set a secured connection
     --db-secured-validation            validate host
     --change-dwh-db-credentials        activate the following options, to restore
                                        the DWH database to a different location etc.
                                        If used, existing credentials are ignored.
     --dwh-db-host=host                 set dwh database host
     --dwh-db-port=port                 set dwh database port
     --dwh-db-user=user                 set dwh database user
     --dwh-db-passfile=file             set dwh database password - read from file
     --dwh-db-password=pass             set dwh database password
     --dwh-db-password                  set dwh database password - interactively
     --dwh-db-name=name                 set dwh database name
     --dwh-db-secured                   set a secured connection for dwh
     --dwh-db-secured-validation        validate host for dwh
     --change-reports-db-credentials    activate the following options, to restore
                                        the Reports database to a different location
                        etc. If used, existing credentials are ignored.
     --reports-db-host=host             set reports database host
     --reports-db-port=port             set reports database port
     --reports-db-user=user             set reports database user
     --reports-db-passfile=file         set reports database password - read from file
     --reports-db-password=pass         set reports database password
     --reports-db-password              set reports database password - interactively
     --reports-db-name=name             set reports database name
     --reports-db-secured               set a secured connection for reports
     --reports-db-secured-validation    validate host for reports
    
     ENVIRONMENT VARIABLES
    
     OVIRT_ENGINE_DATABASE_PASSWORD
         Database password as if provided by --db-password=pass option.
     OVIRT_DWH_DATABASE_PASSWORD
         Database password as if provided by --dwh-db-password=pass option.
     OVIRT_REPORTS_DATABASE_PASSWORD
         Database password as if provided by --reports-db-password=pass option.
    

    命令采用了 shell 命令方式进行实现。

    备份的目录和文件有:

    BACKUP_PATHS="/etc/ovirt-engine
    /etc/ovirt-engine-dwh
    /etc/ovirt-engine-reports
    /etc/pki/ovirt-engine
    /etc/ovirt-engine-setup.conf.d
    /var/lib/ovirt-engine-reports/build-conf
    /var/lib/ovirt-engine-reports/ovirt-engine-reports.war/WEB-INF/js.quartz.properties
    /etc/httpd/conf.d/ovirt-engine-root-redirect.conf
    /etc/httpd/conf.d/ssl.conf
    /etc/httpd/conf.d/z-ovirt-engine-proxy.conf
    /etc/httpd/conf.d/z-ovirt-engine-reports-proxy.conf
    /etc/yum/pluginconf.d/versionlock.list
    /etc/firewalld/services/ovirt-https.xml
    /etc/firewalld/services/ovirt-http.xml
    /etc/firewalld/services/ovirt-postgres.xml"
    

    备份的数据库有:

    数据库 数据库备份名称
    engine engine_backup.db.bz2
    dwh dwh_backup.db.bz2
    reports reports_backup.db.bz2
    • 备份命令如下,采用了 bzip2 压缩方式。
    pg_dump \
        -E "UTF8" \
        --disable-dollar-quoting \
        --disable-triggers \
        --format=p \
        -w \
        -U "${user}" \
        -h "${host}" \
        -p "${port}" \
        "${database}" \
        2> "${pgdump_log}" \
        | bzip2 > "${file}.bz2" \
    
    • 压缩后的.bz2中,包含的是数据库导出的所有 SQL 语句和数据。

    • 数据库连接通过读取配置文件 10-setup-database.conf

    changeEngineDBConf() {
        local conf="${ENGINE_ETC}/engine.conf.d/10-setup-database.conf"
        [ -f "${conf}" ] || logdie "Can not find ${conf}"
    
        local backup="${conf}.$(date +"%Y%m%d%H%M%S")"
        log "Backing up ${conf} to ${backup}"
        cp -a "${conf}" "${backup}" || die "Failed to backup ${conf}"
        output "Rewriting ${conf}"
        printf "%s\n" "${MY_DB_CREDS}" > "${conf}"
    }
    

    备份的目录结构:

    • 备份的目录数据库等,最终产生一个压缩包。
    tar -C "${tardir}" -cpSsjf "${backupfile}"
    
    • 恢复则是解压的过程,先对备份文件进行解压缩,根据备份文件中的路径和文件进行 mkdircp 的操作。
    mkdir tmp
    tar -C ./tmp -pSsxf ovirt-backup
    
    restoreFiles() {
        local paths="$1"
        echo "${paths}" | while read -r path; do
            local dirname="$(dirname ${path})"
            local backup="${TEMP_FOLDER}/files/${path}"
            [ -e "${backup}" ] || continue
            [ -d "${dirname}" ] || mkdir -p "${dirname}" || logdie "Cannot create directory ${dirname}"
            cp -a "${backup}" "${dirname}" || logdie "Cannot copy '${backup}' to '${dirname}'"
            if selinuxenabled; then
                restorecon -R "${path}" || logdie "Failed setting selinux context for ${path}"
            fi
        done || logdie "Cannot read ${paths}"
    }
    
    • 目录结构与备份的目录和文件保持一致。
    • md5sum 里面存储了每个文件的 md5
    • version 保存版本信息。
    • 备份目录:/var/lib/ovirt-engine/backups

    注意:engine-backup --mode=restore 要求 engine 服务是停止状态,engine 数据库为空。

    相关文章

      网友评论

        本文标题:【Ovirt 笔记】engine-backup 的实现原理

        本文链接:https://www.haomeiwen.com/subject/lkcsxxtx.html