yhkylin-backup-tools/backup-daemon/deletebackupproxy.cpp

98 lines
3.2 KiB
C++
Raw Permalink Normal View History

2021-12-06 14:55:00 +08:00
#include "deletebackupproxy.h"
#include <QProcess>
2021-12-30 10:27:03 +08:00
#include <QDateTime>
#include <QRegularExpression>
2021-12-06 14:55:00 +08:00
#include <QDebug>
#include "../common/utils.h"
IMPLEMENT_DYNCREATE(DeleteBackupProxy)
DeleteBackupProxy::DeleteBackupProxy()
{}
DeleteBackupProxy::~DeleteBackupProxy()
{}
void DeleteBackupProxy::doWorkEx()
{
qDebug() << "DeleteBackupProxy::doWorkEx invoke begin";
2021-12-06 14:55:00 +08:00
// 1、删除/backup/snapshots/backuplist.xml对应项
if (!deleteXmlBackupPoint())
return;
// 2、删除/backup/snapshots/{uuid}对应目录
deleteBackupPointDir();
// 3、同时删除唯一识别文件中对应的条目
Utils::deleteBackupUniqueRecord(m_backupWrapper.m_backupName);
// 删除成功信号
emit workResult(true);
qDebug() << "DeleteBackupProxy::doWorkEx invoke end";
2021-12-06 14:55:00 +08:00
}
/**
* @brief /backup/snapshots/backuplist.xml对应项
*/
bool DeleteBackupProxy::deleteXmlBackupPoint()
{
qDebug() << "DeleteBackupProxy::deleteXmlBackupPoint invoke begin";
2021-12-06 14:55:00 +08:00
QString xmlPath;
if (m_backupWrapper.m_iPosition == BackupPosition::LOCAL || m_backupWrapper.m_iPosition == BackupPosition::CUSTOMIZE)
2021-12-06 14:55:00 +08:00
xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH;
else
xmlPath = m_backupWrapper.m_prefixDestPath + BACKUP_XML_PATH;
xmlPath.replace("//", "/");
ParseBackupList parse(xmlPath);
2022-02-22 15:25:28 +08:00
// 查询节点
2022-03-09 10:27:29 +08:00
m_backupPoint = parse.findBackupPointByUuid(m_backupWrapper.m_uuid);
2022-02-22 15:25:28 +08:00
// 删除节点
if (!m_backupWrapper.m_uuid.contains(QRegularExpression("^\\{.*-.*-.*-.*-.*\\}$")) || parse.deleteItem(m_backupWrapper.m_uuid) != ParseBackupList::SUCCESS) {
2021-12-06 14:55:00 +08:00
qCritical() << QString("failed to delete %1 from backuplist.xml!").arg(m_backupWrapper.m_uuid);
emit workResult(false);
return false;
}
qDebug() << "DeleteBackupProxy::deleteXmlBackupPoint invoke end";
2021-12-06 14:55:00 +08:00
return true;
}
/**
* @brief /backup/snapshots/uuid对应目录
*/
void DeleteBackupProxy::deleteBackupPointDir()
{
qDebug() << "DeleteBackupProxy::deleteBackupPointDir invoke begin";
2021-12-06 14:55:00 +08:00
QString uuidPath;
if (m_backupPoint.m_iPosition == BackupPosition::LOCAL)
2021-12-06 14:55:00 +08:00
uuidPath = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid;
else if (m_backupPoint.m_iPosition == BackupPosition::CUSTOMIZE)
uuidPath = m_backupPoint.m_path + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid;
2021-12-06 14:55:00 +08:00
else
uuidPath = m_backupWrapper.m_prefixDestPath + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid;
uuidPath.replace("//", "/");
QStringList args;
args << "-rf";
args << uuidPath;
QProcess::execute("rm", args);
2021-12-30 10:27:03 +08:00
QString time = QDateTime::currentDateTime().toString("yy-MM-dd hh:mm:ss");
2022-03-10 15:59:33 +08:00
if ( int(BackupType::BACKUP_DATA) == m_backupPoint.m_type
|| int(BackupType::INC_BACKUP_DATA) == m_backupPoint.m_type) {
2022-03-09 10:27:29 +08:00
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)+ "," + m_backupPoint.m_backupName);
2022-02-22 15:25:28 +08:00
} else {
2022-03-09 10:27:29 +08:00
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,,," + m_backupPoint.m_backupName);
2022-02-22 15:25:28 +08:00
}
qDebug() << "DeleteBackupProxy::deleteBackupPointDir invoke end";
2021-12-06 14:55:00 +08:00
}