mirror of
https://github.com/uroni/urbackup_backend.git
synced 2025-10-26 11:36:50 +00:00
Mount backup storage on client startup
This commit is contained in:
parent
2d6aa10905
commit
0711655c21
@ -21,6 +21,7 @@
|
||||
#include "../Interface/Server.h"
|
||||
#include <dokan/dokan.h>
|
||||
#include <sddl.h>
|
||||
#include "../stringtools.h"
|
||||
|
||||
static NTSTATUS DOKAN_CALLBACK
|
||||
DokanCreateFile(LPCWSTR FileName, PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
|
||||
@ -158,9 +159,25 @@ DokanFindFiles(LPCWSTR FileName,
|
||||
if (*FileName == '\\')
|
||||
offs = 1;
|
||||
|
||||
std::vector<SFile> files = fs->listFiles(Server->ConvertFromWchar(FileName + offs));
|
||||
std::string ldir = Server->ConvertFromWchar(FileName + offs);
|
||||
|
||||
int top_path = 0;
|
||||
for (char ch : ldir)
|
||||
if (ch == '\\')
|
||||
++top_path;
|
||||
|
||||
std::vector<SFile> files = fs->listFiles(ldir);
|
||||
for (SFile& file : files)
|
||||
{
|
||||
if (!ldir.empty() && top_path == 0 &&
|
||||
(file.name == ".hashes" ||
|
||||
next(file.name, 0, ".symlink_")))
|
||||
continue;
|
||||
|
||||
if (ldir.empty() &&
|
||||
file.name.find(".new") != std::string::npos)
|
||||
continue;
|
||||
|
||||
WIN32_FIND_DATAW find_data = {};
|
||||
std::wstring wfilename = Server->ConvertToWchar(file.name);
|
||||
memcpy(find_data.cFileName, wfilename.c_str(), (std::min)(259ULL, wfilename.size()*sizeof(wchar_t)));
|
||||
|
||||
@ -138,7 +138,16 @@ bool FilesystemManager::mountFileSystem(const std::string& url, const std::strin
|
||||
|
||||
IBackupFileSystem* fs = filesystems[url];
|
||||
|
||||
return dokany_mount(fs, mount_path);
|
||||
std::thread dm([url, fs, mount_path]() {
|
||||
if (!dokany_mount(fs, mount_path))
|
||||
{
|
||||
Server->Log("Mounting fs " + url + " at \"" + mount_path + "\" failed", LL_ERROR);
|
||||
}
|
||||
});
|
||||
|
||||
dm.detach();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IBackupFileSystem* FilesystemManager::getFileSystem(const std::string& path)
|
||||
@ -151,3 +160,68 @@ IBackupFileSystem* FilesystemManager::getFileSystem(const std::string& path)
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void FilesystemManager::startupMountFileSystems()
|
||||
{
|
||||
std::vector<SFile> facet_dirs = getFiles("urbackup");
|
||||
|
||||
for (SFile& fdir : facet_dirs)
|
||||
{
|
||||
if (!fdir.isdir || !next(fdir.name, 0, "data_"))
|
||||
continue;
|
||||
|
||||
int facet_id = watoi(getafter("data_", fdir.name));
|
||||
|
||||
std::vector<SFile> settings_files = getFiles("urbackup/" + fdir.name);
|
||||
|
||||
for (SFile& sfn : settings_files)
|
||||
{
|
||||
if (sfn.isdir ||
|
||||
(sfn.name != "settings.cfg" &&
|
||||
!next(sfn.name, 0, "settings_")))
|
||||
continue;
|
||||
|
||||
std::string clientsubname;
|
||||
if (sfn.name != "settings.cfg")
|
||||
{
|
||||
clientsubname = getbetween("settings_", ".cfg", sfn.name);
|
||||
|
||||
if (clientsubname.empty())
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string dest, dest_params, computername;
|
||||
str_map dest_secret_params;
|
||||
size_t max_backups = 1;
|
||||
std::string perm_uid;
|
||||
if (!ClientConnector::getBackupDest(clientsubname, facet_id, dest,
|
||||
dest_params, dest_secret_params, computername, max_backups, perm_uid))
|
||||
continue;
|
||||
|
||||
std::string backups_mpath;
|
||||
|
||||
if (facet_id != 1)
|
||||
backups_mpath += std::to_string(facet_id);
|
||||
|
||||
if (!clientsubname.empty())
|
||||
{
|
||||
if (!backups_mpath.empty())
|
||||
backups_mpath += "_";
|
||||
|
||||
backups_mpath += clientsubname;
|
||||
}
|
||||
|
||||
backups_mpath = "backups" + backups_mpath;
|
||||
|
||||
|
||||
if (!os_directory_exists(backups_mpath)
|
||||
&& !os_create_dir(backups_mpath))
|
||||
continue;
|
||||
|
||||
std::string fmpath = os_get_final_path(backups_mpath);
|
||||
|
||||
mountFileSystem(dest, dest_params, dest_secret_params,
|
||||
fmpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@ public:
|
||||
const str_map& secret_params, const std::string& mount_path);
|
||||
|
||||
static IBackupFileSystem* getFileSystem(const std::string& url);
|
||||
|
||||
static void startupMountFileSystems();
|
||||
private:
|
||||
|
||||
static std::mutex mutex;
|
||||
|
||||
@ -577,6 +577,11 @@ DLLEXPORT void LoadActions(IServer* pServer)
|
||||
cacheVolumes();
|
||||
#endif
|
||||
|
||||
std::thread sm([]() {
|
||||
FilesystemManager::startupMountFileSystems();
|
||||
});
|
||||
sm.detach();
|
||||
|
||||
Server->Log("Started UrBackupClient Backend...", LL_INFO);
|
||||
Server->wait(1000);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user