Merge branch 'master' of ssh://urbackup.git.sourceforge.net/gitroot/urbackup/backend

This commit is contained in:
Martin Raiber 2011-11-05 13:52:25 +01:00
commit 0cd9739cc1
14 changed files with 125 additions and 44 deletions

View File

@ -26,7 +26,12 @@
#ifndef BDBPLUGIN
#include "Server.h"
#else
#ifdef LINUX
#include "bdbplugin/config.h"
#include DB_HEADER
#else
#include <db.h>
#endif
#include "Interface/Server.h"
#endif
#include "Query.h"
@ -100,9 +105,21 @@ bool CDatabase::Open(std::string pFile)
}
else
{
sqlite3_busy_timeout(db, 50);
Write("PRAGMA foreign_keys = ON");
Write("PRAGMA synchronous=NORMAL");
#ifdef BDBPLUGIN
db_results res=Read("PRAGMA multiversion");
if(!res.empty() && res[0][L"multiversion"]!=L"1")
{
Write("PRAGMA multiversion=ON");
}
Write("PRAGMA synchronous=ON");
Write("PRAGMA snapshot_isolation=ON");
//Write("PRAGMA bdbsql_error_file='urbackup/bdb_errors.log'");
#else
Write("PRAGMA synchronous=NORMAL");
#endif
Write("PRAGMA foreign_keys = ON");
sqlite3_busy_timeout(db, 50);
return true;
}
}
@ -404,5 +421,14 @@ bool CDatabase::Dump(const std::string &pFile)
return true;
}
std::string CDatabase::getEngineName(void)
{
#ifndef BDBPLUGIN
return "sqlite";
#else
return "bdb";
#endif
}
#endif

View File

@ -44,6 +44,7 @@ public:
virtual bool Import(const std::string &pFile);
virtual bool Dump(const std::string &pFile);
virtual std::string getEngineName(void);
private:
db_nresults results;

View File

@ -25,6 +25,8 @@ public:
virtual bool Import(const std::string &pFile)=0;
virtual bool Dump(const std::string &pFile)=0;
virtual std::string getEngineName(void)=0;
};
#endif

View File

@ -24,7 +24,12 @@
#include "Server.h"
#else
#include "Interface/Server.h"
#include "db.h"
#ifdef LINUX
#include "bdbplugin/config.h"
#include DB_HEADER
#else
#include <db.h>
#endif
#endif
#include "sqlite/sqlite3.h"
#include "Database.h"

View File

@ -1,7 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = liburbackupserver_bdbplugin.la
liburbackupserver_bdbplugin_la_SOURCES = dllmain.cpp BDBFactory.cpp ../Database.cpp ../Query.cpp ../sqlite/shell.c
noinst_HEADERS = IUrlFactory.h pluginmgr.h UrlFactory.h
AM_CXXFLAGS = -DLINUX -DBDBPLUGIN $(BDBSQL_CFLAGS) $(BDB_CFLAGS)
AM_LDFLAGS =$(BDBSQL_LIBS) $(BDB_LIBS)
noinst_HEADERS=../Interface/DatabaseInt.h ../Interface/DatabaseFactory.h ../Interface/Server.h ../Interface/File.h ../sqlite/sqlite3.h ../sqlite/shell.h ../Query.h ../Database.h ../vld.h
AM_CXXFLAGS = -DLINUX -DBDBPLUGIN
AM_LDFLAGS =$(DB_SQL_LIBS)
noinst_HEADERS=../Interface/Database.h ../Interface/Query.h ../Interface/Object.h ../Interface/Mutex.h ../Interface/Condition.h ../Interface/DatabaseInt.h ../Interface/DatabaseFactory.h ../Interface/Server.h ../Interface/File.h ../sqlite/sqlite3.h ../sqlite/shell.h ../Query.h ../Database.h ../vld.h ../Interface/Types.h BDBFactory.h

View File

@ -14,8 +14,10 @@ AC_PROG_LIBTOOL
# Checks for libraries.
AX_BERKELEY_DB(5.1,, AC_MSG_ERROR([Sorry, you need BerkleyDB. Please look for distribution packages(libdb-dev) or get it from http://www.oracle.com/technetwork/database/berkeleydb/]))
AX_BERKELEY_DB_SQL(5.1,, AC_MSG_ERROR([Sorry, you need SQL support for BerkleyDB. Please look for distribution packages(libdb-sql-dev) or get it from http://www.oracle.com/technetwork/database/berkeleydb/]))
#AX_BERKELEY_DB(5.1,, AC_MSG_ERROR([Sorry, you need BerkleyDB. Please look for distribution packages(libdb-dev) or get it from http://www.oracle.com/technetwork/database/berkeleydb/]))
AX_BERKELEY_DB_SQL(5.2,, [
AC_MSG_ERROR([Sorry, you need BerkleyDB with SQL support. Please look for distribution packages(libdb-sql-dev) or get it from http://www.oracle.com/technetwork/database/berkeleydb/])
])
# Checks for header files.
AC_HEADER_STDC

View File

@ -28,7 +28,12 @@
#include "../Interface/Server.h"
#include "../Database.h"
#include "BDBFactory.h"
#ifdef LINUX
#include "config.h"
#include DB_HEADER
#else
#include <db.h>
#endif
#include "../sqlite/sqlite3.h"
IServer *Server=NULL;

View File

@ -56,7 +56,7 @@ AC_DEFUN([AX_BERKELEY_DB],
AC_MSG_CHECKING([for Berkeley DB >= $minversion])
fi
for version in "" 5.0 4.9 4.8 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0 3.6 3.5 3.4 3.3 3.2 3.1 ; do
for version in "" 5.1 5.0 4.9 4.8 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0 3.6 3.5 3.4 3.3 3.2 3.1 ; do
if test -z $version ; then
db_lib="-ldb"

View File

@ -30,7 +30,7 @@
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 6
#serial 7
AC_DEFUN([AX_BERKELEY_DB_SQL],
[
@ -39,13 +39,13 @@ AC_DEFUN([AX_BERKELEY_DB_SQL],
minversion=ifelse([$1], ,,$1)
DB_HEADER=""
DB_LIBS=""
DB_SQL_LIBS=""
if test -z $minversion ; then
minvermajor=0
minverminor=0
minverpatch=0
AC_MSG_CHECKING([for Berkeley DB])
AC_MSG_CHECKING([for Berkeley DB SQL])
else
minvermajor=`echo $minversion | cut -d. -f1`
minverminor=`echo $minversion | cut -d. -f2`
@ -53,18 +53,32 @@ AC_DEFUN([AX_BERKELEY_DB_SQL],
minvermajor=${minvermajor:-0}
minverminor=${minverminor:-0}
minverpatch=${minverpatch:-0}
AC_MSG_CHECKING([for Berkeley DB >= $minversion])
AC_MSG_CHECKING([for Berkeley DB SQL>= $minversion])
fi
for version in "" 5.1 5.0 4.9 4.8 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0 3.6 3.5 3.4 3.3 3.2 3.1 ; do
for version in 5.2 5.1 5.0 4.9 4.8 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0 3.6 3.5 3.4 3.3 3.2 3.1 ""; do
for version2 in "" 5.2 5.1 5.0 4.9 4.8 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0 3.6 3.5 3.4 3.3 3.2 3.1; do
if test -z $version ; then
db_lib="-ldb_sql -ldb"
try_headers="db.h"
if test -z $version2 ; then
db_lib="-ldb_sql -ldb -ldl"
try_headers="db.h"
else
db_lib="-ldb_sql-$version2 -ldb -ldl"
try_headers="db.h"
fi
else
db_lib="-ldb_sql-$version -ldb-$version"
try_headers="db$version/db.h db`echo $version | sed -e 's,\..*,,g'`/db.h"
if test "x$version2" != "x"; then
continue 1;
fi
db_lib="-ldb_sql-$version -ldb-$version -ldl"
try_headers="db$version/db.h db`echo $version | sed -e 's,\..*,,g'`/db.h db.h"
fi
#echo $db_lib
#echo $try_headers
LIBS="$old_LIBS $db_lib"
@ -92,20 +106,21 @@ AC_DEFUN([AX_BERKELEY_DB_SQL],
AC_MSG_RESULT([header $db_hdr, library $db_lib])
DB_HEADER="$db_hdr"
DB_LIBS="$db_lib"
DB_SQL_LIBS="$db_lib"
])
fi
done
done
done
LIBS="$old_LIBS"
if test -z $DB_HEADER ; then
if test -z "$DB_HEADER" ; then
AC_MSG_RESULT([not found])
ifelse([$3], , :, [$3])
else
AC_DEFINE_UNQUOTED(DB_HEADER, ["$DB_HEADER"], ["Berkeley DB Header File"])
AC_SUBST(DB_LIBS)
AC_SUBST(DB_SQL_LIBS)
ifelse([$2], , :, [$2])
fi
])

View File

@ -32,7 +32,13 @@ then
PLUGIN_URL=""
fi
DAEMON_PLUGINS="$PLUGIN_PYCHART $PLUGIN_URL --plugin $DAEMON_LIBS/liburbackupserver_downloadplugin.so --plugin $DAEMON_LIBS/liburbackupserver_fsimageplugin.so --plugin $DAEMON_LIBS/liburbackupserver.so --plugin $DAEMON_LIBS/liburbackupserver_httpserver.so --http_root $DAEMON_DIR/urbackup/www --workingdir $DAEMON_DIR --server true --user urbackup"
PLUGIN_BDB="--plugin $DAEMON_LIBS/liburbackupserver_bdbplugin.so"
if ! test -e $DAEMON_LIBS/liburbackupserver_bdbplugin.so
then
PLUGIN_BDB=""
fi
DAEMON_PLUGINS="$PLUGIN_BDB $PLUGIN_PYCHART $PLUGIN_URL --plugin $DAEMON_LIBS/liburbackupserver_downloadplugin.so --plugin $DAEMON_LIBS/liburbackupserver_fsimageplugin.so --plugin $DAEMON_LIBS/liburbackupserver.so --plugin $DAEMON_LIBS/liburbackupserver_httpserver.so --http_root $DAEMON_DIR/urbackup/www --workingdir $DAEMON_DIR --server true --user urbackup"
S_DAEMON="--daemon"
print_help()

View File

@ -4,15 +4,21 @@ cbuild=""
switch_m_build()
{
cp defaults_$cbuild defaults
cp init.d_$cbuild init.d
if test -e defaults_$cbuild
then
cp defaults_$cbuild defaults
cp init.d_$cbuild init.d
fi
}
switch_build()
{
pwd
cp Makefile.am_$cbuild Makefile.am
cp configure.ac_$cbuild configure.ac
if test -e Makefile.am_$cbuild
then
pwd
cp Makefile.am_$cbuild Makefile.am
cp configure.ac_$cbuild configure.ac
fi
}
switch()
@ -31,6 +37,9 @@ then
elif [[ "x$1" == "xclient" ]]
then
cbuild="client"
elif [[ "x$1" == "xbdbplugin" ]]
then
cbuild="bdbplugin"
else
echo "No valid build enviroment. Available: client, server"
exit 0

View File

@ -318,16 +318,13 @@ DLLEXPORT void LoadActions(IServer* pServer)
#ifndef CLIENT_ONLY
if(both || (!both && !is_backup_client) )
{
std::string bdb_config="mutex_set_max 1000000\r\nset_tx_max 500000\r\nset_lg_regionmax 524288\r\nset_lg_bsize 4194304\r\nset_lg_max 20971520\r\nset_lk_max_locks 10000\r\nset_lk_max_lockers 10000\r\nset_lk_max_objects 10000\r\n";
std::string bdb_config="mutex_set_max 1000000\r\nset_tx_max 500000\r\nset_lg_regionmax 10485760\r\nset_lg_bsize 4194304\r\nset_lg_max 20971520\r\nset_lk_max_locks 100000\r\nset_lk_max_lockers 10000\r\nset_lk_max_objects 100000\r\nset_cachesize 0 104857600 1";
if( !FileExists("urbackup/backup_server.db") && FileExists("urbackup/backup_server.db.template") )
if( !FileExists("urbackup/backup_server.bdb") && !FileExists("urbackup/backup_server.db") && FileExists("urbackup/backup_server.db.template") )
{
copy_file(L"urbackup/backup_server.db.template", L"urbackup/backup_server.db");
}
else if( !FileExists("urbackup/backup_server.db") && !FileExists("urbackup/backup_server.bdb") && FileExists("urbackup/backup_server.bdb.template") )
{
copy_file(L"urbackup/backup_server.bdb.template", L"urbackup/backup_server.bdb");
}
if( !FileExists("urbackup/backup_server.db") )
{
bool init=false;

View File

@ -142,8 +142,12 @@ void ServerCleanupThread::updateStats(bool interruptible)
void ServerCleanupThread::do_cleanup(void)
{
db_results cache_res=db->Read("PRAGMA cache_size");
db->Write("PRAGMA cache_size = 100000");
db_results cache_res;
if(db->getEngineName()=="sqlite")
{
cache_res=db->Read("PRAGMA cache_size");
db->Write("PRAGMA cache_size = 100000");
}
removeerr.clear();
cleanup_images();

View File

@ -12,10 +12,10 @@
#include "server_status.h"
#include "server_get.h"
const bool update_stats_use_transactions_del=true;
bool update_stats_use_transactions_del=true;
const bool update_stats_use_transactions_done=false;
const bool update_stats_autocommit=true;
const bool update_stats_bulk_done_files=true;
bool update_stats_bulk_done_files=true;
ServerUpdateStats::ServerUpdateStats(bool image_repair_mode, bool interruptible)
: image_repair_mode(image_repair_mode), interruptible(interruptible)
@ -26,10 +26,10 @@ void ServerUpdateStats::createQueries(void)
{
q_get_images=db->Prepare("SELECT id,clientid,path FROM backup_images WHERE complete=1 AND running<datetime('now','-300 seconds')", false);
q_update_images_size=db->Prepare("UPDATE clients SET bytes_used_images=? WHERE id=?", false);
q_get_ncount_files=db->Prepare("SELECT a.rowid AS id, shahash, filesize, rsize, clientid, backupid FROM files WHERE did_count=0 LIMIT 10000", false);
q_get_ncount_files=db->Prepare("SELECT rowid AS id, shahash, filesize, rsize, clientid, backupid FROM files WHERE did_count=0 LIMIT 10000", false);
q_has_client=db->Prepare("SELECT count(*) AS c FROM files WHERE shahash=? AND filesize=? AND clientid=?", false);
q_mark_done=db->Prepare("UPDATE files SET did_count=1 WHERE rowid=?", false);
q_get_clients=db->Prepare("SELECT clientid, SUM(rsize) AS s_rsize FROM files WHERE shahash=? AND filesize=? AND did_count=1 GROUP BY clientid", false);
q_get_clients=db->Prepare("SELECT clientid, SUM(rsize) AS s_rsize FROM files WHERE shahash=? AND filesize=? AND +did_count=1 GROUP BY clientid", false);
q_get_sizes=db->Prepare("SELECT id,bytes_used_files FROM clients", false);
q_size_update=db->Prepare("UPDATE clients SET bytes_used_files=? WHERE id=?", false);
q_get_delfiles=db->Prepare("SELECT files_del.rowid AS id, shahash, filesize, rsize, clientid, backupid, incremental, is_del FROM files_del LIMIT 10000", false);
@ -42,7 +42,7 @@ void ServerUpdateStats::createQueries(void)
q_save_client_hist=db->Prepare("INSERT INTO clients_hist (id, name, lastbackup, lastseen, lastbackup_image, bytes_used_files, bytes_used_images, hist_id) SELECT id, name, lastbackup, lastseen, lastbackup_image, bytes_used_files, bytes_used_images, ? AS hist_id FROM clients", false);
q_set_file_backup_null=db->Prepare("UPDATE backups SET size_bytes=0 WHERE size_bytes=-1 AND complete=1", false);
q_transfer_bytes=db->Prepare("UPDATE files SET rsize=? WHERE rowid=?", false);
q_get_transfer=db->Prepare("SELECT rowid AS id FROM files WHERE shahash=? AND filesize=? AND did_count=1 AND rsize=0 LIMIT 1", false);
q_get_transfer=db->Prepare("SELECT rowid AS id FROM files WHERE shahash=? AND filesize=? AND +did_count=1 AND +rsize=0 LIMIT 1", false);
q_create_hist=db->Prepare("INSERT INTO clients_hist_id (created) VALUES (CURRENT_TIMESTAMP)", false);
q_get_all_clients=db->Prepare("SELECT id FROM clients", false);
q_mark_done_bulk_files=db->Prepare("UPDATE files SET did_count=1 WHERE rowid IN ( SELECT rowid FROM files WHERE did_count=0 LIMIT 10000 )");
@ -77,8 +77,12 @@ void ServerUpdateStats::destroyQueries(void)
void ServerUpdateStats::operator()(void)
{
db=Server->getDatabase(Server->getThreadID(), URBACKUPDB_SERVER);
db_results cache_res=db->Read("PRAGMA cache_size");
db->Write("PRAGMA cache_size = 100000");
db_results cache_res;
if(db->getEngineName()=="sqlite")
{
cache_res=db->Read("PRAGMA cache_size");
db->Write("PRAGMA cache_size = 100000");
}
createQueries();
@ -184,6 +188,12 @@ void ServerUpdateStats::update_files(void)
unsigned int last_commit_time=Server->getTimeMS();
std::map<int, SDelInfo> del_sizes;
if(db->getEngineName()=="bdb")
{
update_stats_bulk_done_files=false;
update_stats_use_transactions_del=false;
}
if(!update_stats_autocommit)
{