出厂还原优化

This commit is contained in:
赵民勇 2022-09-15 15:11:01 +08:00
parent 1003397079
commit 4da3262b84
3 changed files with 42 additions and 20 deletions

View File

@ -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}' |

View File

@ -1193,8 +1193,8 @@ elif [ $backupORrestore = "--restoreretainuserdata" ]; then
restoreAuto
elif [ $backupORrestore = "--factoryrestore" ]; then
m_isFactory=true
mount >>$PLOGFILE
mountBackup
mount >>$PLOGFILE
restoreAuto #还原, grub时只有一键还原没有增量还原
#umountBackup

View File

@ -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";