应系统更新模块要求,提供给其系统还原接口
This commit is contained in:
parent
631d53f340
commit
781f0a9e5d
|
@ -49,10 +49,16 @@ bool ManagerAdaptor::umountBackupPartition()
|
|||
return out0;
|
||||
}
|
||||
|
||||
void ManagerAdaptor::autoBackUpForSystemUpdate_noreturn(const QString &autobackup_name, const QString &create_note, const QString &inc_note, const QString &frontUserName, int frontUid)
|
||||
void ManagerAdaptor::autoBackUpForSystemUpdate_noreturn(const QString &backupName, const QString &createNote, const QString &incNote, const QString &frontUserName, int frontUid)
|
||||
{
|
||||
// handle method call com.kylin.backup.manager.autoBackUpForSystemUpdate_noreturn
|
||||
QMetaObject::invokeMethod(parent(), "autoBackUpForSystemUpdate_noreturn", Q_ARG(QString, autobackup_name), Q_ARG(QString, create_note), Q_ARG(QString, inc_note), Q_ARG(QString, frontUserName), Q_ARG(int, frontUid));
|
||||
QMetaObject::invokeMethod(parent(), "autoBackUpForSystemUpdate_noreturn", Q_ARG(QString, backupName), Q_ARG(QString, createNote), Q_ARG(QString, incNote), Q_ARG(QString, frontUserName), Q_ARG(int, frontUid));
|
||||
}
|
||||
|
||||
void ManagerAdaptor::autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid)
|
||||
{
|
||||
// handle method call com.kylin.backup.manager.autoRestoreForSystemUpdate
|
||||
QMetaObject::invokeMethod(parent(), "autoRestoreForSystemUpdate", Q_ARG(QString, frontUserName), Q_ARG(int, frontUid));
|
||||
}
|
||||
|
||||
int ManagerAdaptor::checkEnv(BackupWrapper backupWrapper)
|
||||
|
|
|
@ -58,6 +58,9 @@ class ManagerAdaptor: public QDBusAbstractAdaptor
|
|||
" <signal name=\"backupFinished\">\n"
|
||||
" <arg direction=\"out\" type=\"b\" name=\"result\"/>\n"
|
||||
" </signal>\n"
|
||||
" <signal name=\"sendAutoRestoreResult\">\n"
|
||||
" <arg direction=\"out\" type=\"b\" name=\"result\"/>\n"
|
||||
" </signal>\n"
|
||||
" <signal name=\"progress\">\n"
|
||||
" <arg direction=\"out\" type=\"i\"/>\n"
|
||||
" <arg direction=\"out\" type=\"i\"/>\n"
|
||||
|
@ -69,9 +72,13 @@ class ManagerAdaptor: public QDBusAbstractAdaptor
|
|||
" <arg direction=\"out\" type=\"b\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"autoBackUpForSystemUpdate_noreturn\">\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"autobackup_name\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"create_note\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"inc_note\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"backupName\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"createNote\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"incNote\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"frontUserName\"/>\n"
|
||||
" <arg direction=\"in\" type=\"i\" name=\"frontUid\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"autoRestoreForSystemUpdate\">\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"frontUserName\"/>\n"
|
||||
" <arg direction=\"in\" type=\"i\" name=\"frontUid\"/>\n"
|
||||
" </method>\n"
|
||||
|
@ -121,7 +128,8 @@ public: // PROPERTIES
|
|||
public Q_SLOTS: // METHODS
|
||||
int Mount_backup_partition();
|
||||
bool umountBackupPartition();
|
||||
void autoBackUpForSystemUpdate_noreturn(const QString &autobackup_name, const QString &create_note, const QString &inc_note, const QString &frontUserName, int frontUid);
|
||||
void autoBackUpForSystemUpdate_noreturn(const QString &backupName, const QString &createNote, const QString &incNote, const QString &frontUserName, int frontUid);
|
||||
void autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid);
|
||||
int checkEnv(BackupWrapper backupWrapper);
|
||||
int deleteBackupPoint(BackupWrapper backupWrapper);
|
||||
QString getBackupCommentForSystemUpdate(QString &state);
|
||||
|
@ -141,6 +149,7 @@ Q_SIGNALS: // SIGNALS
|
|||
void sendRate(int in0, int in1);
|
||||
void sendRestoreResult(bool result);
|
||||
void sendStartBackupResult(int result);
|
||||
void sendAutoRestoreResult(bool result);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -300,13 +300,13 @@ int MyBackupManager::ghostBackup(const BackupWrapper& backupWrapper)
|
|||
|
||||
/**
|
||||
* @brief 控制面板调用的备份接口,重构暂时先兼容以前的老接口
|
||||
* @param autobackup_name 备份名称
|
||||
* @param create_note 创建时备注
|
||||
* @param inc_note 增量备注
|
||||
* @param backupName 备份名称
|
||||
* @param createNote 创建时备注
|
||||
* @param incNote 增量备注
|
||||
* @param frontUserName 前端用户名
|
||||
* @param frontUid 前端用户id
|
||||
*/
|
||||
void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid)
|
||||
void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& backupName, const QString& createNote, const QString& incNote, const QString& frontUserName, int frontUid)
|
||||
{
|
||||
qDebug("MyBackupManager::autoBackUpForSystemUpdate_noreturn invoke begin");
|
||||
|
||||
|
@ -321,13 +321,13 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
|
|||
xmlPath.replace("//", "/");
|
||||
ParseBackupList parseXml(xmlPath);
|
||||
ParseBackupList::BackupPoint backupPoint = parseXml.findBackupPointByUuid(backupWrapper.m_uuid);
|
||||
if (autobackup_name.isEmpty()) {
|
||||
if (backupName.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_backupName = backupName;
|
||||
}
|
||||
backupWrapper.m_backupPaths << "/";
|
||||
backupWrapper.m_backupExcludePaths = Utils::getFromExcludePathsFile();
|
||||
|
@ -339,7 +339,7 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
|
|||
backupWrapper.m_iPosition = BackupPosition::LOCAL;
|
||||
backupWrapper.m_frontUserName = frontUserName;
|
||||
backupWrapper.m_frontUid = frontUid;
|
||||
backupWrapper.m_note = create_note.isEmpty() ? inc_note : create_note;
|
||||
backupWrapper.m_note = createNote.isEmpty() ? incNote : createNote;
|
||||
|
||||
Worker* worker = WorkerFactory::createWorker(backupWrapper.m_type, backupWrapper.m_iPosition);
|
||||
if (nullptr == worker) {
|
||||
|
@ -357,7 +357,7 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
|
|||
default:
|
||||
emit this->sendStartBackupResult(result);
|
||||
this->finished();
|
||||
if (!Utils::isRunning("kybackup")) {
|
||||
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
|
||||
this->umountBackupPartition();
|
||||
}
|
||||
break;
|
||||
|
@ -369,7 +369,7 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
|
|||
connect(worker, &Worker::workResult, this, [&] (bool result) {
|
||||
emit this->sendBackupResult(result);
|
||||
this->finished();
|
||||
if (!Utils::isRunning("kybackup")) {
|
||||
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
|
||||
this->umountBackupPartition();
|
||||
}
|
||||
});
|
||||
|
@ -382,6 +382,66 @@ void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autoback
|
|||
qDebug("MyBackupManager::autoBackUpForSystemUpdate_noreturn invoke end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 控制面板调用的系统自动备份点还原接口
|
||||
* @note 此接口是后来加的,系统更新模块意图在更新失败后直接调用还原接口进行还原
|
||||
*/
|
||||
void MyBackupManager::autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid)
|
||||
{
|
||||
qDebug("MyBackupManager::autoRestoreForSystemUpdate invoke begin");
|
||||
if (m_isActive || !lock(frontUid)) {
|
||||
emit sendAutoRestoreResult(false);
|
||||
return ;
|
||||
}
|
||||
Mount_backup_partition();
|
||||
|
||||
BackupWrapper backupWrapper;
|
||||
backupWrapper.m_uuid = AUTO_BACKUP_UUID;
|
||||
backupWrapper.m_type = BackupType::RESTORE_SYSTEM;
|
||||
backupWrapper.m_iPosition = BackupPosition::LOCAL;
|
||||
backupWrapper.m_frontUserName = frontUserName;
|
||||
backupWrapper.m_frontUid = frontUid;
|
||||
|
||||
Worker* worker = WorkerFactory::createWorker(backupWrapper.m_type, backupWrapper.m_iPosition);
|
||||
if (nullptr == worker) {
|
||||
emit sendAutoRestoreResult(false);
|
||||
return ;
|
||||
}
|
||||
|
||||
worker->setParam(backupWrapper);
|
||||
connect(worker, &Worker::checkResult, this, [&](int result) {
|
||||
switch (result) {
|
||||
case int(BackupResult::CHECK_ENV_SUCCESS) :
|
||||
case int(BackupResult::RESTORE_START_SUCCESS) :
|
||||
break;
|
||||
default:
|
||||
emit this->sendAutoRestoreResult(false);
|
||||
this->finished();
|
||||
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
|
||||
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->sendAutoRestoreResult(result);
|
||||
this->finished();
|
||||
if (!Utils::isRunning(BACKUP_CLI_NAME)) {
|
||||
this->umountBackupPartition();
|
||||
}
|
||||
});
|
||||
worker->moveToThread(&workerThread);
|
||||
connect(&workerThread, &MyThread::started, worker, &Worker::doWork);
|
||||
connect(&workerThread, &MyThread::finished, worker, &Worker::deleteLater);
|
||||
|
||||
workerThread.start();
|
||||
|
||||
qDebug("MyBackupManager::autoRestoreForSystemUpdate invoke end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 控制面板调用的获取系统备份接口
|
||||
* @param state
|
||||
|
|
|
@ -25,6 +25,8 @@ signals:
|
|||
void sendBackupResult(bool result);
|
||||
// 进度信号
|
||||
void sendRate(int, int);
|
||||
// 还原结果信号
|
||||
void sendAutoRestoreResult(bool result);
|
||||
|
||||
// 模块内使用的信号
|
||||
// 进度信号
|
||||
|
@ -56,7 +58,9 @@ public slots:
|
|||
// ghost镜像
|
||||
int ghostBackup(const BackupWrapper& backupWrapper);
|
||||
// 控制面板调用的备份接口,重构暂时先兼容以前的老接口
|
||||
void autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid);
|
||||
void autoBackUpForSystemUpdate_noreturn(const QString& backupName, const QString& createNote, const QString& incNote, const QString& frontUserName, int frontUid);
|
||||
// 控制面板调用的系统自动备份点还原接口
|
||||
void autoRestoreForSystemUpdate(const QString& frontUserName, int frontUid);
|
||||
// 控制面板调用的获取系统备份接口
|
||||
QString getBackupCommentForSystemUpdate(QString& state);
|
||||
// 获取备份状态
|
||||
|
@ -79,13 +83,13 @@ private:
|
|||
// 解锁
|
||||
bool unlock();
|
||||
void uninhibit();
|
||||
// 自旋锁
|
||||
spinlock_mutex m_mutex;
|
||||
|
||||
// 关闭、开启安全保护
|
||||
void setKysecStatus(bool status);
|
||||
|
||||
private:
|
||||
// 自旋锁
|
||||
spinlock_mutex m_mutex;
|
||||
// 锁文件描述符
|
||||
int m_fdLockFile = -1;
|
||||
QDBusUnixFileDescriptor m_inhibitFileDescriptor;
|
||||
|
|
|
@ -307,6 +307,7 @@ void ParseBackupList::getCustomizePaths(QStringList &customizePaths)
|
|||
/**
|
||||
* @brief 获取最后一次系统备份,排除自动备份点、自定义备份点
|
||||
* @return
|
||||
* @note 经过测试发现出厂备份点也不能作为基准点进行增量,因为出厂备份的安全标记和其它不同,咨询安全同事说解决不了。所以也排除出厂备份。
|
||||
*/
|
||||
ParseBackupList::BackupPoint ParseBackupList::getLastSysBackupPoint()
|
||||
{
|
||||
|
@ -328,7 +329,7 @@ ParseBackupList::BackupPoint ParseBackupList::getLastSysBackupPoint()
|
|||
continue;
|
||||
|
||||
QDomElement eleUuid = node.firstChildElement(UUID);
|
||||
if (eleUuid.isNull() || eleUuid.text() == AUTO_BACKUP_UUID)
|
||||
if (eleUuid.isNull() || eleUuid.text() == AUTO_BACKUP_UUID || eleUuid.text() == FACTORY_BACKUP_UUID)
|
||||
continue;
|
||||
|
||||
QDomElement eleState = node.firstChildElement(STATE);
|
||||
|
|
Loading…
Reference in New Issue