操作日志

This commit is contained in:
zhaominyong 2021-12-30 10:27:03 +08:00
parent cb92357cbd
commit aae6b39ca7
21 changed files with 249 additions and 25 deletions

View File

@ -350,7 +350,8 @@ bool DataBackupProxy::backupData()
Utils::writeBackupLog(m_backupPoint.m_time + ","
+ m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size
+ "," + QString::number(m_backupWrapper.m_frontUid));
+ "," + QString::number(m_backupWrapper.m_frontUid)
+ "," + m_backupWrapper.m_backupName);
Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName);
m_bSuccess = true;
}

View File

@ -128,7 +128,7 @@ void DataRestoreProxy::restoreData()
connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) {
if (result) {
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid));
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)+ "," + m_backupWrapper.m_backupName);
}
emit this->workResult(result);
});

View File

@ -45,8 +45,6 @@ private:
// 是否还原成功
bool m_bSuccess;
// 当前备份uuid
QString m_curUuid;
// 当前还原源目录
QString m_srcPath;
// 还原进程

View File

@ -1,5 +1,6 @@
#include "deletebackupproxy.h"
#include <QProcess>
#include <QDateTime>
#include <QDebug>
#include "../common/utils.h"
@ -66,5 +67,8 @@ void DeleteBackupProxy::deleteBackupPointDir()
args << "-rf";
args << uuidPath;
QProcess::execute("rm", args);
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)+ "," + m_backupWrapper.m_backupName);
}

View File

@ -20,6 +20,8 @@ private:
bool deleteXmlBackupPoint();
void deleteBackupPointDir();
ParseBackupList::BackupPoint m_backupPoint;
};
#endif // DELETEBACKUPPROXY_H

View File

@ -434,7 +434,8 @@ bool SystemBackupProxy::backupSystem()
// Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","+ m_backupWrapper.m_note + "," + m_backupPoint.m_size+ "," + QString::number(m_backupWrapper.m_frontUid));
Utils::writeBackupLog(m_backupPoint.m_time + ","
+ m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size);
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size
+ ",," + m_backupWrapper.m_backupName);
Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName);
m_bSuccess = true;
}

View File

@ -320,7 +320,9 @@ void SystemRestoreProxy::restoreSystem()
}
args << m_srcPath + "/";
args << destPath + "/";
destPath += "/";
destPath.replace("//", "/");
args << destPath;
m_p = new RsyncPathToDirProcess(this);
connect(m_p, &RsyncPathToDirProcess::progress, this, &SystemRestoreProxy::progress);
@ -328,7 +330,7 @@ void SystemRestoreProxy::restoreSystem()
if (result) {
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
// Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid));
Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,,");
Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,,," + m_backupWrapper.m_backupName);
Utils::updateSyncFile();
QString fileIfSync = Utils::getSysRootPath() + FILE_IF_SYNC;

View File

@ -311,7 +311,8 @@ bool UDiskDataBackupProxy::backupDataToUdisk()
Utils::writeBackupLog(m_backupPoint.m_time + ","
+ m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size
+ "," + QString::number(m_backupWrapper.m_frontUid));
+ "," + QString::number(m_backupWrapper.m_frontUid)
+ "," + m_backupWrapper.m_backupName);
Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName);
m_bSuccess = true;
}

View File

@ -129,7 +129,7 @@ void UDiskDataRestoreProxy::restoreData()
m_isFinished = true;
if (result) {
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid));
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)+ "," + m_backupWrapper.m_backupName);
}
emit this->workResult(result);
});

View File

@ -50,8 +50,6 @@ private:
bool m_bSuccess;
// 是否完成
bool m_isFinished;
// 当前备份uuid
QString m_curUuid;
// 当前还原源目录
QString m_srcPath;
// 还原进程

View File

@ -470,7 +470,8 @@ bool UDiskSystemBackupProxy::backup(const QStringList &args)
// Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","+ m_backupWrapper.m_note + "," + m_backupPoint.m_size+ "," + QString::number(m_backupWrapper.m_frontUid));
Utils::writeBackupLog(m_backupPoint.m_time + ","
+ m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ","
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size);
+ m_backupWrapper.m_note + "," + m_backupPoint.m_size
+ ",," + m_backupWrapper.m_backupName);
Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName);
m_bSuccess = true;

View File

@ -325,7 +325,9 @@ void UDiskSystemRestoreProxy::restoreSystem()
QStringList args = getRsyncArgs(SystemRestoreScene::SYSTEM_RESTORE);
args << m_srcPath + "/";
args << destPath + "/";
destPath += "/";
destPath.replace("//", "/");
args << destPath;
m_p = new RsyncPathToDirProcess(this);
connect(m_p, &RsyncPathToDirProcess::progress, this, &UDiskSystemRestoreProxy::progress);
@ -333,7 +335,7 @@ void UDiskSystemRestoreProxy::restoreSystem()
if (result) {
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
// Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid));
Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,,");
Utils::writeBackupLog(time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + ",,,," + m_backupWrapper.m_backupName);
Utils::updateSyncFile();
QString fileIfSync = Utils::getSysRootPath() + FILE_IF_SYNC;

View File

@ -65,9 +65,6 @@ Worker * WorkerFactory::createWorker(int type, int position)
className = "SystemBackupProxy";
}
break;
case BackupType::AUTO_BACKUP_SYSTEM:
className = "AutoSystemBackupProxy";
break;
case BackupType::RESTORE_SYSTEM:
case BackupType::RESTORE_SYSTEM_WITH_DATA:
if (BackupPosition::UDISK == position) {

View File

@ -76,8 +76,6 @@ enum BackupType {
DELETE_BACKUP = 8,
// ghost镜像
GHOST_IMAGE = 9,
// 自动升级模块的自动备份
AUTO_BACKUP_SYSTEM = 10,
// 仅仅初始化BackupType枚举类变量用没有用于持久化不用固定其值
BACKUP_TYPE_INIT,

View File

@ -619,7 +619,7 @@ bool Utils::writeBackupLog(QString line)
std::fputs("#5:retaining user data\n", fp.get());
std::fputs("#6:restore data\n", fp.get());
std::fputs("#8:delete backup\n", fp.get());
std::fputs("#for example: 17-04-25 10:43:56,{uuidxxxxx},0,this is a note\n", fp.get());
std::fputs("#for example: 17-04-25 10:43:56,{uuidxxxxx},0,this is a note,21.19KB,userid-1000,备份名称\n", fp.get());
}
std::fputs(line.toStdString().data(), fp.get());
std::fflush(fp.get());
@ -938,13 +938,15 @@ QList<BackupWrapper> Utils::getBackupLogList()
}
if (record.m_backupName.isEmpty()) {
// if (FACTORY_BACKUP_UUID == record.m_uuid) {
// record.m_backupName = QObject::tr("Factory Backup");
// } else if (AUTO_BACKUP_UUID == record.m_uuid) {
if (FACTORY_BACKUP_UUID == record.m_uuid) {
record.m_backupName = QObject::tr("Factory Backup");
}
// else if (AUTO_BACKUP_UUID == record.m_uuid) {
// record.m_backupName = QObject::tr("Auto Backup");
// } else {
record.m_backupName = record.m_uuid;
// }
else {
record.m_backupName = record.m_uuid;
}
}
list << record;

View File

@ -62,6 +62,7 @@ HEADERS += \
module/databackup.h \
module/datarestore.h \
module/managebackuppointlist.h \
module/operationlog.h \
module/selectrestorepoint.h \
module/systembackup.h \
module/systemrestore.h \
@ -102,6 +103,7 @@ SOURCES += \
module/databackup.cpp \
module/datarestore.cpp \
module/managebackuppointlist.cpp \
module/operationlog.cpp \
module/selectrestorepoint.cpp \
module/systembackup.cpp \
module/systemrestore.cpp \

View File

@ -12,6 +12,7 @@
#include "module/systemrestore.h"
#include "module/databackup.h"
#include "module/datarestore.h"
#include "module/operationlog.h"
#include "backup_manager_interface.h"
#include "globalbackupinfo.h"
#include "messageboxutils.h"
@ -222,6 +223,10 @@ void MainDialog::selected(int func_type)
m_stackedWidget = new DataRestore(ui->centralwidget);
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::RESTORE_DATA);
break;
case FuncTypeConverter::FunType::OPERATION_LOG:
m_stackedWidget = new OperationLog(ui->centralwidget);
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::OPERATION_LOG);
break;
default:
m_stackedWidget = new SystemBackup(ui->centralwidget);
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_SYSTEM);

View File

@ -0,0 +1,180 @@
#include "operationlog.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QSettings>
#include <QTextCodec>
OperationLog::OperationLog(QWidget *parent) :
QStackedWidget(parent)
{
// 界面手写代码创建,作为练手
initFirstWidget();
}
OperationLog::~OperationLog()
{}
/**
* @brief
*/
void OperationLog::initFirstWidget()
{
QWidget *first = new QWidget;
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->addSpacing(10);
QHBoxLayout *hlayoutLine1 = new QHBoxLayout;
// 列表为空时展示图片
QLabel *labelEmptyLogo = new QLabel(this);
QPixmap pixmap(":/images/empty.png");
labelEmptyLogo->setPixmap(pixmap);
hlayoutLine1->addStretch();
hlayoutLine1->addWidget(labelEmptyLogo);
hlayoutLine1->addStretch();
vlayout->addLayout(hlayoutLine1);
QHBoxLayout *hlayoutLine2 = new QHBoxLayout;
QLabel *labelEmptyText = new QLabel(tr("No operation log"));
labelEmptyText->setAlignment(Qt::AlignCenter);
labelEmptyText->setEnabled(false);
hlayoutLine2->addStretch();
hlayoutLine2->addWidget(labelEmptyText);
hlayoutLine2->addStretch();
vlayout->addLayout(hlayoutLine2);
QHBoxLayout *hlayoutLine3 = new QHBoxLayout;
QStringList headerLabels;
headerLabels << tr("Backup Name") << tr("UUID") << tr("Operation") << tr("Operation Time");
m_tableWidget = new QTableWidget;
m_tableWidget->setFixedSize(680, 560);
m_tableWidget->setColumnCount(headerLabels.size());
m_tableWidget->setHorizontalHeaderLabels(headerLabels);
m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_tableWidget->horizontalHeader()->setTextElideMode(Qt::ElideRight);
m_tableWidget->horizontalHeader()->setFixedHeight(30);
m_tableWidget->verticalHeader()->setHidden(true); // 好像隐藏不掉
m_tableWidget->verticalHeader()->setVisible(false); //左侧标题不可见
m_tableWidget->verticalHeader()->setDefaultSectionSize(30); // 设置行高
m_tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
m_tableWidget->setSortingEnabled(false); // 等录入完数据后再排序
m_tableWidget->setAlternatingRowColors(true);
m_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_tableWidget->hideColumn(1); // 隐藏uuid
hlayoutLine3->addStretch();
hlayoutLine3->addWidget(m_tableWidget);
hlayoutLine3->addStretch();
vlayout->addLayout(hlayoutLine3);
vlayout->addStretch();
first->setLayout(vlayout);
QList<BackupWrapper> list = Utils::getBackupLogList();
if (list.isEmpty()) {
labelEmptyLogo->setVisible(true);
labelEmptyText->setVisible(true);
m_tableWidget->setVisible(false);
} else {
labelEmptyLogo->setVisible(false);
labelEmptyText->setVisible(false);
m_tableWidget->setVisible(true);
initOperationLogs(list);
}
addWidget(first);
}
/**
* @brief
*/
void OperationLog::initOperationLogs(const QList<BackupWrapper>& list)
{
m_tableWidget->clearContents();
m_tableWidget->setRowCount(0);
m_tableWidget->setSortingEnabled(false); // 等录入完数据后再排序
int indexOfRow = 0;
for (const BackupWrapper& backupPoint : list) {
m_tableWidget->insertRow(indexOfRow);
setItem(indexOfRow, 0, backupPoint.m_backupName);
setItem(indexOfRow, 1, backupPoint.m_uuid);
setItem(indexOfRow, 2, castTypeToString(backupPoint.m_type));
setItem(indexOfRow, 3, backupPoint.m_time);
++indexOfRow;
}
m_tableWidget->setSortingEnabled(true); // 等录入完数据后再排序
m_tableWidget->sortItems(3, Qt::DescendingOrder);
}
/**
* @brief QTableWidget的单元格内容
* @param row
* @param column
* @param text
*/
void OperationLog::setItem(int row, int column, const QString& text, int alignFlag)
{
QTableWidgetItem *item = new QTableWidgetItem;
item->setText(text);
item->setToolTip(text);
item->setTextAlignment(alignFlag);
m_tableWidget->setItem(row, column, item);
}
/**
* @brief
* @param type
* @return
*/
QString OperationLog::castTypeToString(int type)
{
QString name;
switch (type) {
case BackupType::BACKUP_SYSTEM :
name = tr("new system backup");
break;
case BackupType::INC_BACKUP_SYSTEM :
name = tr("udpate system backup");
break;
case BackupType::BACKUP_DATA :
name = tr("new data backup");
break;
case BackupType::INC_BACKUP_DATA :
name = tr("update data backup");
break;
case BackupType::RESTORE_SYSTEM :
name = tr("restore system");
break;
case BackupType::RESTORE_SYSTEM_WITH_DATA :
name = tr("restore retaining user data");
break;
case BackupType::RESTORE_DATA :
name = tr("restore data");
break;
case BackupType::DELETE_BACKUP :
name = tr("delete backup");
break;
case BackupType::GHOST_IMAGE :
name = tr("make ghost image");
break;
default:
break;
}
return name;
}

View File

@ -0,0 +1,24 @@
#ifndef OPERATIONLOG_H
#define OPERATIONLOG_H
#include <QStackedWidget>
#include <QTableWidget>
#include "../common/utils.h"
class OperationLog : public QStackedWidget
{
Q_OBJECT
public:
explicit OperationLog(QWidget* parent = nullptr);
virtual ~OperationLog();
private:
void initFirstWidget();
void initOperationLogs(const QList<BackupWrapper>& list);
void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignLeft | Qt::AlignVCenter);
QString castTypeToString(int type);
QTableWidget *m_tableWidget;
};
#endif // OPERATIONLOG_H

View File

@ -190,6 +190,7 @@ void SystemRestore::on_button_beginRestore_clicked(bool checked)
this->m_uuid = "";
this->m_devPath = "";
this->m_backupName = "";
this->m_isOtherMachine = "";
// 出厂还原,不用去选择备份点
@ -204,6 +205,7 @@ void SystemRestore::on_button_beginRestore_clicked(bool checked)
//出厂还原
m_uuid = FACTORY_BACKUP_UUID;
m_devPath = "";
this->m_backupName = "";
this->m_isOtherMachine = false;
} else {
// 系统备份点列表中选择备份点
@ -211,6 +213,7 @@ void SystemRestore::on_button_beginRestore_clicked(bool checked)
connect(selectRestoreDialog, &SelectRestorePoint::selected, this, [=](ParseBackupList::BackupPoint backupPoint){
this->m_uuid = backupPoint.m_uuid;
this->m_devPath = backupPoint.m_path;
this->m_backupName = backupPoint.m_backupName;
this->m_isOtherMachine = backupPoint.m_iPosition == BackupPosition::OTHER ? true : false;
});
@ -483,6 +486,7 @@ void SystemRestore::on_checkEnv_start()
backupWrapper.m_type = m_isRetainUserData ? BackupType::RESTORE_SYSTEM_WITH_DATA : BackupType::RESTORE_SYSTEM;
backupWrapper.m_iPosition = m_devPath.isEmpty() ? BackupPosition::LOCAL : BackupPosition::UDISK;
backupWrapper.m_uuid = m_uuid;
backupWrapper.m_backupName = m_backupName;
backupWrapper.m_prefixDestPath = m_devPath;
backupWrapper.m_isOtherMachine = m_isOtherMachine ? 1 : 0;
backupWrapper.m_frontUid = getuid();
@ -683,6 +687,7 @@ void SystemRestore::on_restore_start()
backupWrapper.m_type = m_isRetainUserData ? BackupType::RESTORE_SYSTEM_WITH_DATA : BackupType::RESTORE_SYSTEM;
backupWrapper.m_iPosition = m_devPath.isEmpty() ? BackupPosition::LOCAL : BackupPosition::UDISK;
backupWrapper.m_uuid = m_uuid;
backupWrapper.m_backupName = m_backupName;
backupWrapper.m_prefixDestPath = m_devPath;
backupWrapper.m_isOtherMachine = m_isOtherMachine ? 1 : 0;
backupWrapper.m_frontUid = getuid();

View File

@ -62,6 +62,7 @@ private:
QString m_uuid; // 还原点的UUID
QString m_devPath; // 如果是从移动设备进行还原,此中保存移动设备挂载路径
QString m_backupName; // 还原点的备份点名称
bool m_isOtherMachine; // 是否异机备份点还原
// 系统备份状态
int m_systemRestoreState;