修改笔误+还原工具本身

This commit is contained in:
赵民勇 2023-03-08 11:28:29 +08:00
parent 7eeb898536
commit 8fc597cea2
8 changed files with 62 additions and 67 deletions

View File

@ -71,7 +71,7 @@ bool CustomizeGhostImageProxy::checkEnvEx()
return false; return false;
} }
m_imgDst = m_srcPath + "/" + UDISK_MKSQUASHFS_IMG_NAME; m_imgDst = m_srcPath + "/" + UDISK_MKSQUASHFS_IMG_NAME;
if (!Utils::filsExists(m_imgDst)) { if (!Utils::fileExists(m_imgDst)) {
emit checkResult(int(BackupResult::GHOST_SRC_DIRECTORY_IS_NOT_EXIST)); emit checkResult(int(BackupResult::GHOST_SRC_DIRECTORY_IS_NOT_EXIST));
return false; return false;
} }
@ -175,7 +175,7 @@ void CustomizeGhostImageProxy::doGhostImage()
if (resultRsync) { if (resultRsync) {
// 文件更名 // 文件更名
QString imgFileName = m_destPath + "/" + UDISK_MKSQUASHFS_IMG_NAME; QString imgFileName = m_destPath + "/" + UDISK_MKSQUASHFS_IMG_NAME;
if (Utils::filsExists(imgFileName)) { if (Utils::fileExists(imgFileName)) {
QStringList args; QStringList args;
args << imgFileName; args << imgFileName;
args << m_kyimg; args << m_kyimg;

View File

@ -48,7 +48,7 @@ bool CustomizeSystemRestoreProxy::checkEnvEx()
// 2、检测.user.txt是否存在 // 2、检测.user.txt是否存在
m_userFile = m_backupPoint.m_path + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE; m_userFile = m_backupPoint.m_path + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE;
m_userFile.replace("//", "/"); m_userFile.replace("//", "/");
if (!Utils::filsExists(m_userFile)) { if (!Utils::fileExists(m_userFile)) {
qCritical(".user.txt文件不存在"); qCritical(".user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -57,7 +57,7 @@ bool CustomizeSystemRestoreProxy::checkEnvEx()
// 3、检测.exclude.user.txt是否存在 // 3、检测.exclude.user.txt是否存在
m_excludeUserFile = m_backupPoint.m_path + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE; m_excludeUserFile = m_backupPoint.m_path + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE;
m_excludeUserFile.replace("//", "/"); m_excludeUserFile.replace("//", "/");
if (!Utils::filsExists(m_excludeUserFile)) { if (!Utils::fileExists(m_excludeUserFile)) {
qCritical(".exclude.user.txt文件不存在"); qCritical(".exclude.user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -72,7 +72,7 @@ bool CustomizeSystemRestoreProxy::checkEnvEx()
return false; return false;
} }
m_imgFileName = m_backupPath + "/" + UDISK_MKSQUASHFS_IMG_NAME; m_imgFileName = m_backupPath + "/" + UDISK_MKSQUASHFS_IMG_NAME;
if (!Utils::filsExists(m_imgFileName)) { if (!Utils::fileExists(m_imgFileName)) {
qCritical("还原点{uuid}/data/dst.img文件不存在"); qCritical("还原点{uuid}/data/dst.img文件不存在");
emit checkResult(int(BackupResult::INC_NOT_FOUND_DIR)); emit checkResult(int(BackupResult::INC_NOT_FOUND_DIR));
return false; return false;
@ -345,24 +345,22 @@ void CustomizeSystemRestoreProxy::restoreSystem()
} }
// 2209后新增了一些依赖还原到以前的4.0.13版后缺少依赖无法运行故此最后还得还原backup-daemon和kybackup本身 // 2209后新增了一些依赖还原到以前的4.0.13版后缺少依赖无法运行故此最后还得还原backup-daemon和kybackup本身
// QString version = Utils::getBackupVersion(); // 兼容Qt库从5.12.8升级到5.15,系统还原的最后也将备份还原工具本身还原
// if (version.contains("4.0.13")) // QString version = Utils::getBackupVersion();
// { // if (version.contains("4.0.13"))
// RsyncPathToDirProcess * process = new RsyncPathToDirProcess(this); {
// QStringList arguments; // initrd.img已经还原为旧状态需要将新版本的backup-auto-efi等脚本文件更新到initrd.img中这样我们修改后的新逻辑才能生效
// arguments << "-avAHXr"; QString msg;
// arguments << this->m_srcPath + "usr/bin/kybackup"; Utils::executeCMD("update-initramfs -u", msg);
// arguments << destPath + "usr/bin/"; qDebug() << msg;
// process->start(args, true);
// arguments.clear(); // 写入标记rsync_backup_self:${UUID}到文件/etc/file_if_sync中表示需要还原backup-daemon和kybackup本身
// arguments << "-avAHXr"; QString line("rsync_backup_self:");
// arguments << this->m_srcPath + "usr/bin/backup-daemon"; line += m_curUuid;
// arguments << destPath + "usr/bin/"; Utils::syncWriteFile(fileIfSync, line);
// process->start(args, true); ::sync();
// sync(); Utils::wait(5);
// Utils::wait(5); }
// }
emit this->workResult(result); emit this->workResult(result);
Utils::wait(2); Utils::wait(2);

View File

@ -43,7 +43,7 @@ bool DataRestoreProxy::checkEnvEx()
// 1、检测.user.txt是否存在 // 1、检测.user.txt是否存在
m_userFile = m_prePath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE; m_userFile = m_prePath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE;
m_userFile.replace("//", "/"); m_userFile.replace("//", "/");
if (!Utils::filsExists(m_userFile)) { if (!Utils::fileExists(m_userFile)) {
qCritical(".user.txt文件不存在"); qCritical(".user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -52,7 +52,7 @@ bool DataRestoreProxy::checkEnvEx()
// 2、检测.exclude.user.txt是否存在 // 2、检测.exclude.user.txt是否存在
m_excludeUserFile = m_prePath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE; m_excludeUserFile = m_prePath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE;
m_excludeUserFile.replace("//", "/"); m_excludeUserFile.replace("//", "/");
if (!Utils::filsExists(m_excludeUserFile)) { if (!Utils::fileExists(m_excludeUserFile)) {
qCritical(".exclude.user.txt文件不存在"); qCritical(".exclude.user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;

View File

@ -38,7 +38,7 @@ bool SystemRestoreProxy::checkEnvEx()
// 1、检测.user.txt是否存在 // 1、检测.user.txt是否存在
m_userFile = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE; m_userFile = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE;
m_userFile.replace("//", "/"); m_userFile.replace("//", "/");
if (!Utils::filsExists(m_userFile)) { if (!Utils::fileExists(m_userFile)) {
qCritical(".user.txt文件不存在"); qCritical(".user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -47,7 +47,7 @@ bool SystemRestoreProxy::checkEnvEx()
// 2、检测.exclude.user.txt是否存在 // 2、检测.exclude.user.txt是否存在
m_excludeUserFile = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE; m_excludeUserFile = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE;
m_excludeUserFile.replace("//", "/"); m_excludeUserFile.replace("//", "/");
if (!Utils::filsExists(m_excludeUserFile)) { if (!Utils::fileExists(m_excludeUserFile)) {
qCritical(".exclude.user.txt文件不存在"); qCritical(".exclude.user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -416,23 +416,22 @@ void SystemRestoreProxy::restoreSystem()
QProcess::execute("sync"); QProcess::execute("sync");
// 2209后新增了一些依赖还原到以前的4.0.13版后缺少依赖无法运行故此最后还得还原backup-daemon和kybackup本身 // 2209后新增了一些依赖还原到以前的4.0.13版后缺少依赖无法运行故此最后还得还原backup-daemon和kybackup本身
// QString version = Utils::getBackupVersion(); // 兼容Qt库从5.12.8升级到5.15,系统还原的最后也将备份还原工具本身还原
// if (version.contains("4.0.13")) // QString version = Utils::getBackupVersion();
// { // if (version.contains("4.0.13"))
// RsyncPathToDirProcess * process = new RsyncPathToDirProcess(this); {
// QStringList arguments; // initrd.img已经还原为旧状态需要将新版本的backup-auto-efi等脚本文件更新到initrd.img中这样我们修改后的新逻辑才能生效
// arguments << "-avAHXr"; QString msg;
// arguments << this->m_srcPath + "usr/bin/kybackup"; Utils::executeCMD("update-initramfs -u", msg);
// arguments << destPath + "usr/bin/"; qDebug() << msg;
// process->start(args, true);
// arguments.clear(); // 写入标记rsync_backup_self:${UUID}到文件/etc/file_if_sync中表示需要还原backup-daemon和kybackup本身
// arguments << "-avAHXr"; QString line("rsync_backup_self:");
// arguments << this->m_srcPath + "usr/bin/backup-daemon"; line += m_curUuid;
// arguments << destPath + "usr/bin/"; Utils::syncWriteFile(fileIfSync, line);
// process->start(args, true); ::sync();
// ::sync(); Utils::wait(5);
// } }
Utils::wait(5); Utils::wait(5);
emit this->workResult(result); emit this->workResult(result);

View File

@ -39,7 +39,7 @@ bool UDiskDataRestoreProxy::checkEnvEx()
// 1、检测.user.txt是否存在 // 1、检测.user.txt是否存在
m_userFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE; m_userFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE;
if (!Utils::filsExists(m_userFile)) { if (!Utils::fileExists(m_userFile)) {
qCritical(".user.txt文件不存在"); qCritical(".user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -47,7 +47,7 @@ bool UDiskDataRestoreProxy::checkEnvEx()
// 2、检测.exclude.user.txt是否存在 // 2、检测.exclude.user.txt是否存在
m_excludeUserFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE; m_excludeUserFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE;
if (!Utils::filsExists(m_excludeUserFile)) { if (!Utils::fileExists(m_excludeUserFile)) {
qCritical(".exclude.user.txt文件不存在"); qCritical(".exclude.user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;

View File

@ -40,7 +40,7 @@ bool UDiskSystemRestoreProxy::checkEnvEx()
// 1、检测.user.txt是否存在 // 1、检测.user.txt是否存在
m_userFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE; m_userFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + PATHS_USER_FILE;
m_userFile.replace("//", "/"); m_userFile.replace("//", "/");
if (!Utils::filsExists(m_userFile)) { if (!Utils::fileExists(m_userFile)) {
qCritical(".user.txt文件不存在"); qCritical(".user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -49,7 +49,7 @@ bool UDiskSystemRestoreProxy::checkEnvEx()
// 2、检测.exclude.user.txt是否存在 // 2、检测.exclude.user.txt是否存在
m_excludeUserFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE; m_excludeUserFile = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid + "/" + EXCLUDE_PATHS_USER_FILE;
m_excludeUserFile.replace("//", "/"); m_excludeUserFile.replace("//", "/");
if (!Utils::filsExists(m_excludeUserFile)) { if (!Utils::fileExists(m_excludeUserFile)) {
qCritical(".exclude.user.txt文件不存在"); qCritical(".exclude.user.txt文件不存在");
emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED)); emit checkResult(int(BackupResult::WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED));
return false; return false;
@ -374,7 +374,7 @@ bool UDiskSystemRestoreProxy::doPrepare()
// 移动设备系统备份如果有img则需要先将img挂载到/backup/imgbackup目录 // 移动设备系统备份如果有img则需要先将img挂载到/backup/imgbackup目录
QString imgPath = m_backupPath + "/" + UDISK_MKSQUASHFS_IMG_NAME; QString imgPath = m_backupPath + "/" + UDISK_MKSQUASHFS_IMG_NAME;
if (Utils::filsExists(imgPath)) { if (Utils::fileExists(imgPath)) {
// 1、检测目录/backup/imgbackup是否存在不存在则创建此目录 // 1、检测目录/backup/imgbackup是否存在不存在则创建此目录
QString dstImgMountPath = Utils::getSysRootPath() + BACKUP_IMGBACKUP_PATH; QString dstImgMountPath = Utils::getSysRootPath() + BACKUP_IMGBACKUP_PATH;
dstImgMountPath.replace("//", "/"); dstImgMountPath.replace("//", "/");
@ -469,24 +469,22 @@ void UDiskSystemRestoreProxy::restoreSystem()
} }
// 2209后新增了一些依赖还原到以前的4.0.13版后缺少依赖无法运行故此最后还得还原backup-daemon和kybackup本身 // 2209后新增了一些依赖还原到以前的4.0.13版后缺少依赖无法运行故此最后还得还原backup-daemon和kybackup本身
// QString version = Utils::getBackupVersion(); // 兼容Qt库从5.12.8升级到5.15,系统还原的最后也将备份还原工具本身还原
// if (version.contains("4.0.13")) // QString version = Utils::getBackupVersion();
// { // if (version.contains("4.0.13"))
// RsyncPathToDirProcess * process = new RsyncPathToDirProcess(this); {
// QStringList arguments; // initrd.img已经还原为旧状态需要将新版本的backup-auto-efi等脚本文件更新到initrd.img中这样我们修改后的新逻辑才能生效
// arguments << "-avAHXr"; QString msg;
// arguments << this->m_srcPath + "usr/bin/kybackup"; Utils::executeCMD("update-initramfs -u", msg);
// arguments << destPath + "usr/bin/"; qDebug() << msg;
// process->start(args, true);
// arguments.clear(); // 写入标记rsync_backup_self:${UUID}到文件/etc/file_if_sync中表示需要还原backup-daemon和kybackup本身
// arguments << "-avAHXr"; QString line("rsync_backup_self:");
// arguments << this->m_srcPath + "usr/bin/backup-daemon"; line += m_curUuid;
// arguments << destPath + "usr/bin/"; Utils::syncWriteFile(fileIfSync, line);
// process->start(args, true); ::sync();
// sync(); Utils::wait(5);
// Utils::wait(5); }
// }
} }
if (Utils::isDirEmpty(m_backupPath)) if (Utils::isDirEmpty(m_backupPath))

View File

@ -611,7 +611,7 @@ bool Utils::writeFileByLines(const QString& fileName, const QStringList& lines)
* @author zhaominyong * @author zhaominyong
* @since 2021/05/29 * @since 2021/05/29
*/ */
bool Utils::filsExists(const QString &fileName) bool Utils::fileExists(const QString &fileName)
{ {
struct stat buffer; struct stat buffer;
return (stat(fileName.toStdString().data(), &buffer) == 0); return (stat(fileName.toStdString().data(), &buffer) == 0);
@ -650,7 +650,7 @@ bool Utils::writeBackupLog(QString line)
logFile.replace("//", "/"); logFile.replace("//", "/");
std::string fileName(logFile.toStdString()); std::string fileName(logFile.toStdString());
// 判断文件是否存在 // 判断文件是否存在
bool exists = filsExists(logFile); bool exists = fileExists(logFile);
std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(std::fopen(fileName.data(), "a+"), std::fclose); std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(std::fopen(fileName.data(), "a+"), std::fclose);

View File

@ -162,7 +162,7 @@ public:
* @author zhaominyong * @author zhaominyong
* @since 2021/05/29 * @since 2021/05/29
*/ */
static bool filsExists(const QString &fileName); static bool fileExists(const QString &fileName);
/** /**
* @brief * @brief