mirror of
https://github.com/uroni/urbackup_backend.git
synced 2025-10-26 11:36:50 +00:00
Add file entries every min_file_incr times for each file.
The client may not be trusted => Setting to force the server to read and calculate the respective file hashes instead of trusting the client
This commit is contained in:
parent
01082fab4c
commit
cc05a512e1
3
urbackupcommon/adler32.h
Normal file
3
urbackupcommon/adler32.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
unsigned int adler32(unsigned int adler, const char *buf, unsigned int len);
|
||||
@ -120,5 +120,6 @@ std::vector<std::wstring> getGlobalSettingsList(void)
|
||||
ret.push_back(L"global_soft_fs_quota");
|
||||
ret.push_back(L"filescache_type");
|
||||
ret.push_back(L"filescache_size");
|
||||
ret.push_back(L"trust_client_hashes");
|
||||
return ret;
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
lib_LTLIBRARIES = liburbackupserver.la
|
||||
liburbackupserver_la_SOURCES = dllmain.cpp ../stringtools.cpp ../urbackupcommon/os_functions_lin.cpp server.cpp server_get.cpp server_hash.cpp server_image.cpp ../urbackupcommon/sha2/sha2.c ../common/data.cpp fileclient/FileClient.cpp ../urbackupcommon/fileclient/tcpstack.cpp server_prepare_hash.cpp server_update.cpp server_status.cpp server_channel.cpp server_ping.cpp server_log.cpp ../urbackupcommon/escape.cpp server_writer.cpp ../urbackupcommon/bufmgr.cpp server_running.cpp server_cleanup.cpp server_settings.cpp server_update_stats.cpp serverinterface/helper.cpp ../urbackupcommon/json.cpp serverinterface/lastacts.cpp serverinterface/login.cpp serverinterface/progress.cpp serverinterface/salt.cpp serverinterface/users.cpp serverinterface/piegraph.cpp serverinterface/usage.cpp serverinterface/usagegraph.cpp serverinterface/status.cpp serverinterface/settings.cpp serverinterface/backups.cpp serverinterface/logs.cpp serverinterface/getimage.cpp serverinterface/download_client.cpp treediff/TreeDiff.cpp treediff/TreeNode.cpp treediff/TreeReader.cpp ChunkPatcher.cpp ../urbackupcommon/CompressedPipe.cpp InternetServiceConnector.cpp ../urbackupcommon/InternetServicePipe.cpp ../md5.cpp ../urbackupcommon/settingslist.cpp fileclient/FileClientChunked.cpp ../urbackupcommon/adler32.cpp server_archive.cpp filedownload.cpp serverinterface/shutdown.cpp snapshot_helper.cpp verify_hashes.cpp apps/cleanup_cmd.cpp apps/repair_cmd.cpp dao/ServerCleanupDao.cpp lmdb/mdb.c lmdb/midl.c MDBFileCache.cpp DatabaseFileCache.cpp create_files_cache.cpp FileCache.cpp SQLiteFileCache.cpp serverinterface/livelog.cpp serverinterface/start_backup.cpp serverinterface/create_zip.cpp server_dir_links.cpp dao/ServerBackupDao.cpp apps/export_auth_log.cpp server_download.cpp
|
||||
liburbackupserver_la_SOURCES = dllmain.cpp ../stringtools.cpp ../urbackupcommon/os_functions_lin.cpp server.cpp server_get.cpp server_hash.cpp server_image.cpp ../urbackupcommon/sha2/sha2.c ../common/data.cpp fileclient/FileClient.cpp ../urbackupcommon/fileclient/tcpstack.cpp server_prepare_hash.cpp server_update.cpp server_status.cpp server_channel.cpp server_ping.cpp server_log.cpp ../urbackupcommon/escape.cpp server_writer.cpp ../urbackupcommon/bufmgr.cpp server_running.cpp server_cleanup.cpp server_settings.cpp server_update_stats.cpp serverinterface/helper.cpp ../urbackupcommon/json.cpp serverinterface/lastacts.cpp serverinterface/login.cpp serverinterface/progress.cpp serverinterface/salt.cpp serverinterface/users.cpp serverinterface/piegraph.cpp serverinterface/usage.cpp serverinterface/usagegraph.cpp serverinterface/status.cpp serverinterface/settings.cpp serverinterface/backups.cpp serverinterface/logs.cpp serverinterface/getimage.cpp serverinterface/download_client.cpp treediff/TreeDiff.cpp treediff/TreeNode.cpp treediff/TreeReader.cpp ChunkPatcher.cpp ../urbackupcommon/CompressedPipe.cpp InternetServiceConnector.cpp ../urbackupcommon/InternetServicePipe.cpp ../md5.cpp ../urbackupcommon/settingslist.cpp fileclient/FileClientChunked.cpp ../urbackupcommon/adler32.cpp server_archive.cpp filedownload.cpp serverinterface/shutdown.cpp snapshot_helper.cpp verify_hashes.cpp apps/cleanup_cmd.cpp apps/repair_cmd.cpp dao/ServerCleanupDao.cpp lmdb/mdb.c lmdb/midl.c MDBFileCache.cpp DatabaseFileCache.cpp create_files_cache.cpp FileCache.cpp SQLiteFileCache.cpp serverinterface/livelog.cpp serverinterface/start_backup.cpp serverinterface/create_zip.cpp server_dir_links.cpp dao/ServerBackupDao.cpp apps/export_auth_log.cpp server_download.cpp server_hash_existing.cpp
|
||||
liburbackupserver_la_LDFLAGS = --no-undefined
|
||||
if WITH_FORTIFY
|
||||
AM_CPPFLAGS = -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2
|
||||
@ -22,5 +22,5 @@ endif
|
||||
$(INSTALL_DATA) $(INSTALL_OPTS) $(srcdir)/www/*.gif "$(DESTDIR)$(localstatedir)/urbackup/www/"
|
||||
$(INSTALL_DATA) $(INSTALL_OPTS) $(srcdir)/urbackup_dsa.pub "$(DESTDIR)$(localstatedir)/urbackup/urbackup_dsa.pub"
|
||||
$(INSTALL_DATA) $(INSTALL_OPTS) $(srcdir)/www/*.swf "$(DESTDIR)$(localstatedir)/urbackup/www/"
|
||||
noinst_HEADERS = server_ping.h server_cleanup.h ../urbackupcommon/os_functions.h server_image.h ../urbackupcommon/json.h serverinterface/helper.h serverinterface/action_header.h serverinterface/actions.h server_writer.h ../urbackupcommon/settings.h server_image.h server_settings.h zero_hash.h server_update.h server_log.h server_hash.h server_status.h ../urbackupcommon/bufmgr.h server_update_stats.h ../urbackupcommon/sha2/sha2.h ../md5.h fileclient/FileClient.h ../common/data.h fileclient/socket_header.h ../urbackupcommon/fileclient/tcpstack.h fileclient/packet_ids.h database.h mbr_code.h action_header.h ../urbackupcommon/escape.h server.h server_running.h server_prepare_hash.h actions.h server_channel.h server_get.h treediff/TreeDiff.h treediff/TreeNode.h treediff/TreeReader.h ../fileservplugin/IFileServFactory.h ../fileservplugin/IFileServ.h ../urlplugin/IUrlFactory.h ../urbackupcommon/capa_bits.h ../cryptoplugin/ICryptoFactory.h fileclient/FileClientChunked.h ChunkPatcher.h ../urbackupcommon/CompressedPipe.h ../urbackupcommon/InternetServicePipe.h ../urbackupcommon/InternetServiceIDs.h InternetServiceConnector.h ../md5.h ../urbackupcommon/settingslist.h server_archive.h ../cryptoplugin/IZlibCompression.h ../cryptoplugin/IZlibDecompression.h ../cryptoplugin/ICryptoFactory.h ../cryptoplugin/IAESEncryption.h ../cryptoplugin/IAESDecryption.h ../fileservplugin/chunk_settings.h ../urbackupcommon/internet_pipe_capabilities.h ../urbackupcommon/mbrdata.h filedownload.h snapshot_helper.h apps/cleanup_cmd.h apps/repair_cmd.h dao/ServerCleanupDao.h lmdb/lmdb.h lmdb/midl.h MDBFileCache.h DatabaseFileCache.h create_files_cache.h FileCache.h SQLiteFileCache.h serverinterface/rights.h ../common/miniz.c server_dir_links.h dao/ServerBackupDao.h apps/app.h apps/export_auth_log.h serverinterface/login.h server_download.h
|
||||
noinst_HEADERS = server_ping.h server_cleanup.h ../urbackupcommon/os_functions.h server_image.h ../urbackupcommon/json.h serverinterface/helper.h serverinterface/action_header.h serverinterface/actions.h server_writer.h ../urbackupcommon/settings.h server_image.h server_settings.h zero_hash.h server_update.h server_log.h server_hash.h server_status.h ../urbackupcommon/bufmgr.h server_update_stats.h ../urbackupcommon/sha2/sha2.h ../md5.h fileclient/FileClient.h ../common/data.h fileclient/socket_header.h ../urbackupcommon/fileclient/tcpstack.h fileclient/packet_ids.h database.h mbr_code.h action_header.h ../urbackupcommon/escape.h server.h server_running.h server_prepare_hash.h actions.h server_channel.h server_get.h treediff/TreeDiff.h treediff/TreeNode.h treediff/TreeReader.h ../fileservplugin/IFileServFactory.h ../fileservplugin/IFileServ.h ../urlplugin/IUrlFactory.h ../urbackupcommon/capa_bits.h ../cryptoplugin/ICryptoFactory.h fileclient/FileClientChunked.h ChunkPatcher.h ../urbackupcommon/CompressedPipe.h ../urbackupcommon/InternetServicePipe.h ../urbackupcommon/InternetServiceIDs.h InternetServiceConnector.h ../md5.h ../urbackupcommon/settingslist.h server_archive.h ../cryptoplugin/IZlibCompression.h ../cryptoplugin/IZlibDecompression.h ../cryptoplugin/ICryptoFactory.h ../cryptoplugin/IAESEncryption.h ../cryptoplugin/IAESDecryption.h ../fileservplugin/chunk_settings.h ../urbackupcommon/internet_pipe_capabilities.h ../urbackupcommon/mbrdata.h filedownload.h snapshot_helper.h apps/cleanup_cmd.h apps/repair_cmd.h dao/ServerCleanupDao.h lmdb/lmdb.h lmdb/midl.h MDBFileCache.h DatabaseFileCache.h create_files_cache.h FileCache.h SQLiteFileCache.h serverinterface/rights.h ../common/miniz.c server_dir_links.h dao/ServerBackupDao.h apps/app.h apps/export_auth_log.h serverinterface/login.h server_download.h ../urbackupcommon/adler32.h server_hash_existing.h
|
||||
EXTRA_DIST = backup_server.db ../urbackup/status.htm www/*.js www/*.htm www/*.css www/*.png www/*.gif www/*.ico urbackup_dsa.pub www/*.swf
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
#include "InternetServiceConnector.h"
|
||||
#include "server_update_stats.h"
|
||||
#include "../urbackupcommon/escape.h"
|
||||
#include "../urbackupcommon/adler32.h"
|
||||
#include "server_running.h"
|
||||
#include "server_cleanup.h"
|
||||
#include "treediff/TreeDiff.h"
|
||||
@ -39,6 +40,7 @@
|
||||
#include "../Interface/PipeThrottler.h"
|
||||
#include "snapshot_helper.h"
|
||||
#include "../cryptoplugin/ICryptoFactory.h"
|
||||
#include "server_hash_existing.h"
|
||||
#include "server_dir_links.h"
|
||||
#include "server.h"
|
||||
#include <algorithm>
|
||||
@ -125,6 +127,8 @@ BackupServerGet::BackupServerGet(IPipe *pPipe, sockaddr_in pAddr, const std::wst
|
||||
|
||||
last_file_backup_try=0;
|
||||
count_file_backup_try=0;
|
||||
|
||||
hash_existing_mutex = Server->createMutex();
|
||||
|
||||
}
|
||||
|
||||
@ -148,6 +152,8 @@ BackupServerGet::~BackupServerGet(void)
|
||||
local_hash->deinitDatabase();
|
||||
delete local_hash;
|
||||
}
|
||||
|
||||
Server->destroy(hash_existing_mutex);
|
||||
}
|
||||
|
||||
namespace
|
||||
@ -2292,8 +2298,12 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
}
|
||||
}
|
||||
|
||||
bool copy_file_entries_sparse = internet_connection && server_settings->getSettings()->internet_calculate_filehashes_on_client;
|
||||
int copy_file_entries_sparse_modulo = server_settings->getSettings()->min_file_incr;
|
||||
bool trust_client_hashes = server_settings->getSettings()->trust_client_hashes;
|
||||
|
||||
bool copy_file_entries=false;
|
||||
if(resumed_backup)
|
||||
if(resumed_backup || copy_file_entries_sparse)
|
||||
{
|
||||
copy_file_entries = backup_dao->createTemporaryNewFilesTable();
|
||||
copy_file_entries = copy_file_entries && backup_dao->createTemporaryLastFilesTable();
|
||||
@ -2302,8 +2312,12 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
if ( copy_file_entries )
|
||||
{
|
||||
copy_file_entries = copy_file_entries && backup_dao->copyToTemporaryLastFilesTable(last.backupid);
|
||||
|
||||
if(copy_file_entries && resumed_full)
|
||||
{
|
||||
copy_file_entries_sparse = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IFile *clientlist=Server->openFile("urbackup/clientlist_"+nconvert(clientid)+"_new.ub", MODE_WRITE);
|
||||
@ -2321,6 +2335,15 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
|
||||
THREADPOOL_TICKET server_download_ticket =
|
||||
Server->getThreadPool()->execute(server_download.get());
|
||||
|
||||
std::auto_ptr<ServerHashExisting> server_hash_existing;
|
||||
THREADPOOL_TICKET server_hash_existing_ticket = ILLEGAL_THREADPOOL_TICKET;
|
||||
if(copy_file_entries_sparse && !trust_client_hashes)
|
||||
{
|
||||
server_hash_existing.reset(new ServerHashExisting(clientid, this));
|
||||
server_hash_existing_ticket =
|
||||
Server->getThreadPool()->execute(server_hash_existing.get());
|
||||
}
|
||||
|
||||
char buffer[4096];
|
||||
_u32 read;
|
||||
@ -2373,6 +2396,7 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
backup_stopped=true;
|
||||
ServerLogger::Log(clientid, L"Server admin stopped backup.", LL_ERROR);
|
||||
server_download->queueSkip();
|
||||
server_hash_existing->queueStop(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2566,15 +2590,23 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
|
||||
bool copy_curr_file_entry=false;
|
||||
bool curr_has_hash = false;
|
||||
|
||||
if(indirchange==true || hasChange(line, diffs)) //is changed
|
||||
bool copy_curr_file_entry_sparse=false;
|
||||
std::string curr_sha2;
|
||||
{
|
||||
std::map<std::wstring, std::wstring>::iterator hash_it=( (local_hash==NULL)?extra_params.end():extra_params.find(L"sha512") );
|
||||
|
||||
bool f_ok=false;
|
||||
std::map<std::wstring, std::wstring>::iterator hash_it =
|
||||
( (local_hash==NULL)?extra_params.end():extra_params.find(L"sha512") );
|
||||
if(hash_it!=extra_params.end())
|
||||
{
|
||||
if(link_file(cf.name, osspecific_name, curr_path, curr_os_path, with_hashes, base64_decode_dash(wnarrow(hash_it->second)), cf.size, false))
|
||||
curr_sha2 = base64_decode_dash(wnarrow(hash_it->second));
|
||||
}
|
||||
}
|
||||
|
||||
if(indirchange==true || hasChange(line, diffs)) //is changed
|
||||
{
|
||||
bool f_ok=false;
|
||||
if(!curr_sha2.empty())
|
||||
{
|
||||
if(link_file(cf.name, osspecific_name, curr_path, curr_os_path, with_hashes, curr_sha2 , cf.size, false))
|
||||
{
|
||||
f_ok=true;
|
||||
}
|
||||
@ -2624,13 +2656,13 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
}
|
||||
++link_logcnt;
|
||||
|
||||
std::map<std::wstring, std::wstring>::iterator hash_it=( (local_hash==NULL)?extra_params.end():extra_params.find(L"sha512") );
|
||||
|
||||
if(hash_it!=extra_params.end())
|
||||
if(!curr_sha2.empty())
|
||||
{
|
||||
if(link_file(cf.name, osspecific_name, curr_path, curr_os_path, with_hashes, base64_decode_dash(wnarrow(hash_it->second)), cf.size, false))
|
||||
if(link_file(cf.name, osspecific_name, curr_path, curr_os_path, with_hashes, curr_sha2, cf.size, false))
|
||||
{
|
||||
f_ok=true;
|
||||
copy_curr_file_entry=copy_file_entries;
|
||||
copy_curr_file_entry_sparse = copy_file_entries_sparse;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2649,6 +2681,7 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
else //created hard link successfully
|
||||
{
|
||||
copy_curr_file_entry=copy_file_entries;
|
||||
copy_curr_file_entry_sparse = copy_file_entries_sparse;
|
||||
|
||||
if(with_hashes)
|
||||
{
|
||||
@ -2659,6 +2692,7 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
else
|
||||
{
|
||||
copy_curr_file_entry=copy_file_entries;
|
||||
copy_curr_file_entry_sparse = copy_file_entries_sparse;
|
||||
curr_has_hash = with_hashes;
|
||||
}
|
||||
|
||||
@ -2670,6 +2704,27 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
{
|
||||
backup_dao->insertIntoTemporaryNewFilesTable(backuppath+local_curr_os_path, curr_has_hash?(backuppath_hashes+local_curr_os_path):std::wstring(),
|
||||
fileEntry.shahash, fileEntry.filesize);
|
||||
|
||||
copy_curr_file_entry_sparse=false;
|
||||
}
|
||||
}
|
||||
|
||||
if(copy_curr_file_entry_sparse)
|
||||
{
|
||||
std::string curr_path = curr_path + "/" + Server->ConvertToUTF8(cf.name);
|
||||
int crc32 = static_cast<int>(adler32(0, curr_path.c_str(), curr_path.size()));
|
||||
if(crc32 % copy_file_entries_sparse_modulo == incremental_num )
|
||||
{
|
||||
if(trust_client_hashes && !curr_sha2.empty())
|
||||
{
|
||||
backup_dao->insertIntoTemporaryNewFilesTable(backuppath+local_curr_os_path, curr_has_hash?(backuppath_hashes+local_curr_os_path):std::wstring(),
|
||||
curr_sha2, cf.size);
|
||||
}
|
||||
else if(server_hash_existing.get())
|
||||
{
|
||||
addExistingHashesToDb();
|
||||
server_hash_existing->queueFile(backuppath+local_curr_os_path, curr_has_hash?(backuppath_hashes+local_curr_os_path):std::wstring());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2685,6 +2740,8 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
}
|
||||
|
||||
server_download->queueStop(false);
|
||||
server_hash_existing->queueStop(false);
|
||||
|
||||
|
||||
while(!Server->getThreadPool()->waitFor(server_download_ticket, 1000))
|
||||
{
|
||||
@ -2713,6 +2770,8 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
r_offline=true;
|
||||
}
|
||||
|
||||
sendBackupOkay(r_offline==false && c_has_error==false);
|
||||
|
||||
tmp->Seek(0);
|
||||
line = 0;
|
||||
resetEntryState();
|
||||
@ -2738,7 +2797,12 @@ bool BackupServerGet::doIncrBackup(bool with_hashes, bool intra_file_diffs, bool
|
||||
|
||||
Server->destroy(clientlist);
|
||||
|
||||
sendBackupOkay(r_offline==false && c_has_error==false);
|
||||
if(server_hash_existing_ticket!=ILLEGAL_THREADPOOL_TICKET)
|
||||
{
|
||||
Server->getThreadPool()->waitFor(server_hash_existing_ticket);
|
||||
}
|
||||
|
||||
addExistingHashesToDb();
|
||||
|
||||
if(copy_file_entries)
|
||||
{
|
||||
@ -4817,3 +4881,27 @@ void BackupServerGet::calculateEtaFileBackup( int64 &last_eta_update, int64 ctim
|
||||
|
||||
last_eta_received_bytes = received_data_bytes;
|
||||
}
|
||||
|
||||
void BackupServerGet::addExistingHash( const std::wstring& fullpath, const std::wstring& hashpath, const std::string& shahash, int64 filesize )
|
||||
{
|
||||
ServerBackupDao::SFileEntry file_entry;
|
||||
file_entry.exists = true;
|
||||
file_entry.fullpath = fullpath;
|
||||
file_entry.hashpath = hashpath;
|
||||
file_entry.shahash = shahash;
|
||||
file_entry.filesize = filesize;
|
||||
|
||||
IScopedLock lock(hash_existing_mutex);
|
||||
hash_existing.push_back(file_entry);
|
||||
}
|
||||
|
||||
void BackupServerGet::addExistingHashesToDb()
|
||||
{
|
||||
IScopedLock lock(hash_existing_mutex);
|
||||
for(size_t i=0;i<hash_existing.size();++i)
|
||||
{
|
||||
backup_dao->insertIntoTemporaryNewFilesTable(hash_existing[i].fullpath, hash_existing[i].hashpath,
|
||||
hash_existing[i].shahash, hash_existing[i].filesize);
|
||||
}
|
||||
hash_existing.clear();
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ class IPipe;
|
||||
class ServerPingThread;
|
||||
class FileClient;
|
||||
class IPipeThrottler;
|
||||
class ServerHashExisting;
|
||||
|
||||
struct SBackup
|
||||
{
|
||||
@ -43,6 +44,7 @@ class BackupServerGet : public IThread, public FileClientChunked::ReconnectionCa
|
||||
public FileClient::ReconnectionCallback, public INotEnoughSpaceCallback,
|
||||
public FileClient::NoFreeSpaceCallback, public FileClientChunked::NoFreeSpaceCallback
|
||||
{
|
||||
friend ServerHashExisting;
|
||||
public:
|
||||
BackupServerGet(IPipe *pPipe, sockaddr_in pAddr, const std::wstring &pName, bool internet_connection, bool use_snapshots, bool use_reflink);
|
||||
~BackupServerGet(void);
|
||||
@ -181,6 +183,10 @@ private:
|
||||
|
||||
bool authenticatePubKey();
|
||||
|
||||
void addExistingHash(const std::wstring& fullpath, const std::wstring& hashpath, const std::string& shahash, int64 filesize);
|
||||
|
||||
void addExistingHashesToDb();
|
||||
|
||||
SSettings curr_intervals;
|
||||
|
||||
IPipe *pipe;
|
||||
@ -299,4 +305,7 @@ private:
|
||||
std::string session_identity;
|
||||
|
||||
ServerBackupDao* backup_dao;
|
||||
|
||||
IMutex* hash_existing_mutex;
|
||||
std::vector<ServerBackupDao::SFileEntry> hash_existing;
|
||||
};
|
||||
|
||||
88
urbackupserver/server_hash_existing.cpp
Normal file
88
urbackupserver/server_hash_existing.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
#include "server_hash_existing.h"
|
||||
#include "server_prepare_hash.h"
|
||||
#include "../Interface/Server.h"
|
||||
#include "server_log.h"
|
||||
|
||||
ServerHashExisting::ServerHashExisting( int clientid, BackupServerGet* server_get )
|
||||
: has_error(false), clientid(clientid), server_get(server_get)
|
||||
{
|
||||
mutex = Server->createMutex();
|
||||
cond = Server->createCondition();
|
||||
}
|
||||
|
||||
|
||||
ServerHashExisting::~ServerHashExisting()
|
||||
{
|
||||
Server->destroy(mutex);
|
||||
Server->destroy(cond);
|
||||
}
|
||||
|
||||
|
||||
void ServerHashExisting::operator()()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
SHashItem item;
|
||||
{
|
||||
IScopedLock lock(mutex);
|
||||
while(queue.empty())
|
||||
{
|
||||
cond->wait(&lock);
|
||||
}
|
||||
|
||||
item = queue.front();
|
||||
queue.pop_front();
|
||||
}
|
||||
|
||||
if(item.do_stop)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IFile* f = Server->openFile(item.fullpath, MODE_READ);
|
||||
|
||||
if(f==NULL)
|
||||
{
|
||||
ServerLogger::Log(clientid, L"Error opening file \""+item.hashpath+L"\" for hashing", LL_WARNING);
|
||||
has_error = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectScope destroy_f(f);
|
||||
|
||||
int64 filesize = f->Size();
|
||||
std::string sha2 = BackupServerPrepareHash::hash_sha512(f);
|
||||
|
||||
server_get->addExistingHash(item.fullpath, item.hashpath, sha2, filesize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerHashExisting::queueStop( bool front )
|
||||
{
|
||||
SHashItem item;
|
||||
item.do_stop = true;
|
||||
IScopedLock lock(mutex);
|
||||
if(front)
|
||||
{
|
||||
queue.push_front(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
queue.push_back(item);
|
||||
}
|
||||
cond->notify_one();
|
||||
}
|
||||
|
||||
void ServerHashExisting::queueFile( const std::wstring& fullpath, const std::wstring& hashpath )
|
||||
{
|
||||
SHashItem item;
|
||||
item.fullpath = fullpath;
|
||||
item.hashpath = hashpath;
|
||||
|
||||
IScopedLock lock(mutex);
|
||||
queue.push_back(item);
|
||||
cond->notify_one();
|
||||
}
|
||||
|
||||
|
||||
39
urbackupserver/server_hash_existing.h
Normal file
39
urbackupserver/server_hash_existing.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Interface/Mutex.h"
|
||||
#include "../Interface/Condition.h"
|
||||
#include "server_get.h"
|
||||
#include <deque>
|
||||
|
||||
class ServerHashExisting : public IThread
|
||||
{
|
||||
public:
|
||||
ServerHashExisting(int clientid, BackupServerGet* server_get);
|
||||
~ServerHashExisting();
|
||||
|
||||
void queueStop(bool front);
|
||||
|
||||
void queueFile(const std::wstring& fullpath, const std::wstring& hashpath);
|
||||
|
||||
void operator()();
|
||||
|
||||
private:
|
||||
|
||||
struct SHashItem
|
||||
{
|
||||
SHashItem()
|
||||
: do_stop(false)
|
||||
{}
|
||||
|
||||
std::wstring fullpath;
|
||||
std::wstring hashpath;
|
||||
bool do_stop;
|
||||
};
|
||||
|
||||
IMutex* mutex;
|
||||
ICondition* cond;
|
||||
std::deque<SHashItem> queue;
|
||||
bool has_error;
|
||||
int clientid;
|
||||
BackupServerGet* server_get;
|
||||
};
|
||||
@ -120,7 +120,7 @@ void BackupServerPrepareHash::operator()(void)
|
||||
std::string h;
|
||||
if(!diff_file)
|
||||
{
|
||||
h=hash(tf);
|
||||
h=hash_sha512(tf);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -150,24 +150,25 @@ void BackupServerPrepareHash::operator()(void)
|
||||
}
|
||||
}
|
||||
|
||||
std::string BackupServerPrepareHash::hash(IFile *f)
|
||||
std::string BackupServerPrepareHash::hash_sha512(IFile *f)
|
||||
{
|
||||
f->Seek(0);
|
||||
unsigned char buf[4096];
|
||||
unsigned char buf[32768];
|
||||
_u32 rc;
|
||||
|
||||
sha512_init(&ctx);
|
||||
sha512_ctx local_ctx;
|
||||
sha512_init(&local_ctx);
|
||||
do
|
||||
{
|
||||
rc=f->Read((char*)buf, 4096);
|
||||
rc=f->Read((char*)buf, 32768);
|
||||
if(rc>0)
|
||||
sha512_update(&ctx, buf, rc);
|
||||
sha512_update(&local_ctx, buf, rc);
|
||||
}
|
||||
while(rc==4096);
|
||||
while(rc>0);
|
||||
|
||||
std::string ret;
|
||||
ret.resize(64);
|
||||
sha512_final(&ctx, (unsigned char*)&ret[0]);
|
||||
sha512_final(&local_ctx, (unsigned char*)&ret[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -32,9 +32,11 @@ public:
|
||||
void next_chunk_patcher_bytes(const char *buf, size_t bsize, bool changed);
|
||||
|
||||
bool hasError(void);
|
||||
|
||||
static std::string hash_sha512(IFile *f);
|
||||
|
||||
private:
|
||||
std::string hash(IFile *f);
|
||||
|
||||
std::string hash_with_patch(IFile *f, IFile *patch);
|
||||
|
||||
IPipe *pipe;
|
||||
|
||||
@ -311,6 +311,7 @@ void ServerSettings::readSettingsDefault(void)
|
||||
settings->internet_calculate_filehashes_on_client=(settings_default->getValue("internet_calculate_filehashes_on_client", "false")=="true");
|
||||
settings->use_incremental_symlinks=(settings_default->getValue("use_incremental_symlinks", "true")=="true");
|
||||
settings->compress_images=(settings_default->getValue("compress_images", "true")=="true");
|
||||
settings->trust_client_hashes=(settings_default->getValue("trust_client_hashes", "true")=="true");
|
||||
}
|
||||
|
||||
void ServerSettings::readSettingsClient(void)
|
||||
|
||||
@ -88,6 +88,7 @@ struct SSettings
|
||||
bool internet_calculate_filehashes_on_client;
|
||||
bool use_incremental_symlinks;
|
||||
bool compress_images;
|
||||
bool trust_client_hashes;
|
||||
};
|
||||
|
||||
struct STimeSpan
|
||||
|
||||
@ -181,6 +181,7 @@ void getGeneralSettings(JSON::Object& obj, IDatabase *db, ServerSettings &settin
|
||||
SET_SETTING(filescache_size);
|
||||
SET_SETTING(suspend_index_limit);
|
||||
SET_SETTING(use_incremental_symlinks);
|
||||
SET_SETTING(trust_client_hashes);
|
||||
|
||||
#undef SET_SETTING
|
||||
}
|
||||
|
||||
@ -309,6 +309,7 @@
|
||||
<ClCompile Include="server_download.cpp" />
|
||||
<ClCompile Include="server_get.cpp" />
|
||||
<ClCompile Include="server_hash.cpp" />
|
||||
<ClCompile Include="server_hash_existing.cpp" />
|
||||
<ClCompile Include="server_image.cpp" />
|
||||
<ClCompile Include="server_log.cpp" />
|
||||
<ClCompile Include="server_ping.cpp" />
|
||||
@ -331,6 +332,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\common\data.h" />
|
||||
<ClInclude Include="..\md5.h" />
|
||||
<ClInclude Include="..\urbackupcommon\adler32.h" />
|
||||
<ClInclude Include="..\urbackupcommon\bufmgr.h" />
|
||||
<ClInclude Include="..\urbackupcommon\capa_bits.h" />
|
||||
<ClInclude Include="..\urbackupcommon\CompressedPipe.h" />
|
||||
@ -378,6 +380,7 @@
|
||||
<ClInclude Include="server_download.h" />
|
||||
<ClInclude Include="server_get.h" />
|
||||
<ClInclude Include="server_hash.h" />
|
||||
<ClInclude Include="server_hash_existing.h" />
|
||||
<ClInclude Include="server_image.h" />
|
||||
<ClInclude Include="server_log.h" />
|
||||
<ClInclude Include="server_ping.h" />
|
||||
|
||||
@ -261,6 +261,9 @@
|
||||
<ClCompile Include="server_download.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="server_hash_existing.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="action_header.h">
|
||||
@ -461,5 +464,11 @@
|
||||
<ClInclude Include="server_download.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\urbackupcommon\adler32.h">
|
||||
<Filter>fileclient</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="server_hash_existing.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
File diff suppressed because one or more lines are too long
@ -331,6 +331,10 @@
|
||||
<td>{tUse symlinks during incremental file backups}:</td>
|
||||
<td><input type="checkbox" id="use_incremental_symlinks" value="false" {use_incremental_symlinks}/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{tTrust client hashes during incremental file backups}:</td>
|
||||
<td><input type="checkbox" id="trust_client_hashes" value="false" {trust_client_hashes}/></td>
|
||||
</tr>
|
||||
{global_settings_end|s}
|
||||
<tr>
|
||||
<td>{tEnd-to-end verification of all file backups}:</td>
|
||||
|
||||
@ -1448,6 +1448,7 @@ function show_settings2(data)
|
||||
data.settings.silent_update=getCheckboxValue(data.settings.silent_update);
|
||||
data.settings.end_to_end_file_backup_verification=getCheckboxValue(data.settings.end_to_end_file_backup_verification);
|
||||
data.settings.internet_calculate_filehashes_on_client=getCheckboxValue(data.settings.internet_calculate_filehashes_on_client);
|
||||
data.settings.trust_client_hashes=getCheckboxValue(data.settings.trust_client_hashes);
|
||||
|
||||
var transfer_mode_params1=["raw", "hashed"];
|
||||
var transfer_mode_params2=["raw", "hashed", "blockhash"];
|
||||
@ -1856,7 +1857,8 @@ g.general_settings_list=[
|
||||
"filescache_type",
|
||||
"filescache_size",
|
||||
"suspend_index_limit",
|
||||
"use_incremental_symlinks"
|
||||
"use_incremental_symlinks",
|
||||
"trust_client_hashes"
|
||||
];
|
||||
g.mail_settings_list=[
|
||||
"mail_servername",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user