2021-12-28 16:51:35 +08:00
|
|
|
|
#include "datarestoreproxy.h"
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
|
#include "../common/utils.h"
|
|
|
|
|
#include "mymountproxy.h"
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_DYNCREATE(DataRestoreProxy)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 构造函数
|
|
|
|
|
*/
|
|
|
|
|
DataRestoreProxy::DataRestoreProxy()
|
|
|
|
|
{
|
|
|
|
|
m_bSuccess = false;
|
|
|
|
|
m_p = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 析构函数
|
|
|
|
|
*/
|
|
|
|
|
DataRestoreProxy::~DataRestoreProxy()
|
|
|
|
|
{
|
|
|
|
|
delete m_p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 环境检测
|
|
|
|
|
* @return false,检测失败;true,检测成功
|
|
|
|
|
*/
|
|
|
|
|
bool DataRestoreProxy::checkEnvEx()
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "DataRestoreProxy::checkEnvEx invoke begin";
|
|
|
|
|
|
|
|
|
|
// 1、检测.user.txt是否存在
|
|
|
|
|
m_userFile = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE;
|
|
|
|
|
m_userFile.replace("//", "/");
|
|
|
|
|
if (!Utils::filsExists(m_userFile)) {
|
|
|
|
|
qCritical(".user.txt文件不存在");
|
|
|
|
|
emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2、检测.exclude.user.txt是否存在
|
|
|
|
|
m_excludeUserFile = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE;
|
|
|
|
|
m_excludeUserFile.replace("//", "/");
|
|
|
|
|
if (!Utils::filsExists(m_excludeUserFile)) {
|
|
|
|
|
qCritical(".exclude.user.txt文件不存在");
|
|
|
|
|
emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3、检测还原点是否存在
|
|
|
|
|
m_backupPath = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/data";
|
|
|
|
|
m_backupPath.replace("//", "/");
|
|
|
|
|
if (Utils::isDirEmpty(m_backupPath)) {
|
|
|
|
|
qCritical("还原点{uuid}/data目录不存在");
|
|
|
|
|
emit checkResult(int(BackupResult::INC_NOT_FOUND_DIR));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit checkResult(int(BackupResult::CHECK_ENV_SUCCESS));
|
|
|
|
|
|
|
|
|
|
qDebug() << "DataRestoreProxy::checkEnvEx invoke end";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 执行还原逻辑
|
|
|
|
|
*/
|
|
|
|
|
void DataRestoreProxy::doWorkEx()
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "DataRestoreProxy::doWorkEx invoke begin";
|
|
|
|
|
|
|
|
|
|
// 1、校验
|
|
|
|
|
if (!checkEnvEx())
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
// 2、还原数据
|
|
|
|
|
restoreData();
|
|
|
|
|
|
|
|
|
|
qDebug() << "DataRestoreProxy::doWorkEx invoke end";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 根据场景获取rsync命令参数
|
|
|
|
|
* @param scene,场景
|
|
|
|
|
* @return 组装好的rsync的参数信息
|
|
|
|
|
*/
|
|
|
|
|
QStringList DataRestoreProxy::getRsyncArgs(DataRestoreScene scene)
|
|
|
|
|
{
|
|
|
|
|
QStringList args;
|
|
|
|
|
args << "-avAHXr";
|
|
|
|
|
args << "--info=progress2";
|
|
|
|
|
args << "--no-inc-recursive";
|
|
|
|
|
args << "--ignore-missing-args";
|
|
|
|
|
args << "--delete";
|
|
|
|
|
|
|
|
|
|
switch (scene) {
|
|
|
|
|
case DataRestoreScene::DATA_RESTORE :
|
|
|
|
|
args << "--files-from" << m_userFile;
|
|
|
|
|
|
|
|
|
|
break ;
|
|
|
|
|
default:
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 数据还原
|
|
|
|
|
*/
|
|
|
|
|
void DataRestoreProxy::restoreData()
|
|
|
|
|
{
|
|
|
|
|
QStringList args = getRsyncArgs(DataRestoreScene::DATA_RESTORE);
|
|
|
|
|
|
2021-12-29 10:20:15 +08:00
|
|
|
|
m_srcPath = m_backupPath;
|
|
|
|
|
QString destPath = Utils::getSysRootPath();
|
|
|
|
|
destPath.replace("//", "/");
|
2021-12-28 16:51:35 +08:00
|
|
|
|
args << m_srcPath + "/";
|
|
|
|
|
args << destPath + "/";
|
|
|
|
|
|
|
|
|
|
m_p = new RsyncPathToDirProcess(this);
|
|
|
|
|
connect(m_p, &RsyncPathToDirProcess::progress, this, &DataRestoreProxy::progress);
|
|
|
|
|
connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) {
|
|
|
|
|
if (result) {
|
|
|
|
|
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
|
2021-12-30 10:27:03 +08:00
|
|
|
|
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)+ "," + m_backupWrapper.m_backupName);
|
2021-12-28 16:51:35 +08:00
|
|
|
|
}
|
|
|
|
|
emit this->workResult(result);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_p->start(args, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|