Handles creation of, deletion of and switching between, bachups.
More...
#include <backupmanager.h>
|
| BackupManager ()=default |
| Empty default constructor.
|
|
void | addTarget (const std::filesystem::path &path, const std::string &name, const std::vector< std::string > &backup_names) |
| Adds a new target file or directory to be managed.
|
|
void | addTarget (const std::filesystem::path &path) |
| Adds a backup target which was previously managed by a BackupManager.
|
|
void | removeTarget (int target_id) |
| Removes the given target by deleting all relevant backups and config files.
|
|
void | addBackup (int target_id, const std::string &name, int source=-1) |
| Adds a new backup for the given target by copying the currently active backup.
|
|
void | removeBackup (int target_id, int backup_id, bool update_dirs=true) |
| Deletes the given backup for given target.
|
|
void | setActiveBackup (int target_id, int backup_id) |
| Changes the currently active backup for the given target.
|
|
void | setProfile (int profile) |
| Sets the active profile to the new profile and changes all active backups if needed.
|
|
void | addProfile (int source=-1) |
| Adds a new profile.
|
|
void | removeProfile (int profile) |
| Removes the given profile.
|
|
std::vector< BackupTarget > | getTargets () const |
| Returns a vector containing information about all managed backup targets.
|
|
void | reset () |
| Deletes all entries in targets_ as well as all profiles.
|
|
int | getNumTargets () |
| Returns the number of backup targets.
|
|
int | getNumBackups (int target_id) |
| Returns the number of backups for the given target.
|
|
void | setBackupName (int target_id, int backup_id, const std::string &name) |
| Setter for the name of a backup belonging to the given target.
|
|
void | setBackupTargetName (int target_id, const std::string &name) |
| Setter for the name of a backup target.
|
|
void | overwriteBackup (int target_id, int source_backup, int dest_backup) |
| Deletes all files in the dest backup and replaces them with the files from the source backup.
|
|
void | setLog (const std::function< void(Log::LogLevel, const std::string &)> &new_log) |
| Setter for log callback.
|
|
|
void | updateDirectories () |
| Ensures consistency with the data on disk.
|
|
void | updateDirectories (int target_id) |
| Ensures consistency with the data on disk.
|
|
void | updateState () |
| Updates internal state by parsing every targets state file.
|
|
void | updateSettings () |
| Updates every targets state file with the internal state.
|
|
void | writeSettings (const std::filesystem::path &path, const Json::Value &settings) const |
| Writes the given json object to disk.
|
|
Json::Value | readSettings (const std::filesystem::path &path) const |
| Reads the given file and creates a json object from the files data.
|
|
std::filesystem::path | getConfigPath (const std::filesystem::path &path) const |
| Returns the path to the file which contains state data for the given file or directory.
|
|
std::filesystem::path | getBackupPath (const std::filesystem::path &path, int backup) const |
| Returns the path to the given backup for the given file or directory.
|
|
std::filesystem::path | getBackupPath (int target, int backup) const |
| Returns the path to the given existing backup for the given target.
|
|
|
std::vector< BackupTarget > | targets_ {} |
| Contains all managed targets.
|
|
int | num_profiles_ = 0 |
| Number of profiles.
|
|
int | cur_profile_ = -1 |
| Currently active profile.
|
|
std::function< void(Log::LogLevel, const std::string &)> | log_ |
| Callback for logging.
|
|
|
static const std::string | BAK_EXTENSION = ".lmmbakman" |
| File extension used for backups.
|
|
static const std::string | JSON_EXTENSION = BAK_EXTENSION + ".json" |
| File extension used for the files used to store a targets state.
|
|
Handles creation of, deletion of and switching between, bachups.
◆ addBackup()
void BackupManager::addBackup |
( |
int | target_id, |
|
|
const std::string & | name, |
|
|
int | source = -1 ) |
Adds a new backup for the given target by copying the currently active backup.
- Parameters
-
target_id | Target for which to create a new backup. |
name | Display name for the new backup. |
source | Backup from which to copy files to create the new backup. If -1: copy currently active backup. |
◆ addProfile()
void BackupManager::addProfile |
( |
int | source = -1 | ) |
|
Adds a new profile.
- Parameters
-
source | If this refers to an existing backup: Copy the active backups from that profile. |
◆ addTarget() [1/2]
void BackupManager::addTarget |
( |
const std::filesystem::path & | path | ) |
|
Adds a backup target which was previously managed by a BackupManager.
- Parameters
-
path | Path to the target file or directory. |
◆ addTarget() [2/2]
void BackupManager::addTarget |
( |
const std::filesystem::path & | path, |
|
|
const std::string & | name, |
|
|
const std::vector< std::string > & | backup_names ) |
Adds a new target file or directory to be managed.
- Parameters
-
path | Path to the target file or directory. |
name | Display name for this target. |
backup_names | Display names for initial backups. Must contain at least one. |
◆ getBackupPath() [1/2]
std::filesystem::path BackupManager::getBackupPath |
( |
const std::filesystem::path & | path, |
|
|
int | backup ) const |
|
private |
Returns the path to the given backup for the given file or directory.
- Parameters
-
path | Path to a backup target. |
backup | Backup id for the given target. |
- Returns
- The path.
◆ getBackupPath() [2/2]
sfs::path BackupManager::getBackupPath |
( |
int | target, |
|
|
int | backup ) const |
|
private |
Returns the path to the given existing backup for the given target.
- Parameters
-
path | target Target for which to find the path. |
backup | Backup id for the given target. |
- Returns
- The path.
◆ getConfigPath()
sfs::path BackupManager::getConfigPath |
( |
const std::filesystem::path & | path | ) |
const |
|
private |
Returns the path to the file which contains state data for the given file or directory.
- Parameters
-
path | File or directory for which to generate the path. |
- Returns
- The path.
◆ getNumBackups()
int BackupManager::getNumBackups |
( |
int | target_id | ) |
|
Returns the number of backups for the given target.
- Parameters
-
- Returns
- The number of backups.
◆ getTargets()
std::vector< BackupTarget > BackupManager::getTargets |
( |
| ) |
const |
Returns a vector containing information about all managed backup targets.
- Returns
- The vector.
◆ overwriteBackup()
void BackupManager::overwriteBackup |
( |
int | target_id, |
|
|
int | source_backup, |
|
|
int | dest_backup ) |
Deletes all files in the dest backup and replaces them with the files from the source backup.
- Parameters
-
target_id | Backup target. |
source_backup | Backup from which to copy files. |
dest_backup | Target for data deletion. |
◆ readSettings()
Json::Value BackupManager::readSettings |
( |
const std::filesystem::path & | path | ) |
const |
|
private |
Reads the given file and creates a json object from the files data.
- Parameters
-
- Returns
- The json object created from the file.
◆ removeBackup()
void BackupManager::removeBackup |
( |
int | target_id, |
|
|
int | backup_id, |
|
|
bool | update_dirs = true ) |
Deletes the given backup for given target.
- Parameters
-
target_id | Target from which to delete a backup. |
backup_id | Backup to remove. |
update_dirs | If true: Repair the target if it is in an invalid state, e.g. if a backup has been manually deleted. |
◆ removeProfile()
void BackupManager::removeProfile |
( |
int | profile | ) |
|
Removes the given profile.
- Parameters
-
profile | Profile to be removed. |
◆ removeTarget()
void BackupManager::removeTarget |
( |
int | target_id | ) |
|
Removes the given target by deleting all relevant backups and config files.
- Parameters
-
target_id | Target to remove. |
◆ setActiveBackup()
void BackupManager::setActiveBackup |
( |
int | target_id, |
|
|
int | backup_id ) |
Changes the currently active backup for the given target.
- Parameters
-
target_id | Target for which to change the active backup. |
backup_id | New active backup. |
◆ setBackupName()
void BackupManager::setBackupName |
( |
int | target_id, |
|
|
int | backup_id, |
|
|
const std::string & | name ) |
Setter for the name of a backup belonging to the given target.
- Parameters
-
target_id | Backup target. |
backup_id | Backup to be edited. |
name | The new name. |
◆ setBackupTargetName()
void BackupManager::setBackupTargetName |
( |
int | target_id, |
|
|
const std::string & | name ) |
Setter for the name of a backup target.
- Parameters
-
target_id | Backup target. |
name | The new name. |
◆ setLog()
void BackupManager::setLog |
( |
const std::function< void(Log::LogLevel, const std::string &)> & | new_log | ) |
|
Setter for log callback.
- Parameters
-
◆ setProfile()
void BackupManager::setProfile |
( |
int | profile | ) |
|
Sets the active profile to the new profile and changes all active backups if needed.
- Parameters
-
profile | New active profile. |
◆ updateDirectories() [1/2]
void BackupManager::updateDirectories |
( |
| ) |
|
|
private |
Ensures consistency with the data on disk.
This is accomplished by deleting backups for which no file exists and files on disk which should by filename and extension be a backup but have an invalid id. This is done for all files matching the filename and path of any target.
◆ updateDirectories() [2/2]
void BackupManager::updateDirectories |
( |
int | target_id | ) |
|
|
private |
Ensures consistency with the data on disk.
This is accomplished by deleting backups for which no file exists and renaming files on disk which should by filename and extension be a backup but have an invalid id. This is done for all files matching the filename and path of the given target.
- Parameters
-
target_id | Target to check. |
◆ writeSettings()
void BackupManager::writeSettings |
( |
const std::filesystem::path & | path, |
|
|
const Json::Value & | settings ) const |
|
private |
Writes the given json object to disk.
- Parameters
-
path | Path to write to. |
settings | The json object. |
◆ log_
std::function<void(Log::LogLevel, const std::string&)> BackupManager::log_ |
|
private |
Initial value:
const std::string& b) {}
LogLevel
Represents the importance of a log message.
Definition log.h:19
Callback for logging.
The documentation for this class was generated from the following files: