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