Added glob file exclusion

This commit is contained in:
Martin Raiber 2011-05-06 18:08:14 +02:00
parent f23526b185
commit 84becc3b35
8 changed files with 185 additions and 15 deletions

View File

@ -159,6 +159,9 @@ bool ClientConnector::Run(void)
do_quit=true;
return true;
}
IScopedLock lock(backup_mutex);
backup_running=0;
backup_done=true;
return false;
}
else if(msg=="done")
@ -172,6 +175,9 @@ bool ClientConnector::Run(void)
tcpstack.Send(pipe, msg);
lasttime=Server->getTimeMS();
state=0;
IScopedLock lock(backup_mutex);
backup_running=0;
backup_done=true;
}
}break;
case 2:
@ -645,6 +651,11 @@ void ClientConnector::ReceivePackets(void)
Server->Log("Invalid command", LL_ERROR);
}
}
else if(cmd.find("1GET BACKUP DIRS")==0 && pw_ok==true)
{
getBackupDirs(1);
lasttime=Server->getTimeMS();
}
else if(cmd.find("GET BACKUP DIRS")==0 && pw_ok==true)
{
getBackupDirs();
@ -1212,15 +1223,19 @@ bool ClientConnector::checkPassword(const std::wstring &pw)
return stored_pw==Server->ConvertToUTF8(pw);
}
void ClientConnector::getBackupDirs(void)
void ClientConnector::getBackupDirs(int version)
{
IDatabase *db=Server->getDatabase(Server->getThreadID(), URBACKUPDB_CLIENT);
IQuery *q=db->Prepare("SELECT id,path FROM backupdirs");
IQuery *q=db->Prepare("SELECT id,name,path FROM backupdirs");
db_results res=q->Read();
std::string msg;
for(size_t i=0;i<res.size();++i)
{
msg+=Server->ConvertToUTF8(res[i][L"id"])+"\n";
if(version!=0)
{
msg+=Server->ConvertToUTF8(res[i][L"name"])+"|";
}
msg+=Server->ConvertToUTF8(res[i][L"path"]);
if(i+1<res.size())
msg+="\n";
@ -1245,9 +1260,12 @@ bool ClientConnector::saveBackupDirs(str_map &args)
dir=args[L"dir_"+convert(i)];
if(!dir.empty())
{
std::string name=replaceChars( ExtractFileName(wnarrow(dir) ) );
if(name=="urbackup")
name="urbackup_1";
std::wstring name;
str_map::iterator name_arg=args.find(L"dir_"+convert(i)+L"_name");
if(name_arg!=args.end() && !name_arg->second.empty())
name=name_arg->second;
else
name=widen(replaceChars( ExtractFileName(wnarrow(dir) ) ));
if(dir[dir.size()-1]=='\\' || dir[dir.size()-1]=='/' )
dir.erase(dir.size()-1,1);
@ -1258,10 +1276,10 @@ bool ClientConnector::saveBackupDirs(str_map &args)
for(int k=0;k<100;++k)
{
q2->Reset();
q2->Bind(name+"_"+nconvert(k));
q2->Bind(name+L"_"+convert(k));
if(q2->Read().empty()==true)
{
name+="_"+nconvert(k);
name+=L"_"+convert(k);
break;
}
}

View File

@ -28,7 +28,7 @@ public:
private:
bool checkPassword(const std::wstring &cmd);
void getBackupDirs(void);
void getBackupDirs(int version=0);
bool saveBackupDirs(str_map &args);
void updateLastBackup(void);
void getBackupStatus(void);

View File

@ -208,7 +208,7 @@ std::vector<SBackupDir> ClientDAO::getBackupDirs(void)
{
SBackupDir dir;
dir.id=watoi(res[i][L"id"]);
dir.tname=wnarrow(res[i][L"name"]);
dir.tname=res[i][L"name"];
dir.path=res[i][L"path"];
ret.push_back(dir);

View File

@ -25,7 +25,7 @@ typedef struct _GUID {
struct SBackupDir
{
int id;
std::string tname;
std::wstring tname;
std::wstring path;
};

145
urbackup/glob/glob.cpp Normal file
View File

@ -0,0 +1,145 @@
/*
* robust glob pattern matcher
* ozan s. yigit/dec 1994
* public domain
*
* glob patterns:
* * matches zero or more wchar_tacters
* ? matches any single wchar_tacter
* [set] matches any wchar_tacter in the set
* [^set] matches any wchar_tacter NOT in the set
* where a set is a group of wchar_tacters or ranges. a range
* is written as two wchar_tacters seperated with a hyphen: a-z denotes
* all wchar_tacters between a to z inclusive.
* [-set] set matches a literal hypen and any wchar_tacter in the set
* []set] matches a literal close bracket and any wchar_tacter in the set
*
* char matches itself except where char is '*' or '?' or '['
* \char matches char, including any pattern wchar_tacter
*
* examples:
* a*c ac abc abbc ...
* a?c acc abc aXc ...
* a[a-z]c aac abc acc ...
* a[-a-z]c a-c aac abc ...
*
* $Log: glob.c,v $
* Revision 1.3 1995/09/14 23:24:23 oz
* removed boring test/main code.
*
* Revision 1.2 94/12/11 10:38:15 oz
* cset code fixed. it is now robust and interprets all
* variations of cset [i think] correctly, including [z-a] etc.
*
* Revision 1.1 94/12/08 12:45:23 oz
* Initial revision
*/
#ifndef NEGATE
#define NEGATE '^' /* std cset negation char */
#endif
bool amatch(const wchar_t *str, const wchar_t *p)
{
int negate;
int match;
int c;
while (*p) {
if (!*str && *p != '*')
return false;
switch (c = *p++) {
case '*':
while (*p == '*')
p++;
if (!*p)
return true;
if (*p != '?' && *p != '[' && *p != '\\')
while (*str && *p != *str)
str++;
while (*str) {
if (amatch(str, p))
return true;
str++;
}
return false;
case '?':
if (*str)
break;
return false;
/*
* set specification is inclusive, that is [a-z] is a, z and
* everything in between. this means [z-a] may be interpreted
* as a set that contains z, a and nothing in between.
*/
case '[':
if (*p != NEGATE)
negate = false;
else {
negate = true;
p++;
}
match = false;
while (!match && (c = *p++)) {
if (!*p)
return false;
if (*p == '-') { /* c-c */
if (!*++p)
return false;
if (*p != ']') {
if (*str == c || *str == *p ||
(*str > c && *str < *p))
match = true;
}
else { /* c-] */
if (*str >= c)
match = true;
break;
}
}
else { /* cc or c] */
if (c == *str)
match = true;
if (*p != ']') {
if (*p == *str)
match = true;
}
else
break;
}
}
if (negate == match)
return false;
/*
* if there is a match, skip past the cset and continue on
*/
while (*p && *p != ']')
p++;
if (!*p++) /* oops! */
return false;
break;
case '\\':
if (*p)
c = *p++;
default:
if (c != *str)
return false;
break;
}
str++;
}
return !*str;
}

View File

@ -809,7 +809,7 @@ bool BackupServerGet::request_filelist_construct(bool full)
delete [] pck;
if(ret!="DONE")
{
ServerLogger::Log(clientid, "Constructing of filelist of \""+clientname+"\" failed - TIMEOUT(2)", LL_ERROR);
ServerLogger::Log(clientid, "Constructing of filelist of \""+clientname+"\" failed: "+ret, LL_ERROR);
break;
}
else
@ -930,7 +930,7 @@ bool BackupServerGet::doFullBackup(void)
std::wstring t=curr_path;
t.erase(0,1);
ServerLogger::Log(clientid, L"Starting shadowcopy \""+t+L"\".", LL_INFO);
start_shadowcopy(wnarrow(t));
start_shadowcopy(Server->ConvertToUTF8(t));
}
}
else
@ -941,7 +941,7 @@ bool BackupServerGet::doFullBackup(void)
std::wstring t=curr_path;
t.erase(0,1);
ServerLogger::Log(clientid, L"Stoping shadowcopy \""+t+L"\".", LL_INFO);
stop_shadowcopy(wnarrow(t));
stop_shadowcopy(Server->ConvertToUTF8(t));
}
curr_path=ExtractFilePath(curr_path);
}
@ -1279,7 +1279,7 @@ bool BackupServerGet::doIncrBackup(void)
t.erase(0,1);
if(r_offline==false)
{
start_shadowcopy(wnarrow(t));
start_shadowcopy(Server->ConvertToUTF8(t));
}
}
}
@ -1296,7 +1296,7 @@ bool BackupServerGet::doIncrBackup(void)
t.erase(0,1);
if(r_offline==false)
{
stop_shadowcopy(wnarrow(t));
stop_shadowcopy(Server->ConvertToUTF8(t));
}
}
curr_path=ExtractFilePath(curr_path);

View File

@ -596,6 +596,7 @@
<ClCompile Include="client_restore.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="escape.cpp" />
<ClCompile Include="glob\glob.cpp" />
<ClCompile Include="os_functions_win.cpp" />
<ClCompile Include="server.cpp" />
<ClCompile Include="serverinterface\backups.cpp" />

View File

@ -28,6 +28,9 @@
<Filter Include="treediff">
<UniqueIdentifier>{1e3a9954-74c9-4bbf-b99c-4f78b6bd555f}</UniqueIdentifier>
</Filter>
<Filter Include="glob">
<UniqueIdentifier>{a6950ae3-9a5d-43aa-a26a-f3429f1cfb83}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="bufmgr.cpp">
@ -195,6 +198,9 @@
<ClCompile Include="treediff\TreeDiff.cpp">
<Filter>treediff</Filter>
</ClCompile>
<ClCompile Include="glob\glob.cpp">
<Filter>glob</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="action_header.h">