From e8fa09f81f1434008d32218895bde8398abddd8e Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Tue, 18 Jan 2022 17:35:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=93=8D=E4=BD=9C=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/databackupproxy.cpp | 86 ++++++++++++++++---- backup-daemon/databackupproxy.h | 24 ++++-- backup-daemon/ghostimageproxy.cpp | 48 ++++++++++-- backup-daemon/ghostimageproxy.h | 4 + backup-daemon/mybackupmanager.cpp | 86 ++++++++++++++++++-- backup-daemon/systembackupproxy.cpp | 96 ++++++++++++++++++----- backup-daemon/systembackupproxy.h | 14 +++- backup-daemon/udiskdatabackupproxy.cpp | 56 ++++++++++--- backup-daemon/udiskdatabackupproxy.h | 13 ++- backup-daemon/udiskghostImageproxy.cpp | 56 +++++++++++-- backup-daemon/udiskghostImageproxy.h | 1 + backup-daemon/udisksystembackupproxy.cpp | 53 ++++++++++++- backup-daemon/udisksystembackupproxy.h | 9 ++- backup-daemon/workerfactory.cpp | 11 +-- backup-daemon/workerfactory.h | 7 +- common/mydefine.h | 4 + kybackup/backuppointlistdialog.cpp | 13 +-- kybackup/backuppointlistdialog.h | 2 +- kybackup/module/databackup.cpp | 26 ++++-- kybackup/module/datarestore.cpp | 4 +- kybackup/module/ghostimage.cpp | 19 ++++- kybackup/module/managebackuppointlist.cpp | 2 +- kybackup/module/operationlog.cpp | 5 +- kybackup/module/systembackup.cpp | 31 +++++--- 24 files changed, 538 insertions(+), 132 deletions(-) diff --git a/backup-daemon/databackupproxy.cpp b/backup-daemon/databackupproxy.cpp index 3f68a0f..6ad398b 100755 --- a/backup-daemon/databackupproxy.cpp +++ b/backup-daemon/databackupproxy.cpp @@ -12,15 +12,23 @@ IMPLEMENT_DYNCREATE(DataBackupProxy) DataBackupProxy::DataBackupProxy() { + m_isOnlyCheck = true; m_bSuccess = false; + m_isFinished = false; m_p = nullptr; m_size = 0; + m_calc = new CalcBackupSize(this); + + connect(this, &DataBackupProxy::cancel, this, &DataBackupProxy::cancelEx); } DataBackupProxy::~DataBackupProxy() { delete m_p; m_p = nullptr; + + delete m_calc; + m_calc = nullptr; } /** @@ -42,10 +50,10 @@ bool DataBackupProxy::checkEnvEx() isIncBackup(); // 3、检测空间是否满足备份 - bool result = checkFreeCapacity(); + calcSizeForBackup(); qDebug() << "DataBackupProxy::checkEnv invoke end"; - return result; + return true; } /** @@ -54,17 +62,52 @@ bool DataBackupProxy::checkEnvEx() void DataBackupProxy::doWorkEx() { qDebug() << "DataBackupProxy::doWorkEx invoke begin"; - // 环境检测 - if (!checkEnvEx()) - return ; - // 开始备份 - doBackup(); + m_isOnlyCheck = false; + // 环境检测 + checkEnvEx(); + qDebug() << "DataBackupProxy::doWorkEx invoke end"; } +/** + * @brief 取消操作 + */ void DataBackupProxy::cancelEx() -{} +{ + m_bCancel = true; + if (!m_isFinished) { + emit this->checkResult(int(BackupResult::START_CANCEL)); + + if (m_calc) + m_calc->stop(); + if (m_p) + m_p->stop(); + + QProcess::execute("sync"); + Utils::wait(5); + deleteFailedData(); + emit this->checkResult(int(BackupResult::CANCEL_SUCCESS)); + } +} + +/** + * @brief 失败则删除相应数据 + */ +void DataBackupProxy::deleteFailedData() +{ + // 1、删除备份目录 + QStringList args; + args << "-rf"; + args << m_destPath; + QProcess::execute("rm", args); + + // 2、删除xml文件中的备份项 + QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parse(xmlPath); + parse.deleteItem(m_curUuid); +} /** * @brief 判断是否增量备份 @@ -92,14 +135,17 @@ bool DataBackupProxy::isIncBackup() /** * @brief 校验剩余空间是否满足备份 */ -bool DataBackupProxy::checkFreeCapacity() +bool DataBackupProxy::checkFreeCapacity(qint64 itotalSize) { qDebug() << "DataBackupProxy::checkFreeCapacity invoke begin"; + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return false; + // 1、计算待备份数据的大小 - qint64 itotalSize = calcSizeForBackup(); m_size = itotalSize; - // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留500M的空间 + // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留5M的空间 itotalSize += 5 * MB; // 2、计算备份分区剩余空间大小 @@ -117,6 +163,12 @@ bool DataBackupProxy::checkFreeCapacity() emit checkResult(int(BackupResult::CHECK_ENV_SUCCESS)); } + if (m_isOnlyCheck) + return result; + + // 开始备份 + doBackup(); + qDebug() << "DataBackupProxy::checkFreeCapacity invoke end"; return result; } @@ -125,7 +177,7 @@ bool DataBackupProxy::checkFreeCapacity() * @brief 计算备份所需空间大小 * @return 计算备份所需空间大小,单位字节 */ -qint64 DataBackupProxy::calcSizeForBackup() +void DataBackupProxy::calcSizeForBackup() { QString destPath = Utils::getSysRootPath(); @@ -152,8 +204,8 @@ qint64 DataBackupProxy::calcSizeForBackup() args << destPath; Utils::mkpath(destPath); - CalcBackupSize calcator; - return calcator.start(args); + connect(m_calc, &CalcBackupSize::finished, this, &DataBackupProxy::checkFreeCapacity); + m_calc->start(args, false); } /** @@ -338,6 +390,11 @@ bool DataBackupProxy::backupData() m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::progress, this, &DataBackupProxy::progress); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + + m_isFinished = true; if (result) { m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING; m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath)); @@ -355,6 +412,7 @@ bool DataBackupProxy::backupData() Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName); m_bSuccess = true; } + emit this->workResult(result); }); m_p->start(args, false); diff --git a/backup-daemon/databackupproxy.h b/backup-daemon/databackupproxy.h index 31ba231..8550ce7 100755 --- a/backup-daemon/databackupproxy.h +++ b/backup-daemon/databackupproxy.h @@ -2,6 +2,7 @@ #define DATABACKUPPROXY_H #include "workerfactory.h" +#include "myprocess/calcbackupsize.h" #include "myprocess/rsyncpathtodirprocess.h" #include "parsebackuplist.h" @@ -28,15 +29,20 @@ public: // 任务处理 virtual void doWorkEx(); +public slots: // 任务取消 virtual void cancelEx(); -private: +private slots: // 校验剩余空间是否满足备份 - bool checkFreeCapacity(); + bool checkFreeCapacity(qint64 itotalSize); + // 备份 + void doBackup(); + +private: // 计算备份所需空间大小 - qint64 calcSizeForBackup(); + void calcSizeForBackup(); /** * @brief 记录/backup/snapshots/backuplist.xml文件 @@ -47,9 +53,6 @@ private: // 备份准备 bool doPrepare(); - // 备份 - void doBackup(); - // 备份系统 bool backupData(); @@ -66,7 +69,16 @@ protected: void do_kylin_security(const QString& dstDir); + // 失败则删除相应数据 + virtual void deleteFailedData(); + + // 计算备份空间大小的进程 + CalcBackupSize *m_calc; + // 是否只是检测 + bool m_isOnlyCheck; // 是否完成 + bool m_isFinished; + // 是否成功 bool m_bSuccess; // 当前备份uuid QString m_curUuid; diff --git a/backup-daemon/ghostimageproxy.cpp b/backup-daemon/ghostimageproxy.cpp index 0c39aea..9a55792 100755 --- a/backup-daemon/ghostimageproxy.cpp +++ b/backup-daemon/ghostimageproxy.cpp @@ -16,6 +16,9 @@ GhostImageProxy::GhostImageProxy() { m_mksquashfs = nullptr; m_bSuccess = false; + m_isFinished = false; + + connect(this, &GhostImageProxy::cancel, this, &GhostImageProxy::cancelEx); } GhostImageProxy::~GhostImageProxy() @@ -91,7 +94,31 @@ void GhostImageProxy::doWorkEx() * @brief 任务取消 */ void GhostImageProxy::cancelEx() -{} +{ + m_bCancel = true; + if (!m_isFinished) { + emit this->checkResult(int(BackupResult::START_CANCEL)); + + if (m_mksquashfs) + m_mksquashfs->stop(); + + QProcess::execute("sync"); + Utils::wait(5); + deleteFailedData(); + emit this->checkResult(int(BackupResult::CANCEL_SUCCESS)); + } +} + +/** + * @brief 失败则删除相应数据 + */ +void GhostImageProxy::deleteFailedData() +{ + // 1、删除镜像文件 + QFile kyimg(m_kyimg); + if (kyimg.exists()) + kyimg.remove(); +} /** * @brief ghost镜像 @@ -108,15 +135,20 @@ void GhostImageProxy::doGhostImage() m_mksquashfs = new MkSquashFSProcess(this); connect(m_mksquashfs, &MkSquashFSProcess::progress, this, &GhostImageProxy::progress); connect(m_mksquashfs, &MkSquashFSProcess::finished, this, [&](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + + m_isFinished = true; if (result) { chown(m_kyimg.toLocal8Bit().data(), m_backupWrapper.m_frontUid, m_backupWrapper.m_gid); - QFileInfo fileInfo(m_kyimg); - QString imgSize = Utils::StringBySize(fileInfo.size()); - QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"); - Utils::writeBackupLog(time + "," - + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + "," - + m_backupWrapper.m_note + "," + imgSize - + ",," + m_backupWrapper.m_backupName); +// QFileInfo fileInfo(m_kyimg); +// QString imgSize = Utils::StringBySize(fileInfo.size()); +// QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"); +// Utils::writeBackupLog(time + "," +// + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + "," +// + m_backupWrapper.m_note + "," + imgSize +// + ",," + m_backupWrapper.m_backupName); m_bSuccess = true; } emit this->workResult(result); diff --git a/backup-daemon/ghostimageproxy.h b/backup-daemon/ghostimageproxy.h index 6ee70c4..664ed93 100755 --- a/backup-daemon/ghostimageproxy.h +++ b/backup-daemon/ghostimageproxy.h @@ -27,6 +27,8 @@ public: private: void doGhostImage(); + void deleteFailedData(); + // 存放.kyimg文件的目录 QString m_destPath; // .kyimg文件 @@ -37,6 +39,8 @@ private: // 是否成功 bool m_bSuccess; + // 是否完成 + bool m_isFinished; }; #endif // GHOSTIMAGEPROXY_H diff --git a/backup-daemon/mybackupmanager.cpp b/backup-daemon/mybackupmanager.cpp index b547303..71bca02 100755 --- a/backup-daemon/mybackupmanager.cpp +++ b/backup-daemon/mybackupmanager.cpp @@ -3,6 +3,7 @@ */ #include +#include #include #include #include @@ -10,6 +11,7 @@ #include "../common/utils.h" #include "mymountproxy.h" #include "workerfactory.h" +#include "parsebackuplist.h" /** * @brief 构造函数 @@ -131,6 +133,7 @@ int MyBackupManager::goBackup(const BackupWrapper& backupWrapper) case int(BackupResult::CHECK_ENV_SUCCESS) : case int(BackupResult::MKSQUASHFS_START_SUCCESS) : case int(BackupResult::BACKUP_START_SUCCESS) : + case int(BackupResult::START_CANCEL) : break; default: this->finished(); @@ -265,6 +268,7 @@ int MyBackupManager::ghostBackup(const BackupWrapper& backupWrapper) case int(BackupResult::CHECK_ENV_SUCCESS) : case int(BackupResult::MKSQUASHFS_START_SUCCESS) : case int(BackupResult::GHOST_START_SUCCESS) : + case int(BackupResult::START_CANCEL) : break; default: this->finished(); @@ -299,13 +303,75 @@ int MyBackupManager::ghostBackup(const BackupWrapper& backupWrapper) */ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid) { - Q_UNUSED(autobackup_name) - Q_UNUSED(create_note) - Q_UNUSED(inc_note) - Q_UNUSED(frontUserName) - Q_UNUSED(frontUid) + qDebug("MyBackupManager::autoBackUpForSystemUpdate_noreturn invoke begin"); - return ; + if (m_isActive || !lock(frontUid)) { + emit sendStartBackupResult(int(BackupResult::LOCK_PROGRAM_FAIL)); + return ; + } + + BackupWrapper backupWrapper; + backupWrapper.m_uuid = AUTO_BACKUP_UUID; + QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parseXml(xmlPath); + ParseBackupList::BackupPoint backupPoint = parseXml.findBackupPointByUuid(backupWrapper.m_uuid); + if (autobackup_name.isEmpty()) { + if (backupPoint.m_backupName.isEmpty()) + backupWrapper.m_backupName = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"); + else + backupWrapper.m_backupName = backupPoint.m_backupName; + } else { + backupWrapper.m_backupName = autobackup_name; + } + backupWrapper.m_backupPaths << "/"; + backupWrapper.m_backupExcludePaths = Utils::getFromExcludePathsFile(); + backupWrapper.m_type = BackupType::BACKUP_SYSTEM; + backupWrapper.m_iPosition = BackupPosition::LOCAL; + backupWrapper.m_frontUserName = frontUserName; + backupWrapper.m_frontUid = frontUid; + backupWrapper.m_note = create_note.isEmpty() ? inc_note : create_note; + + Worker* worker = WorkerFactory::createWorker(backupWrapper.m_type, backupWrapper.m_iPosition); + if (nullptr == worker) { + emit sendStartBackupResult(int(BackupResult::NO_FOUND_DEALCLASS)); + return ; + } + + worker->setParam(backupWrapper); + connect(worker, &Worker::checkResult, this, [&](int result) { + emit this->sendStartBackupResult(result); + + switch (result) { + case int(BackupResult::CHECK_ENV_SUCCESS) : + case int(BackupResult::MKSQUASHFS_START_SUCCESS) : + case int(BackupResult::BACKUP_START_SUCCESS) : + break; + default: + this->finished(); + if (!Utils::isRunning("kybackup")) { + this->umountBackupPartition(); + } + break; + } + }); + connect(worker, &Worker::progress, this, [&](int rate) { + emit this->sendRate(int(BackupState::WORKING), rate); + }); + connect(worker, &Worker::workResult, this, [&] (bool result) { + emit this->sendBackupResult(result); + this->finished(); + if (!Utils::isRunning("kybackup")) { + this->umountBackupPartition(); + } + }); + worker->moveToThread(&workerThread); + connect(&workerThread, &MyThread::started, worker, &Worker::doWork); + connect(&workerThread, &MyThread::finished, worker, &Worker::deleteLater); + + workerThread.start(); + + qDebug("MyBackupManager::autoBackUpForSystemUpdate_noreturn invoke end"); } /** @@ -315,8 +381,12 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback */ QString MyBackupManager::getBackupCommentForSystemUpdate(QString& state) { - Q_UNUSED(state) - return ""; + QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parseXml(xmlPath); + ParseBackupList::BackupPoint backupPoint = parseXml.findBackupPointByUuid(AUTO_BACKUP_UUID); + state = backupPoint.m_state; + return backupPoint.m_backupName; } /** diff --git a/backup-daemon/systembackupproxy.cpp b/backup-daemon/systembackupproxy.cpp index 2bd5534..9c80bf4 100755 --- a/backup-daemon/systembackupproxy.cpp +++ b/backup-daemon/systembackupproxy.cpp @@ -13,19 +13,27 @@ IMPLEMENT_DYNCREATE(SystemBackupProxy) SystemBackupProxy::SystemBackupProxy() { m_bSuccess = false; + m_isFinished = false; m_p = nullptr; m_size = 0; + m_isOnlyCheck = true; + m_calc = new CalcBackupSize(this); + + connect(this, &SystemBackupProxy::cancel, this, &SystemBackupProxy::cancelEx); } SystemBackupProxy::~SystemBackupProxy() { delete m_p; m_p = nullptr; + + delete m_calc; + m_calc = nullptr; } /** * @brief 环境检测 - * @return false,检测失败;true,检测成功 + * @return */ bool SystemBackupProxy::checkEnvEx() { @@ -42,10 +50,10 @@ bool SystemBackupProxy::checkEnvEx() isIncBackup(); // 3、检测空间是否满足备份 - bool result = checkFreeCapacity(); + calcSizeForBackup(); qDebug() << "SystemBackupProxy::checkEnv invoke end"; - return result; + return true; } /** @@ -54,17 +62,51 @@ bool SystemBackupProxy::checkEnvEx() void SystemBackupProxy::doWorkEx() { qDebug() << "SystemBackupProxy::doWorkEx invoke begin"; - // 环境检测 - if (!checkEnvEx()) - return ; - // 开始备份 - doBackup(); + // 环境检测 + checkEnvEx(); + qDebug() << "SystemBackupProxy::doWorkEx invoke end"; } +/** + * @brief 取消操作 + */ void SystemBackupProxy::cancelEx() -{} +{ + m_bCancel = true; + if (!m_isFinished) { + emit this->checkResult(int(BackupResult::START_CANCEL)); + + if (m_calc) + m_calc->stop(); + if (m_p) + m_p->stop(); + + QProcess::execute("sync"); + Utils::wait(5); + deleteFailedData(); + emit this->checkResult(int(BackupResult::CANCEL_SUCCESS)); + } +} + +/** + * @brief 失败则删除相应数据 + */ +void SystemBackupProxy::deleteFailedData() +{ + // 1、删除备份目录 + QStringList args; + args << "-rf"; + args << m_destPath; + QProcess::execute("rm", args); + + // 2、删除xml文件中的备份项 + QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parse(xmlPath); + parse.deleteItem(m_curUuid); +} /** * @brief 判断是否增量备份 @@ -99,12 +141,15 @@ bool SystemBackupProxy::isIncBackup() /** * @brief 校验剩余空间是否满足备份 */ -bool SystemBackupProxy::checkFreeCapacity() +void SystemBackupProxy::checkFreeCapacity(qint64 itotalSize) { qDebug() << "SystemBackupProxy::checkFreeCapacity invoke begin"; + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + // 1、计算待备份数据的大小 - qint64 itotalSize = calcSizeForBackup(); m_size = itotalSize; // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留500M的空间 itotalSize += 500 * MB; @@ -116,23 +161,27 @@ bool SystemBackupProxy::checkFreeCapacity() qint64 freeSize = backupDisk.bytesAvailable(); // 3、校验空间是否足够 - bool result = true; if (itotalSize > freeSize) { emit checkResult(int(BackupResult::BACKUP_CAPACITY_IS_NOT_ENOUGH)); - result = false; } else { emit checkResult(int(BackupResult::CHECK_ENV_SUCCESS)); } + // 仅仅校验,不进行备份 + if (m_isOnlyCheck) + return ; + + // 4、开始备份 + doBackup(); + qDebug() << "SystemBackupProxy::checkFreeCapacity invoke end"; - return result; } /** * @brief 计算备份所需空间大小 - * @return 计算备份所需空间大小,单位字节 + * @return */ -qint64 SystemBackupProxy::calcSizeForBackup() +void SystemBackupProxy::calcSizeForBackup() { QString destPath = Utils::getSysRootPath(); @@ -165,8 +214,8 @@ qint64 SystemBackupProxy::calcSizeForBackup() args << destPath; Utils::mkpath(destPath); - CalcBackupSize calcator; - return calcator.start(args); + connect(m_calc, &CalcBackupSize::finished, this, &SystemBackupProxy::checkFreeCapacity); + m_calc->start(args, false); } /** @@ -304,7 +353,7 @@ bool SystemBackupProxy::doPrepare() userFile.replace("//", "/"); if (!Utils::writeFileByLines(userFile, m_backupWrapper.m_backupPaths)) { emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); - qCritical() << QString("create file %1 failed !").arg(userFile) ; + qCritical() << QString("create file %1 failed !").arg(userFile); return false; } @@ -312,7 +361,7 @@ bool SystemBackupProxy::doPrepare() excludeUserFile.replace("//", "/"); if (!Utils::writeFileByLines(excludeUserFile, m_backupWrapper.m_backupExcludePaths)) { emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); - qCritical() << QString("create file %1 failed !").arg(excludeUserFile) ; + qCritical() << QString("create file %1 failed !").arg(excludeUserFile); return false; } @@ -423,9 +472,14 @@ bool SystemBackupProxy::backupSystem() m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::progress, this, &SystemBackupProxy::progress); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + + m_isFinished = true; if (result) { m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING; - // m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath)); + m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath)); QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; xmlPath.replace("//", "/"); ParseBackupList parse(xmlPath); diff --git a/backup-daemon/systembackupproxy.h b/backup-daemon/systembackupproxy.h index fbb9bdf..58b30f1 100755 --- a/backup-daemon/systembackupproxy.h +++ b/backup-daemon/systembackupproxy.h @@ -2,6 +2,7 @@ #define SYSTEMBACKUPPROXY_H #include "workerfactory.h" +#include "myprocess/calcbackupsize.h" #include "myprocess/rsyncpathtodirprocess.h" #include "parsebackuplist.h" @@ -39,10 +40,10 @@ private: bool isIncBackup(); // 校验剩余空间是否满足备份 - bool checkFreeCapacity(); + void checkFreeCapacity(qint64 itotalSize); // 计算备份所需空间大小 - qint64 calcSizeForBackup(); + void calcSizeForBackup(); /** * @brief 根据场景获取rsync命令参数 @@ -71,14 +72,23 @@ private: void do_kylin_security(const QString& dstDir); + // 失败则删除相应数据 + void deleteFailedData(); + + // 是否只是检测 + bool m_isOnlyCheck; // 是否备份成功 bool m_bSuccess; + // 是否完成 + bool m_isFinished; // 当前备份uuid QString m_curUuid; // 当前备份目标目录 QString m_destPath; // 当前备份所需空间大小 qint64 m_size; + // 计算备份空间大小的进程 + CalcBackupSize *m_calc; // 备份进程 RsyncPathToDirProcess *m_p; // 当前备份节点 diff --git a/backup-daemon/udiskdatabackupproxy.cpp b/backup-daemon/udiskdatabackupproxy.cpp index 3006bff..19532c9 100755 --- a/backup-daemon/udiskdatabackupproxy.cpp +++ b/backup-daemon/udiskdatabackupproxy.cpp @@ -13,20 +13,10 @@ IMPLEMENT_DYNCREATE(UDiskDataBackupProxy) UDiskDataBackupProxy::UDiskDataBackupProxy() { - m_isFinished = false; - m_bSuccess = false; - m_p = nullptr; - m_size = 0; - m_calc = new CalcBackupSize(this); - m_isOnlyCheck = true; } UDiskDataBackupProxy::~UDiskDataBackupProxy() { - delete m_p; - m_p = nullptr; - delete m_calc; - m_calc = nullptr; } /** @@ -86,8 +76,44 @@ void UDiskDataBackupProxy::doWorkEx() qDebug() << "UDiskDataBackupProxy::doWorkEx invoke end"; } +/** + * @brief 取消操作 + */ void UDiskDataBackupProxy::cancelEx() -{} +{ + m_bCancel = true; + if (!m_isFinished) { + emit this->checkResult(int(BackupResult::START_CANCEL)); + + if (m_calc) + m_calc->stop(); + if (m_p) + m_p->stop(); + + QProcess::execute("sync"); + Utils::wait(5); + deleteFailedData(); + emit this->checkResult(int(BackupResult::CANCEL_SUCCESS)); + } +} + +/** + * @brief 失败则删除相应数据 + */ +void UDiskDataBackupProxy::deleteFailedData() +{ + // 1、删除备份目录 + QStringList args; + args << "-rf"; + args << m_destPath; + QProcess::execute("rm", args); + + // 2、删除xml文件中的备份项 + QString xmlPath = m_backupWrapper.m_prefixDestPath + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parse(xmlPath); + parse.deleteItem(m_curUuid); +} /** * @brief 校验剩余空间是否满足备份 @@ -96,6 +122,10 @@ bool UDiskDataBackupProxy::checkFreeCapacityToUdisk(qint64 itotalSize) { qDebug() << "UDiskDataBackupProxy::checkFreeCapacityToUdisk invoke begin"; + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return false; + // 1、计算待备份数据的大小 m_size = itotalSize; // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留500M的空间 @@ -296,6 +326,10 @@ bool UDiskDataBackupProxy::backupDataToUdisk() m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::progress, this, &UDiskDataBackupProxy::progress); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + m_isFinished = true; if (result) { m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING; diff --git a/backup-daemon/udiskdatabackupproxy.h b/backup-daemon/udiskdatabackupproxy.h index d64b0bf..df9a8af 100755 --- a/backup-daemon/udiskdatabackupproxy.h +++ b/backup-daemon/udiskdatabackupproxy.h @@ -2,7 +2,6 @@ #define UDISKDATABACKUPPROXY_H #include "databackupproxy.h" -#include "myprocess/calcbackupsize.h" class UDiskDataBackupProxy : public DataBackupProxy { @@ -19,6 +18,7 @@ public: // 任务处理 virtual void doWorkEx(); +public slots: // 任务取消 virtual void cancelEx(); @@ -39,6 +39,10 @@ private slots: */ bool checkDestDirExists(); +protected: + // 失败则删除相应数据 + virtual void deleteFailedData(); + private: // 计算备份所需空间大小 void calcSizeForBackupToUdisk(); @@ -54,13 +58,6 @@ private: // 备份系统 bool backupDataToUdisk(); - - // 计算备份空间大小的进程 - CalcBackupSize *m_calc; - // 是否只是检测 - bool m_isOnlyCheck; - // 是否完成 - bool m_isFinished; }; #endif // UDISKDATABACKUPPROXY_H diff --git a/backup-daemon/udiskghostImageproxy.cpp b/backup-daemon/udiskghostImageproxy.cpp index f4972a0..f9d9074 100755 --- a/backup-daemon/udiskghostImageproxy.cpp +++ b/backup-daemon/udiskghostImageproxy.cpp @@ -19,6 +19,8 @@ UDiskGhostImageProxy::UDiskGhostImageProxy() m_p = nullptr; m_bSuccess = false; m_isFinished = false; + + connect(this, &UDiskGhostImageProxy::cancel, this, &UDiskGhostImageProxy::cancelEx); } UDiskGhostImageProxy::~UDiskGhostImageProxy() @@ -135,7 +137,34 @@ void UDiskGhostImageProxy::doWorkEx() * @brief 任务取消 */ void UDiskGhostImageProxy::cancelEx() -{} +{ + m_bCancel = true; + if (!m_isFinished) { + emit this->checkResult(int(BackupResult::START_CANCEL)); + + if (m_mksquashfs) + m_mksquashfs->stop(); + if (m_p) + m_p->stop(); + + QProcess::execute("sync"); + Utils::wait(5); + deleteFailedData(); + emit this->checkResult(int(BackupResult::CANCEL_SUCCESS)); + } +} + +/** + * @brief 失败则删除相应数据 + */ +void UDiskGhostImageProxy::deleteFailedData() +{ + // 1、删除镜像文件 + QFile kyimg(m_kyimg); + if (kyimg.exists()) + kyimg.remove(); +} + /** * @brief ghost镜像 @@ -152,23 +181,34 @@ void UDiskGhostImageProxy::doGhostImage() m_mksquashfs = new MkSquashFSProcess(this); connect(m_mksquashfs, &MkSquashFSProcess::progress, this, &UDiskGhostImageProxy::progress); connect(m_mksquashfs, &MkSquashFSProcess::finished, this, [&](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + if (result) { chown(m_kyimg.toLocal8Bit().data(), m_backupWrapper.m_frontUid, m_backupWrapper.m_gid); // 同步到U盘 m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool resultRsync) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + m_isFinished = true; if (resultRsync) { - QFileInfo fileInfo(m_kyimg); - QString imgSize = Utils::StringBySize(fileInfo.size()); - QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"); - Utils::writeBackupLog(time + "," - + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + "," - + m_backupWrapper.m_note + "," + imgSize - + ",," + m_backupWrapper.m_backupName); +// QFileInfo fileInfo(m_kyimg); +// QString imgSize = Utils::StringBySize(fileInfo.size()); +// QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss"); +// Utils::writeBackupLog(time + "," +// + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + "," +// + m_backupWrapper.m_note + "," + imgSize +// + ",," + m_backupWrapper.m_backupName); m_bSuccess = true; } + QFile kyimg(m_kyimg); + if (kyimg.exists()) + kyimg.remove(); emit this->workResult(resultRsync); }); diff --git a/backup-daemon/udiskghostImageproxy.h b/backup-daemon/udiskghostImageproxy.h index 02630c6..761d457 100755 --- a/backup-daemon/udiskghostImageproxy.h +++ b/backup-daemon/udiskghostImageproxy.h @@ -27,6 +27,7 @@ public: private: void doGhostImage(); bool checkDestDirExists(); + void deleteFailedData(); // 存放.kyimg文件的目录 QString m_destPath; diff --git a/backup-daemon/udisksystembackupproxy.cpp b/backup-daemon/udisksystembackupproxy.cpp index d02d796..bd35f37 100755 --- a/backup-daemon/udisksystembackupproxy.cpp +++ b/backup-daemon/udisksystembackupproxy.cpp @@ -21,6 +21,8 @@ UDiskSystemBackupProxy::UDiskSystemBackupProxy() m_calc = new CalcBackupSize(this); m_isOnlyCheck = true; m_mksquashfs = nullptr; + + connect(this, &UDiskSystemBackupProxy::cancel, this, &UDiskSystemBackupProxy::cancelEx); } UDiskSystemBackupProxy::~UDiskSystemBackupProxy() @@ -41,7 +43,7 @@ UDiskSystemBackupProxy::~UDiskSystemBackupProxy() /** * @brief 环境检测 - * @return false,检测失败;true,检测成功 + * @return */ bool UDiskSystemBackupProxy::checkEnvEx() { @@ -93,7 +95,42 @@ void UDiskSystemBackupProxy::doWorkEx() } void UDiskSystemBackupProxy::cancelEx() -{} +{ + m_bCancel = true; + if (!m_isFinished) { + emit this->checkResult(int(BackupResult::START_CANCEL)); + + if (m_calc) + m_calc->stop(); + if (m_mksquashfs) + m_mksquashfs->stop(); + if (m_p) + m_p->stop(); + + QProcess::execute("sync"); + Utils::wait(5); + deleteFailedData(); + emit this->checkResult(int(BackupResult::CANCEL_SUCCESS)); + } +} + +/** + * @brief 失败则删除相应数据 + */ +void UDiskSystemBackupProxy::deleteFailedData() +{ + // 1、删除备份目录 + QStringList args; + args << "-rf"; + args << m_destPath; + QProcess::execute("rm", args); + + // 2、删除xml文件中的备份项 + QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; + xmlPath.replace("//", "/"); + ParseBackupList parse(xmlPath); + parse.deleteItem(m_curUuid); +} /** * @brief 判断是否增量备份 @@ -132,6 +169,10 @@ void UDiskSystemBackupProxy::checkFreeCapacity(qint64 itotalSize) { qDebug() << "UDiskSystemBackupProxy::checkFreeCapacity invoke begin"; + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + // 1、计算待备份数据的大小 m_size = itotalSize; // 备份过程中会有一些临时文件产生,会占用一部分空间,故我们预留500M的空间 @@ -267,6 +308,10 @@ void UDiskSystemBackupProxy::doMksqushfs() m_mksquashfs = new MkSquashFSProcess(this); connect(m_mksquashfs, &MkSquashFSProcess::progress, this, &UDiskSystemBackupProxy::progress); connect(m_mksquashfs, &MkSquashFSProcess::finished, this, [=](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + if (result) { // 开始备份 doBackup(); @@ -456,6 +501,10 @@ bool UDiskSystemBackupProxy::backup(const QStringList &args) m_p = new RsyncPathToDirProcess(this); connect(m_p, &RsyncPathToDirProcess::progress, this, &UDiskSystemBackupProxy::progress); connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { + // 如果是取消了操作,则不再发送其它信息 + if (m_bCancel) + return ; + m_isFinished = true; if (result) { m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING; diff --git a/backup-daemon/udisksystembackupproxy.h b/backup-daemon/udisksystembackupproxy.h index 84fddd5..ead5126 100755 --- a/backup-daemon/udisksystembackupproxy.h +++ b/backup-daemon/udisksystembackupproxy.h @@ -31,9 +31,6 @@ public: // 任务处理 virtual void doWorkEx(); - // 任务取消 - virtual void cancelEx(); - signals: private slots: @@ -46,6 +43,9 @@ private slots: // 备份 void doBackup(); + // 任务取消 + virtual void cancelEx(); + /** * @brief 校验移动盘是否还在 * @return: bool,存在返回true;不存在返回false @@ -89,6 +89,9 @@ private: void do_kylin_security(const QString& dstDir); + // 失败则删除相应数据 + void deleteFailedData(); + // 计算备份空间大小的进程 CalcBackupSize *m_calc; // 压缩进程 diff --git a/backup-daemon/workerfactory.cpp b/backup-daemon/workerfactory.cpp index 09c39d1..9b5fe82 100755 --- a/backup-daemon/workerfactory.cpp +++ b/backup-daemon/workerfactory.cpp @@ -2,7 +2,8 @@ #include Worker::Worker() : - QObject(nullptr) + QObject(nullptr), + m_bCancel(false) {} Worker::~Worker() @@ -25,14 +26,6 @@ void Worker::doWork() doWorkEx(); } -/** - * @brief 任务取消 - */ -void Worker::cancel() -{ - cancelEx(); -} - // 环境检测,个性化部分派生类去实现 bool Worker::checkEnvEx() { diff --git a/backup-daemon/workerfactory.h b/backup-daemon/workerfactory.h index ed18545..b827721 100755 --- a/backup-daemon/workerfactory.h +++ b/backup-daemon/workerfactory.h @@ -22,6 +22,8 @@ signals: void progress(int currentRate); // 工作结果信号 void workResult(bool result); + // 任务取消 + void cancel(); public slots: // 环境检测 @@ -30,9 +32,6 @@ public slots: // 任务处理 void doWork(); - // 任务取消 - void cancel(); - protected: // 环境检测,个性化部分派生类去实现 virtual bool checkEnvEx(); @@ -49,6 +48,8 @@ public: public: // 同一时间只能运行一个备份/还原等操作 BackupWrapper m_backupWrapper; + // 是否取消操作 + bool m_bCancel; }; /** diff --git a/common/mydefine.h b/common/mydefine.h index 65bd0ff..3838b96 100755 --- a/common/mydefine.h +++ b/common/mydefine.h @@ -267,6 +267,10 @@ enum class BackupResult { MKSQUASHFS_START_SUCCESS, // mksquashfs压缩img文件失败 MKSQUASHFS_DO_FAIL, + // 开始取消操作 + START_CANCEL, + // 取消操作成功 + CANCEL_SUCCESS, }; #endif // MYDEFINE_H diff --git a/kybackup/backuppointlistdialog.cpp b/kybackup/backuppointlistdialog.cpp index 9482e8b..93be8dd 100755 --- a/kybackup/backuppointlistdialog.cpp +++ b/kybackup/backuppointlistdialog.cpp @@ -34,15 +34,18 @@ BackupPointListDialog::BackupPointListDialog(QWidget *parent, bool isOnlyShowLoc QStringList headerLabels; // 注意:此处的列需要和枚举Column_Index一一对应 - headerLabels << tr("Backup Name") << tr("UUID") << tr("Backup Time") << tr("Backup Size") << tr("Backup Device") << QObject::tr("Backup State") << QObject::tr("PrefixPath"); + headerLabels << tr("Backup Name") << tr("UUID") << tr("Backup Time") << tr("Backup Size") << tr("Position") << QObject::tr("Backup State") << QObject::tr("PrefixPath"); m_tableWidget = new QTableWidget; m_tableWidget->setColumnCount(headerLabels.size()); m_tableWidget->setHorizontalHeaderLabels(headerLabels); m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); - m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); -// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Name, QHeaderView::Stretch); -// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::UUID, QHeaderView::Stretch); -// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Device, QHeaderView::Stretch); +// m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 300); + m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 320); + m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Time, 150); + m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Size, 120); + m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Device, QHeaderView::Stretch); + m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_State, 150); m_tableWidget->horizontalHeader()->setTextElideMode( Qt::ElideRight); m_tableWidget->horizontalHeader()->setFixedHeight(30); m_tableWidget->verticalHeader()->setHidden(true); // 好像隐藏不掉 diff --git a/kybackup/backuppointlistdialog.h b/kybackup/backuppointlistdialog.h index e82a806..1af8d85 100755 --- a/kybackup/backuppointlistdialog.h +++ b/kybackup/backuppointlistdialog.h @@ -22,7 +22,7 @@ public: UUID, Backup_Time, Backup_Size, - Backup_Device, + Backup_Device, // 即备份位置Position Backup_State, Prefix_Path }; diff --git a/kybackup/module/databackup.cpp b/kybackup/module/databackup.cpp index a8c2b27..f440e72 100755 --- a/kybackup/module/databackup.cpp +++ b/kybackup/module/databackup.cpp @@ -1235,8 +1235,6 @@ void DataBackup::initFifthWidget() labelTip->setIsOriginal(true); labelTip->setFontWordWrap(true); labelTip->setMinimumWidth(700); - // 不要使用电脑,以防数据丢失 - labelTip->setDeplayText(tr("Do not use computers in case of data loss")); hlayoutCenterFont2->addStretch(); hlayoutCenterFont2->addWidget(labelTip); hlayoutCenterFont2->addStretch(); @@ -1247,7 +1245,6 @@ void DataBackup::initFifthWidget() MyPushButton *cancel = new MyPushButton(fifth); cancel->setFixedSize(97, 36); cancel->setText(tr("cancel")); - cancel->setEnabled(true); cancel->setAutoRepeat(true); hlayoutCenterFont3->addStretch(); hlayoutCenterFont3->addWidget(cancel); @@ -1277,6 +1274,9 @@ void DataBackup::initFifthWidget() connect(this, &DataBackup::startBackup, this, [=] { progressBar->setPersent(0); movie->start(); + // 不要使用电脑,以防数据丢失 + labelTip->setDeplayText(tr("Do not use computers in case of data loss")); + cancel->setEnabled(true); // 开始备份 this->on_backup_start(); @@ -1291,7 +1291,13 @@ void DataBackup::initFifthWidget() // 取消备份 connect(cancel, &MyPushButton::clicked, this, [=](bool checked) { Q_UNUSED(checked) - // TODO + // 确定取消当前操作? + if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"), QObject::tr("Are you sure to cancel the operation?"), QObject::tr("Ok"), QObject::tr("Cancel"))) { + return ; + } + cancel->setEnabled(false); + if (m_pInterface) + m_pInterface->cancel(); }); addWidget(fifth); @@ -1359,7 +1365,7 @@ void DataBackup::on_checkBackup_end(int result) break; case int(BackupResult::BACKUP_CAPACITY_IS_NOT_ENOUGH): // 备份空间不足 - errMsg = tr("The storage for backup is not enough."); + errMsg = tr("The storage for backup is not enough"); // 建议释放空间后重试 errTip = tr("Retry after release space"); break; @@ -1373,10 +1379,16 @@ void DataBackup::on_checkBackup_end(int result) case int(BackupResult::WRITE_STORAGEINFO_ADD_ITEM_FAIL): case int(BackupResult::WRITE_STORAGEINFO_UPDATE_ITEM_FAIL): // 创建备份点目录失败 - errMsg = tr("Failed to create the backup point directory."); + errMsg = tr("Failed to create the backup point directory"); // 请检查备份目录是否有写权限 errTip = tr("Please check backup partition permissions"); break; + case int(BackupResult::CANCEL_SUCCESS): + // 已经取消本次备份 + errMsg = tr("The backup had been canceled"); + // 如需要可重新发起备份 + errTip = tr("Re-initiate the backup if necessary"); + break; default: bRst = true; break; @@ -1566,7 +1578,7 @@ void DataBackup::initLastWidget() QIcon icon = QIcon::fromTheme("dialog-error.png", QIcon(":/symbos/dialog-error.png")); resultLogo->setPixmap(icon.pixmap(QSize(20,20))); resultLogo->setVisible(true); - // 环境校验失败 + // 备份失败 bigTitle->setDeplayText(tr("The backup is failed")); dot1->setVisible(true); dot2->setVisible(true); diff --git a/kybackup/module/datarestore.cpp b/kybackup/module/datarestore.cpp index 52966fc..63e53b6 100755 --- a/kybackup/module/datarestore.cpp +++ b/kybackup/module/datarestore.cpp @@ -170,8 +170,8 @@ void DataRestore::on_button_beginRestore_clicked(bool checked) selectRestoreDialog->deleteLater(); return ; } else if (checkIsNeedReboot()){ - // 包含用户家目录,还原完成后将自动重启 - if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"), QObject::tr("Contains the user's home directory, which will automatically reboot after restoration"), QObject::tr("Continue"), QObject::tr("Cancel"))) { + // 包含用户家目录,还原完成后需要重启 + if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"), QObject::tr("Contains the user's home directory, which need to reboot after restoration"), QObject::tr("Continue"), QObject::tr("Cancel"))) { selectRestoreDialog->deleteLater(); return ; } diff --git a/kybackup/module/ghostimage.cpp b/kybackup/module/ghostimage.cpp index 8d93c7a..2a3274f 100755 --- a/kybackup/module/ghostimage.cpp +++ b/kybackup/module/ghostimage.cpp @@ -690,8 +690,6 @@ void GhostImage::initForthWidget() labelTip->setIsOriginal(true); labelTip->setFontWordWrap(true); labelTip->setMinimumWidth(700); - // 不要使用电脑,以防数据丢失 - labelTip->setDeplayText(tr("Do not use computers in case of data loss")); hlayoutCenterFont2->addStretch(); hlayoutCenterFont2->addWidget(labelTip); hlayoutCenterFont2->addStretch(); @@ -749,8 +747,11 @@ void GhostImage::initForthWidget() connect(this, &GhostImage::startGhost, this, [=] { progressBar->setPersent(0); movie->start(); + // 不要使用电脑,以防数据丢失 + labelTip->setDeplayText(tr("Do not use computers in case of data loss")); labelTip_1->setVisible(false); labelTip_1->setDeplayText(""); + cancel->setEnabled(true); // 开始备份 this->on_ghost_start(); @@ -765,7 +766,13 @@ void GhostImage::initForthWidget() // 取消备份 connect(cancel, &MyPushButton::clicked, this, [=](bool checked) { Q_UNUSED(checked) - // TODO + // 确定取消当前操作? + if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"), QObject::tr("Are you sure to cancel the operation?"), QObject::tr("Ok"), QObject::tr("Cancel"))) { + return ; + } + cancel->setEnabled(false); + if (m_pInterface) + m_pInterface->cancel(); }); addWidget(forth); @@ -867,6 +874,12 @@ void GhostImage::on_checkGhost_end(int result) // 请检查刚刚是否有删除备份点操作 errTip = tr("Check whether the backup point has been deleted"); break; + case int(BackupResult::CANCEL_SUCCESS): + // 已经取消本次镜像制作 + errMsg = tr("The image creation had been canceled"); + // 如需要可重新发起镜像制作 + errTip = tr("Re-initiate the image creation if necessary"); + break; default: bRst = true; break; diff --git a/kybackup/module/managebackuppointlist.cpp b/kybackup/module/managebackuppointlist.cpp index dc2e768..5c4215e 100755 --- a/kybackup/module/managebackuppointlist.cpp +++ b/kybackup/module/managebackuppointlist.cpp @@ -20,7 +20,7 @@ ManageBackupPointList::ManageBackupPointList(QWidget *parent, BackupPointType ba } // 隐藏备份点大小Backup Size字段 - m_tableWidget->hideColumn(Column_Index::Backup_Size); + // m_tableWidget->hideColumn(Column_Index::Backup_Size); initTableWidget(); // 您可以删除不需要的备份,更多细节请参考“操作日志” diff --git a/kybackup/module/operationlog.cpp b/kybackup/module/operationlog.cpp index d5215b3..05fecba 100755 --- a/kybackup/module/operationlog.cpp +++ b/kybackup/module/operationlog.cpp @@ -53,7 +53,10 @@ void OperationLog::initFirstWidget() m_tableWidget->setColumnCount(headerLabels.size()); m_tableWidget->setHorizontalHeaderLabels(headerLabels); m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); - m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + // m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + m_tableWidget->horizontalHeader()->resizeSection(0, 340); + m_tableWidget->horizontalHeader()->resizeSection(2, 150); + m_tableWidget->horizontalHeader()->setStretchLastSection(true); m_tableWidget->horizontalHeader()->setTextElideMode(Qt::ElideRight); m_tableWidget->horizontalHeader()->setFixedHeight(30); m_tableWidget->verticalHeader()->setHidden(true); // 好像隐藏不掉 diff --git a/kybackup/module/systembackup.cpp b/kybackup/module/systembackup.cpp index 29ec0b3..b4ae509 100755 --- a/kybackup/module/systembackup.cpp +++ b/kybackup/module/systembackup.cpp @@ -18,6 +18,7 @@ #include "../../common/utils.h" #include "../globalbackupinfo.h" #include "managebackuppointlist.h" +#include "messageboxutils.h" SystemBackup::SystemBackup(QWidget *parent /*= nullptr*/) : QStackedWidget(parent), @@ -822,8 +823,6 @@ void SystemBackup::initFifthWidget() labelTip->setIsOriginal(true); labelTip->setFontWordWrap(true); labelTip->setMinimumWidth(700); - // 不要使用电脑,以防数据丢失 - labelTip->setDeplayText(tr("Do not use computers in case of data loss")); hlayoutCenterFont2->addStretch(); hlayoutCenterFont2->addWidget(labelTip); hlayoutCenterFont2->addStretch(); @@ -846,7 +845,6 @@ void SystemBackup::initFifthWidget() MyPushButton *cancel = new MyPushButton(fifth); cancel->setFixedSize(97, 36); cancel->setText(tr("cancel")); - cancel->setEnabled(true); cancel->setAutoRepeat(true); hlayoutCenterFont3->addStretch(); hlayoutCenterFont3->addWidget(cancel); @@ -878,8 +876,11 @@ void SystemBackup::initFifthWidget() connect(this, &SystemBackup::startBackup, this, [=] { progressBar->setPersent(0); movie->start(); + // 不要使用电脑,以防数据丢失 + labelTip->setDeplayText(tr("Do not use computers in case of data loss")); labelTip_1->setVisible(false); labelTip_1->setDeplayText(""); + cancel->setEnabled(true); // 开始备份 this->on_backup_start(); @@ -894,7 +895,13 @@ void SystemBackup::initFifthWidget() // 取消备份 connect(cancel, &MyPushButton::clicked, this, [=](bool checked) { Q_UNUSED(checked) - // TODO + // 确定取消当前操作? + if (!MessageBoxUtils::QMESSAGE_BOX_WARNING_CANCEL(this, QObject::tr("Warning"), QObject::tr("Are you sure to cancel the operation?"), QObject::tr("Ok"), QObject::tr("Cancel"))) { + return ; + } + cancel->setEnabled(false); + if (m_pInterface) + m_pInterface->cancel(); }); addWidget(fifth); @@ -965,7 +972,7 @@ void SystemBackup::on_checkBackup_end(int result) break; case int(BackupResult::BACKUP_CAPACITY_IS_NOT_ENOUGH): // 备份空间不足 - errMsg = tr("The storage for backup is not enough."); + errMsg = tr("The storage for backup is not enough"); // 建议释放空间后重试 errTip = tr("Retry after release space"); break; @@ -979,20 +986,26 @@ void SystemBackup::on_checkBackup_end(int result) case int(BackupResult::WRITE_STORAGEINFO_ADD_ITEM_FAIL): case int(BackupResult::WRITE_STORAGEINFO_UPDATE_ITEM_FAIL): // 创建备份点目录失败 - errMsg = tr("Failed to create the backup point directory."); + errMsg = tr("Failed to create the backup point directory"); // 请检查备份目录是否有写权限 errTip = tr("Please check backup partition permissions"); break; case int(BackupResult::MKSQUASHFS_START_SUCCESS): - // 正压缩系统到本地磁盘,请耐心等待。。。 + // 正压缩系统到本地磁盘,请耐心等待... errTip = tr("The system is being compressed to the local disk, please wait patiently..."); emit this->backupWarnning(errTip); return; case int(BackupResult::BACKUP_START_SUCCESS): - // 正在传输备份文件到移动设备,即将完成。。。 + // 正在传输备份文件到移动设备,即将完成... errTip = tr("Transferring backup files to mobile device, about to be completed..."); emit this->backupWarnning(errTip); return; + case int(BackupResult::CANCEL_SUCCESS): + // 已经取消本次备份 + errMsg = tr("The backup had been canceled"); + // 如需要可重新发起备份 + errTip = tr("Re-initiate the backup if necessary"); + break; default: bRst = true; break; @@ -1182,7 +1195,7 @@ void SystemBackup::initLastWidget() QIcon icon = QIcon::fromTheme("dialog-error.png", QIcon(":/symbos/dialog-error.png")); resultLogo->setPixmap(icon.pixmap(QSize(20,20))); resultLogo->setVisible(true); - // 环境校验失败 + // 备份失败 bigTitle->setDeplayText(tr("The backup is failed")); dot1->setVisible(true); dot2->setVisible(true);