1 #include "../../test.h"
2 #include "../../../src/bu.h"
3 #include "../../../src/fsops.h"
4 #include "../../../src/server/sdirs.h"
5 #include "../../../src/server/timestamp.h"
6 #include "../build_file.h"
7 #include "build_storage_dirs.h"
8
create_file(const char * backup,const char * file,int compressed_logs)9 static void create_file(const char *backup,
10 const char *file, int compressed_logs)
11 {
12 char path[256]="";
13 if(compressed_logs)
14 snprintf(path, sizeof(path), "%s/%s.gz", backup, file);
15 else
16 snprintf(path, sizeof(path), "%s/%s", backup, file);
17 build_file(path, NULL);
18 }
19
do_build_storage_dirs(struct sdirs * sdirs,struct sd * s,int len,int compressed_logs)20 static void do_build_storage_dirs(struct sdirs *sdirs, struct sd *s, int len,
21 int compressed_logs)
22 {
23 int i=0;
24 time_t t=0;
25 char backup[128]="";
26 char timestamp_path[256]="";
27 fail_unless(!build_path_w(sdirs->client));
28 fail_unless(!mkdir(sdirs->client, 0777));
29 for(i=0; i<len; i++)
30 {
31 snprintf(backup, sizeof(backup),
32 "%s/%s", sdirs->client, s[i].timestamp);
33 snprintf(timestamp_path, sizeof(timestamp_path),
34 "%s/timestamp", backup);
35 fail_unless(!mkdir(backup, 0777));
36 fail_unless(!timestamp_write(timestamp_path, s[i].timestamp));
37 if(s[i].flags & BU_CURRENT)
38 fail_unless(!symlink(s[i].timestamp, sdirs->current));
39 if(s[i].flags & BU_WORKING)
40 fail_unless(!symlink(s[i].timestamp, sdirs->working));
41 if(s[i].flags & BU_FINISHING)
42 fail_unless(!symlink(s[i].timestamp, sdirs->finishing));
43
44 if(s[i].flags & BU_MANIFEST)
45 create_file(backup, "manifest", compressed_logs);
46 if(s[i].flags & BU_LOG_BACKUP)
47 create_file(backup, "log", compressed_logs);
48 if(s[i].flags & BU_LOG_RESTORE)
49 create_file(backup, "restorelog", compressed_logs);
50 if(s[i].flags & BU_LOG_VERIFY)
51 create_file(backup, "verifylog", compressed_logs);
52 if(sdirs->protocol==PROTO_1)
53 {
54 if(s[i].flags & BU_HARDLINKED)
55 create_file(backup, "hardlinked", 0);
56 }
57 // This one is never compressed.
58 if(sdirs->global_sparse)
59 build_file(sdirs->global_sparse, NULL);
60
61 t+=60*60*24; // Add one day.
62 }
63 }
64
build_storage_dirs(struct sdirs * sdirs,struct sd * s,int len)65 void build_storage_dirs(struct sdirs *sdirs, struct sd *s, int len)
66 {
67 do_build_storage_dirs(sdirs, s, len, 0 /* compressed_logs */);
68 }
69
build_storage_dirs_compressed_logs(struct sdirs * sdirs,struct sd * s,int len)70 void build_storage_dirs_compressed_logs(struct sdirs *sdirs,
71 struct sd *s, int len)
72 {
73 do_build_storage_dirs(sdirs, s, len, 1 /* compressed_logs */);
74 }
75