yhkylin-backup-tools/common/mydefine.h

295 lines
8.5 KiB
C
Raw Normal View History

2022-11-01 10:40:05 +08:00
#ifndef MYDEFINE_H
#define MYDEFINE_H
#include <QString>
#include <QStringList>
#include <QMetaType>
#include <QDBusArgument>
#define DEFAULT_APP_PATH "/usr/bin"
#define BACKUP_PATH "/backup"
#define BACKUP_SNAPSHOTS_PATH "/backup/snapshots"
#define BACKUP_XML_PATH "/backup/snapshots/backuplist.xml"
#define EXCLUDE_FILE_PATH "/backup/snapshots/.exclude"
#define CHECK_PATH "/backup/snapshots/check/data/"
#define BACKUP_LOG_TEXT_PATH "/backup/log.txt"
#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 GHOST_PATH "/ghost"
#define DATA_PATH "/data"
#define BOOTINFO_PATH "/etc/.bootinfo"
#define FSTAB_PATH "/etc/fstab"
#define LOCK_FILE "/tmp/lock/kylin-backup.lock"
#define LOCK_FILE_PATH "/tmp/lock"
#define PROC_LOG "/var/log/backup.log"
#define FILE_IF_SYNC "/etc/file_if_sync"
#define BACKUP_CLI_NAME "kybackup"
#define AUTO_BACKUP_UUID "{01234567-0123-0123-0123-0123456789ab}"
#define FACTORY_BACKUP_UUID "{00000000-0000-0000-0000-000000000000}"
#define PATHS_USER_FILE ".user.txt"
#define EXCLUDE_PATHS_USER_FILE ".exclude.user.txt"
#define BACKUP_PARSE_STATE_SUCCESS_STRTING "backup finished"
#define BACKUP_PARSE_STATE_FAIL_STRTING "backup unfinished"
#define BACKUP_PARSE_STATE_INC_SUCCESS_STRTING "inc backup finished"
#define BACKUP_PARSE_STATE_INC_FAIL_STRTING "inc backup unfinished"
#define THEME_YHKYLIN_BACKUP_TOOLS "yhkylin-backup-tools"
#define PID_STRING_LEN 1024
// 蓝色
#define COLOR_BLUE "#3790FA"
// 蓝黑
#define COLOR_BLUE_DARK "#3B4251"
// 浅灰
#define COLOR_LIGHT_DARK "#F4F4F4"
// 灰色
#define COLOR_GRAY "#CCCCCC"
// 深灰
#define COLOR_DARK_GRAY "#393A3E"
// 黑灰
#define COLOR_BLACK_GRAY "#2D2E32"
// 字体灰色
#define COLOR_DISABLE_GRAY "#737373"
// 黄色
#define COLOR_YELLOW "#F8A34C"
// 浅蓝
#define COLOR_LIGHT_BLUE "#DDEBFF"
#define END_LINE "\n"
/**
* @brief
*/
enum BackupType {
// 系统备份
BACKUP_SYSTEM = 0,
// 增量系统备份
INC_BACKUP_SYSTEM = 1,
// 数据备份
BACKUP_DATA = 2,
// 增量数据备份
INC_BACKUP_DATA = 3,
// 系统还原
RESTORE_SYSTEM = 4,
// 保留用户数据还原
RESTORE_SYSTEM_WITH_DATA = 5,
// 数据还原
RESTORE_DATA = 6,
// 增量数据还原,实际没有这个类型,为兼容以前的数据仍然保留
INC_RESTORE_DATA = 7,
// 删除备份点
DELETE_BACKUP = 8,
// ghost镜像
GHOST_IMAGE = 9,
// 仅仅初始化BackupType枚举类变量用没有用于持久化不用固定其值
BACKUP_TYPE_INIT,
};
/**
* @brief
*/
struct BackupWrapper {
// 操作类型,如:系统备份, 系统还原
int m_type = -1;
// 本地备份还是U盘备份: 0-本地备份1-移动设备备份;2-异机备份3-自定义路径
int m_iPosition = -1;
// 备份名称,用于识别备份的,默认是时间
QString m_comment;
// 备份名称用来替换m_comment
QString m_backupName;
// 备份或还原指定的UUID
QString m_uuid;
// 待备份目录
QStringList m_backupPaths;
// 备份需要排除的路径
QStringList m_backupExcludePaths;
// 移动设备挂载路径:备份目标路径/还原点路径(前缀),在向移动设备备份(或从移动设备还原)时使用它来指定对应的移动设备路径
QString m_prefixDestPath;
// 备注信息
QString m_note;
// 备份用户名
QString m_frontUserName;
// 备份用户id
int m_frontUid = -1;
// 备份用户所属组id
int m_gid = -1;
// 是否异机备份点: 0-本机备份1-异机备份
int m_isOtherMachine = 0;
// 下面参数不是入参,是服务端自行跟随业务场景设置
// 是否增量备份
bool m_bIncrement = false;
// 新增备份点时增量备份的基准uuid
QString m_baseUuid;
// 备份时间(暂用于日志查询)
QString m_time;
// 备份大小(暂用于日志查询)
QString m_size;
static void registerMetaType();
};
Q_DECLARE_METATYPE(BackupWrapper)
extern QDBusArgument &operator<<(QDBusArgument &argument, const BackupWrapper &backupWrapper);
extern const QDBusArgument &operator>>(const QDBusArgument &argument, BackupWrapper &backupWrapper);
// 为兼容旧版本对外提供的接口,此处结构前面暂时不变,只在后面增加
enum class MountResult {
MOUNT_RESULT_INIT,
CANNOT_GET_BACKUPUUID,
NO_BLKID_EXIST,
NO_MOUNTED,
GENERATE_IMPORT_FILE_FAIL,
MOUNTED
};
/**
* @brief
*/
enum class BackupState {
// 准备中
PREPARING = 1,
// 工作中
WORKING,
// 空闲状态
BACKUP_STATE_INIT = 99
};
/**
* @brief
*/
enum BackupPosition
{
LOCAL, // 本地磁盘
UDISK, // 移动设备
OTHER, // 移动设备中的其它机器的备份点
CUSTOMIZE, // 自定义路径
};
/**
* @brief
* @note
*/
enum class BackupResult {
// 备份初始
BACKUP_RESULT_INIT,
// /etc/.bootinfo读取失败
ETC_BOOTINFO_READ_FAIL,
// /etc/fstab不存在
FSTAB_IS_NOT_EXIST,
// 文件锁定应用失败
LOCK_PROGRAM_FAIL,
//有其他正在进行的备份或者还原
OTHER_BACKUP_OR_RESTORE_RUNNING,
// 有删除任务正在进行
RM_RUNNING,
// 正在制作镜像
MKSQUASHFS_RUNNING,
// 设备uuid不存在
NO_BLKID_EXIST,
// 挂载/backup分区失败
BACKUP_PARTITION_MOUNT_FAIL,
// 生成备份导入文件失败
GENERATE_BACKUP_IMPORT_FILE_FAIL,
// /backup/current目录不存在
BACKUP_CURRENT_DIR_IS_NOT_EXIST,
// /backup/snapshots目录不存在
BACKUP_SNAPSHOTS_DIR_IS_NOT_EXIST,
// /backup/snapshots/backuplist.xml文件不存在或打开失败
BACKUP_STORAGEINFO_FILE_FAIL_TO_OPEN,
// /backup/snapshots/backuplist.xml格式不正确
BACKUP_STORAGEINFO_IS_NOT_CORRECT,
// 写入 /backup/snapshots/backuplist.xml 失败
WRITE_STORAGEINFO_ADD_ITEM_FAIL,
// 修改 /backup/snapshots/backuplist.xml 失败
WRITE_STORAGEINFO_UPDATE_ITEM_FAIL,
// 增量备份未找到对应的uuid
INC_NOT_FOUND_UUID,
// 增量备份(或还原)未找到对应的目录
INC_NOT_FOUND_DIR,
// 将备份路径写入(或读出)/backup/snapshots/{uuid}/.user.txt失败
WRITE_BACKUP_PATHS_TO_USER_FAILED,
// 将备份路径写入(或读出)/backup/snapshots/{uuid}/.exclude.user.txt失败
WRITE_EXCLUDE_BACKUP_PATHS_TO_USER_FAILED,
// /backup备份空间不足
BACKUP_CAPACITY_IS_NOT_ENOUGH,
// U盘文件系统是只读的
UDISK_FILESYSTEM_IS_READONLY,
// u盘中创建目录/backup/snapshots失败
UDISK_STH_ERROR,
// u盘文件系统是vfat格式容量有限或单个文件大小有限
UDISK_FILESYSTEM_TYPE_IS_VFAT,
// DU计算大小失败
DU_ERR,
// 向U盘备份时先压缩到本地成img文件本地备份分区空间不足
BACKUP_CAPACITY_FOR_UDISKIMG_IS_NOT_ENOUGH,
// U盘容量不足
UDISK_CAPACITY_IS_NOT_ENOUGH,
// /boot/efi同步失败
EFI_RSYNC_FAIL,
// 备份启动失败
BACKUP_PROCESS_START_FAIL,
// 备份失败
BACKUP_PROCESS_DO_FAIL,
// 备份进程成功启动
BACKUP_START_SUCCESS,
// 备份成功,信号未使用此结果
BACKUP_DO_SUCCESS,
// 还原初始
RESTORE_RESULT_INIT,
// 还原目录准备失败
RESTOREDIR_PREPARE_FAILED,
// 还原进程开启失败
RESTORE_PROCESS_START_FAIL,
// 还原失败
RESTORE_PROCESS_DO_FAIL,
// 还原成功开始
RESTORE_START_SUCCESS,
// 还原成功,信号未使用此结果
RESTORE_DO_SUCCESS,
// ghost镜像未找到备份点
GHOST_CANNOT_FIND_BACKUPPOINT,
// ghost源目录不存在
GHOST_SRC_DIRECTORY_IS_NOT_EXIST,
// ghost进程启动失败
GHOST_PROCESS_START_FAIL,
// ghost进程启动成功
GHOST_START_SUCCESS,
// 后面的为新版本新增部分
// 根据操作类型动态创建处理类失败
NO_FOUND_DEALCLASS,
// 环境检测成功
CHECK_ENV_SUCCESS,
// mksquashfs启动成功
MKSQUASHFS_START_SUCCESS,
// mksquashfs压缩img文件失败
MKSQUASHFS_DO_FAIL,
// mksquashfs压缩img文件成功开始转移img文件到u盘
MKSQUASHFS_DO_SUCCESS,
// 开始取消操作
START_CANCEL,
// 取消操作成功
CANCEL_SUCCESS,
};
#endif // MYDEFINE_H