Ovirt

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

2017-05-18  本文已影响21人  58bc06151329

文前说明

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

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

分析整理的版本为 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
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" \
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}"
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}"
}

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

上一篇下一篇

猜你喜欢

热点阅读