yhkylin-backup-tools/common/mydefine.h

228 lines
6.4 KiB
C
Raw Normal View History

2021-08-06 10:20:03 +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"
2021-08-17 10:07:35 +08:00
#define BACKUP_XML_PATH "/backup/snapshots/backuplist.xml"
2021-08-06 10:20:03 +08:00
#define EXCLUDE_FILE_PATH "/backup/snapshots/.exclude"
2021-08-19 19:24:49 +08:00
#define CHECK_PATH "/backup/snapshots/check/data/"
2021-08-06 10:20:03 +08:00
2021-08-17 10:07:35 +08:00
#define BOOTINFO_PATH "/etc/.bootinfo"
2021-08-06 10:20:03 +08:00
#define FSTAB_PATH "/etc/fstab"
2021-08-17 10:07:35 +08:00
#define LOCK_FILE "/tmp/lock/kylin-backup.lock"
#define LOCK_FILE_PATH "/tmp/lock"
#define PROC_LOG "/var/log/backup.log"
2021-08-06 10:20:03 +08:00
#define BACKUP_CLI_NAME "kybackup"
2021-08-24 18:08:18 +08:00
#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"
2021-08-06 10:20:03 +08:00
#define PID_STRING_LEN 1024
/**
* @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,
// 自动升级模块的自动备份
AUTO_BACKUP_SYSTEM = 10,
// 仅仅初始化BackupType枚举类变量用没有用于持久化不用固定其值
BACKUP_TYPE_INIT,
};
/**
* @brief
*/
struct BackupWrapper {
// 操作类型,如:系统备份, 系统还原
int m_type = 0;
// 本地备份还是U盘备份: 0-本地备份1-移动设备备份
int m_iPosition = 0;
// 备份名称,用于识别备份的,默认是时间
QString m_comment;
// 备份名称用来替换m_comment
QString m_backupName;
// 备份或还原指定的UUID
QString m_uuid;
// 待备份目录
QStringList m_backupPaths;
// 备份需要排除的路径
QStringList m_backupExcludePaths;
2021-08-24 18:08:18 +08:00
// 备份目标路径(前缀),在向移动设备备份时使用它来指定对应的移动设备路径
QString m_prefixDestPath;
2021-08-06 10:20:03 +08:00
// 备注信息
QString m_note;
// 备份用户名
QString m_frontUserName;
// 备份用户id
int m_frontUid = -1;
// 备份用户所属组id
int m_gid = -1;
2021-08-17 10:07:35 +08:00
// 是否增量备份
bool m_bIncrement = false;
2021-08-19 19:24:49 +08:00
// 新增备份点时增量备份的基准uuid
QString m_baseUuid;
2021-08-06 10:20:03 +08:00
static void registerMetaType();
};
Q_DECLARE_METATYPE(BackupWrapper)
extern QDBusArgument &operator<<(QDBusArgument &argument, const BackupWrapper &backupWrapper);
extern const QDBusArgument &operator>>(const QDBusArgument &argument, BackupWrapper &backupWrapper);
/**
* @brief
*/
enum class BackupState {
// 准备中
PREPARING = 1,
// 工作中
WORKING,
// 空闲状态
BACKUP_STATE_INIT = 99
};
/**
* @brief
*/
enum BackupPosition
{
LOCAL,
UDISK,
};
/**
* @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,
2021-08-24 18:08:18 +08:00
CHECK_ENV_SUCCESS,
2021-08-06 10:20:03 +08:00
};
#endif // MYDEFINE_H