Line data Source code
1 : #include "../burp.h"
2 : #include "../action.h"
3 : #include "../asfd.h"
4 : #include "../async.h"
5 : #include "../cntr.h"
6 : #include "../conf.h"
7 : #include "../handy.h"
8 : #include "../log.h"
9 : #include "backup_phase1.h"
10 : #include "cvss.h"
11 : #include "protocol1/backup_phase2.h"
12 : #include "protocol2/backup_phase2.h"
13 :
14 : #ifdef HAVE_WIN32
15 : static void set_priority(int priority, const char *str)
16 : {
17 : if(SetThreadPriority(GetCurrentThread(), priority))
18 : logp("Set %s\n", str);
19 : else
20 : logp("Failed to set %s\n", str);
21 : }
22 :
23 : static void set_low_priority(void)
24 : {
25 : // Run timed backups with lower priority. I found that this has to be
26 : // done after the snapshot, or the snapshot never finishes. At least, I
27 : // waited 30 minutes with nothing happening.
28 : #if defined(B_VSS_XP) || defined(B_VSS_W2K3)
29 : set_priority(THREAD_PRIORITY_LOWEST,
30 : "thread_priority_lowest");
31 : #else
32 : set_priority(THREAD_MODE_BACKGROUND_BEGIN,
33 : "thread_mode_background_begin");
34 : #endif
35 : }
36 :
37 : static void unset_low_priority(void)
38 : {
39 : set_priority(THREAD_MODE_BACKGROUND_END,
40 : "thread_mode_background_end");
41 : }
42 : #endif
43 :
44 : // Return 0 for OK, -1 for error.
45 0 : int do_backup_client(struct asfd *asfd, struct conf **confs, enum action action,
46 : int resume)
47 : {
48 0 : int ret=-1;
49 0 : int breaking=get_int(confs[OPT_BREAKPOINT]);
50 :
51 0 : if(action==ACTION_ESTIMATE)
52 0 : logp("do estimate client\n");
53 : else
54 : {
55 0 : logp("do backup client\n");
56 0 : if(get_protocol(confs)==PROTO_1)
57 : logp("Using librsync hash %s\n",
58 0 : rshash_to_str(get_e_rshash(confs[OPT_RSHASH])));
59 : }
60 :
61 : #ifdef HAVE_WIN32
62 : win32_enable_backup_privileges();
63 : #ifdef WIN32_VSS
64 : if(win32_start_vss(confs)) return ret;
65 : #endif
66 : if(action==ACTION_BACKUP_TIMED) set_low_priority();
67 : #endif
68 :
69 : // Scan the file system and send the results to the server.
70 : // Skip phase1 if the server wanted to resume.
71 0 : if(!resume)
72 : {
73 0 : if(breaking==1)
74 : {
75 0 : breakpoint(breaking, __func__);
76 0 : goto end;
77 : }
78 0 : if(backup_phase1_client(asfd, confs, action==ACTION_ESTIMATE))
79 0 : goto end;
80 : }
81 :
82 0 : switch(action)
83 : {
84 : case ACTION_DIFF:
85 : case ACTION_DIFF_LONG:
86 0 : ret=1;
87 0 : goto end;
88 : case ACTION_ESTIMATE:
89 0 : cntr_print(get_cntr(confs), ACTION_ESTIMATE);
90 0 : break;
91 : default:
92 : // Now, the server will be telling us what data we need
93 : // to send.
94 0 : if(breaking==2)
95 : {
96 0 : breakpoint(breaking, __func__);
97 0 : goto end;
98 : }
99 :
100 0 : if(get_protocol(confs)==PROTO_1)
101 : ret=backup_phase2_client_protocol1(asfd,
102 0 : confs, resume);
103 : else
104 : ret=backup_phase2_client_protocol2(asfd,
105 0 : confs, resume);
106 0 : if(ret) goto end;
107 0 : break;
108 : }
109 :
110 0 : ret=0;
111 : end:
112 : #if defined(HAVE_WIN32)
113 : if(action==ACTION_BACKUP_TIMED) unset_low_priority();
114 : #if defined(WIN32_VSS)
115 : win32_stop_vss();
116 : #endif
117 : #endif
118 0 : return ret;
119 : }
|