diff --git a/backup-daemon/systembackupproxy.cpp b/backup-daemon/systembackupproxy.cpp index 7f30e33..cec3764 100755 --- a/backup-daemon/systembackupproxy.cpp +++ b/backup-daemon/systembackupproxy.cpp @@ -424,6 +424,7 @@ bool SystemBackupProxy::backupSystem() connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { if (result) { m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING; + m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath)); QString xmlPath = Utils::getSysRootPath() + BACKUP_XML_PATH; xmlPath.replace("//", "/"); ParseBackupList parse(xmlPath); @@ -432,6 +433,7 @@ bool SystemBackupProxy::backupSystem() Utils::writeBackupLog(m_backupPoint.m_time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + "," + m_backupWrapper.m_note + "," + m_backupPoint.m_size); + Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName); m_bSuccess = true; } emit this->workResult(result); diff --git a/backup-daemon/udisksystembackupproxy.cpp b/backup-daemon/udisksystembackupproxy.cpp index f21595f..947ffcd 100644 --- a/backup-daemon/udisksystembackupproxy.cpp +++ b/backup-daemon/udisksystembackupproxy.cpp @@ -432,6 +432,7 @@ bool UDiskSystemBackupProxy::backup(const QStringList &args) connect(m_p, &RsyncPathToDirProcess::finished, this, [&](bool result) { if (result) { m_backupPoint.m_state = BACKUP_PARSE_STATE_SUCCESS_STRTING; + m_backupPoint.m_size = Utils::StringBySize(Utils::getDirOrFileSize(m_destPath)); QString xmlPath = m_backupWrapper.m_prefixDestPath + BACKUP_XML_PATH; xmlPath.replace("//", "/"); ParseBackupList parse(xmlPath); @@ -440,6 +441,8 @@ bool UDiskSystemBackupProxy::backup(const QStringList &args) Utils::writeBackupLog(m_backupPoint.m_time + "," + m_curUuid + "," + QString::number(m_backupWrapper.m_type) + "," + m_backupWrapper.m_note + "," + m_backupPoint.m_size); + + Utils::update_backup_unique_settings(m_curUuid, m_backupPoint.m_backupName); m_bSuccess = true; } emit this->workResult(result); diff --git a/common/mydefine.h b/common/mydefine.h index 282385d..959f70d 100755 --- a/common/mydefine.h +++ b/common/mydefine.h @@ -17,6 +17,7 @@ #define BACKUP_IMGBACKUP_PATH "/backup/imgbackup" #define IMGBACKUP_PATH "/imgbackup" #define UDISK_MKSQUASHFS_IMG_NAME "dst.img" +#define UDISK_UNIQUE_SETTINGS "/backup/udisk_unique_file" #define DATA_PATH "/data" diff --git a/common/utils.cpp b/common/utils.cpp index d528f1b..9e3b1b7 100755 --- a/common/utils.cpp +++ b/common/utils.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "mylittleparse.h" #include "mydefine.h" @@ -1005,3 +1007,37 @@ QHash Utils::getLeftSizeOfPartitions() } return hash; } + +/** + * @brief 获取文件夹或文件的大小 + * @param path 路径 + * @return 大小 + */ +qint64 Utils::getDirOrFileSize(const QString &path) +{ + char cmd[1024] = { 0 }; + sprintf(cmd, "du -sb '%s' 2>/dev/null | awk '{print $1}'", path.toLocal8Bit().data()); //s:total k:1024 bytes b:1 byte + + QString qsSize; + Utils::executeCMD(cmd, qsSize); + qsSize.replace("\n", ""); + qsSize = qsSize.trimmed(); + return qsSize.toLongLong(); +} + +/** + * @brief 记录下备份点uuid及其名称 + * @param uuid + * @param backupName + */ +void Utils::update_backup_unique_settings(const QString &uuid, const QString &backupName) +{ + // 由于历史原因(原来只校验U盘备份的唯一性),文件名暂不改变 + QString backupUniqueSetting = Utils::getSysRootPath() + UDISK_UNIQUE_SETTINGS; + backupUniqueSetting.replace("//", "/"); + QSettings udisk_unique_settings(backupUniqueSetting, QSettings::IniFormat); + udisk_unique_settings.setIniCodec(QTextCodec::codecForName("utf-8")); + udisk_unique_settings.beginGroup(backupName); + udisk_unique_settings.setValue("uuid", uuid); + udisk_unique_settings.endGroup(); +} diff --git a/common/utils.h b/common/utils.h index 9700850..7453d96 100755 --- a/common/utils.h +++ b/common/utils.h @@ -254,6 +254,20 @@ public: */ static QHash getLeftSizeOfPartitions(); + /** + * @brief 获取文件夹或文件的大小 + * @param path 路径 + * @return 大小 + */ + static qint64 getDirOrFileSize(const QString &path); + + /** + * @brief 记录下备份点uuid及其名称 + * @param uuid + * @param backupName + */ + static void update_backup_unique_settings(const QString &uuid, const QString &backupName); + private: // 系统根目录,默认"/" static QString m_sysRootPath;