From 4da3262b842b672202d8b30c378f640df73b96cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=B0=91=E5=8B=87?= Date: Thu, 15 Sep 2022 15:11:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=8E=82=E8=BF=98=E5=8E=9F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/data/backup-auto | 1 + backup-daemon/data/backup-auto-efi | 2 +- backup-daemon/systemrestoreproxy.cpp | 59 +++++++++++++++++++--------- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/backup-daemon/data/backup-auto b/backup-daemon/data/backup-auto index b68c0dd..9cd8720 100755 --- a/backup-daemon/data/backup-auto +++ b/backup-daemon/data/backup-auto @@ -544,6 +544,7 @@ generateExcludeFile() { echo "/cdrom" >>$EXCLUDEFILE echo "/swap_file" >>$EXCLUDEFILE echo "/var/lib/docker/overlay2" >>$EXCLUDEFILE + echo "/var/log" >>$EXCLUDEFILE #bind挂载的目录不进行备份或还原 cat ${rootpath}/etc/fstab | awk '{if($4~/bind/) print $1}' | diff --git a/backup-daemon/data/backup-auto-efi b/backup-daemon/data/backup-auto-efi index e0c6e99..a3f4ef4 100755 --- a/backup-daemon/data/backup-auto-efi +++ b/backup-daemon/data/backup-auto-efi @@ -1193,8 +1193,8 @@ elif [ $backupORrestore = "--restoreretainuserdata" ]; then restoreAuto elif [ $backupORrestore = "--factoryrestore" ]; then m_isFactory=true - mount >>$PLOGFILE mountBackup + mount >>$PLOGFILE restoreAuto #还原, grub时只有一键还原,没有增量还原 #umountBackup diff --git a/backup-daemon/systemrestoreproxy.cpp b/backup-daemon/systemrestoreproxy.cpp index 650dd31..3909858 100755 --- a/backup-daemon/systemrestoreproxy.cpp +++ b/backup-daemon/systemrestoreproxy.cpp @@ -360,11 +360,6 @@ void SystemRestoreProxy::restoreSystem() fileIfSync.replace("//", "/"); QFileInfo file(fileIfSync); QDateTime beginTime = file.fileTime(QFileDevice::FileModificationTime); - if (FACTORY_BACKUP_UUID == m_curUuid && m_backupWrapper.m_type == BackupType::RESTORE_SYSTEM) { - // 出厂还原有的机器上删除/home/xxx有残留,故在此再强制删除一下,sudo rm -rf命令一遍还删除不了(报错:无法删除/home/xx/.config:目录非空,应该是删除后又自动生成了),多删除几次还不是非常干净,^_^ - removeHome(Utils::getSysRootPath() + "/home"); - removeHome(Utils::getSysRootPath() + "/data/home"); - } QProcess::execute("sync"); Utils::wait(20); Utils::updateSyncFile(); @@ -375,6 +370,13 @@ void SystemRestoreProxy::restoreSystem() if (UpdateTime > beginTime) break; } + if (FACTORY_BACKUP_UUID == m_curUuid && m_backupWrapper.m_type == BackupType::RESTORE_SYSTEM) { + // 出厂还原有的机器上删除/home/xxx有残留,故在此再强制删除一下,sudo rm -rf命令一遍还删除不了(报错:无法删除/home/xx/.config:目录非空,应该是删除后又自动生成了),多删除几次还不是非常干净,^_^ + removeHome(QString(Utils::getSysRootPath() + "/home").replace("//", "/")); + removeHome(QString(Utils::getSysRootPath() + "/data/home").replace("//", "/")); + } + QProcess::execute("sync"); + Utils::wait(5); emit this->workResult(result); Utils::wait(2); @@ -427,9 +429,7 @@ void SystemRestoreProxy::removeHome(const QString& path) QStringList retainUsers = getBackupPointUsers(); qDebug() << retainUsers; - bool needRm = false; QString subcmd("rm -rf "); - QString delDirs; QStringList list = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs); for (const QString& item : list) { // 出厂备份里面的/home/oem等保留 @@ -444,20 +444,41 @@ void SystemRestoreProxy::removeHome(const QString& path) QDir subDir(subPath); subDir.removeRecursively(); - delDirs += "${rootmnt}"; - delDirs += path; - delDirs += "/"; - delDirs += item; - delDirs += " "; - - needRm = true; + qDebug() << (subcmd + subPath); + QProcess::execute(subcmd + subPath); } - if (needRm) { - QString cmd = QString("bash -c \"%1\" ").arg(subcmd + delDirs); - cmd.replace("${rootmnt}", ""); - QProcess::execute(cmd); - } +// bool needRm = false; +// QString subcmd("rm -rf "); +// QString delDirs; +// QStringList list = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs); +// for (const QString& item : list) { +// // 出厂备份里面的/home/oem等保留 +// if (item == "oem") +// continue ; +// if (retainUsers.contains(item)) +// continue ; + +// QString subPath = path; +// subPath += "/"; +// subPath += item; +// QDir subDir(subPath); +// subDir.removeRecursively(); + +// delDirs += "${rootmnt}"; +// delDirs += path; +// delDirs += "/"; +// delDirs += item; +// delDirs += " "; + +// needRm = true; +// } + +// if (needRm) { +// QString cmd = QString("bash -c \"%1\" ").arg(subcmd + delDirs); +// cmd.replace("${rootmnt}", ""); +// QProcess::execute(cmd); +// } } qDebug() << "SystemRestoreProxy::removeHome invoke end";