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

88 lines
2.7 KiB
C++
Raw 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>
2021-12-06 14:55:00 +08:00
#include <QDebug>
#include "../common/utils.h"
IMPLEMENT_DYNCREATE(DeleteBackupProxy)
DeleteBackupProxy::DeleteBackupProxy()
{}
DeleteBackupProxy::~DeleteBackupProxy()
{}
void DeleteBackupProxy::doWorkEx()
{
// 1、删除/backup/snapshots/backuplist.xml对应项
if (!deleteXmlBackupPoint())
return;
// 2、删除/backup/snapshots/{uuid}对应目录
deleteBackupPointDir();
// 3、同时删除唯一识别文件中对应的条目
Utils::deleteBackupUniqueRecord(m_backupWrapper.m_backupName);
// 删除成功信号
emit workResult(true);
}
/**
* @brief /backup/snapshots/backuplist.xml对应项
*/
bool DeleteBackupProxy::deleteXmlBackupPoint()
{
QString xmlPath;
if (m_backupWrapper.m_iPosition == BackupPosition::LOCAL)
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
// 查询节点
ParseBackupList::BackupPoint backupPoint = parse.findBackupPointByUuid(m_backupWrapper.m_uuid);
if ( int(BackupType::BACKUP_DATA) != backupPoint.m_type
&& int(BackupType::INC_BACKUP_DATA) != backupPoint.m_type) {
m_backupWrapper.m_type = backupPoint.m_type;
}
// 删除节点
2021-12-06 14:55:00 +08:00
if (parse.deleteItem(m_backupWrapper.m_uuid) != ParseBackupList::SUCCESS) {
qCritical() << QString("failed to delete %1 from backuplist.xml!").arg(m_backupWrapper.m_uuid);
emit workResult(false);
return false;
}
return true;
}
/**
* @brief /backup/snapshots/uuid对应目录
*/
void DeleteBackupProxy::deleteBackupPointDir()
{
QString uuidPath;
if (m_backupWrapper.m_iPosition == BackupPosition::LOCAL)
uuidPath = Utils::getSysRootPath() + BACKUP_SNAPSHOTS_PATH + "/" + m_backupWrapper.m_uuid;
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-02-22 15:25:28 +08:00
if ( int(BackupType::BACKUP_DATA) == m_backupWrapper.m_type
|| int(BackupType::INC_BACKUP_DATA) == m_backupWrapper.m_type) {
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,," + QString::number(m_backupWrapper.m_frontUid)+ "," + m_backupWrapper.m_backupName);
} else {
Utils::writeBackupLog(time + "," + m_backupWrapper.m_uuid + "," + QString::number(m_backupWrapper.m_type) + ",,,," + m_backupWrapper.m_backupName);
}
2021-12-06 14:55:00 +08:00
}