Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Many changes to BackupPCd client (BackupPC side of things) |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
aaba01233085c72613b5a3b7e9a47fb1 |
User & Date: | rkeene 2008-04-05 20:57:05 |
Context
2008-11-06
| ||
20:53 | Updated file_sync tool to use the same blocksize size in the sender as the receiver. check-in: 73a43a3c3b user: rkeene tags: trunk | |
2008-04-05
| ||
20:57 | Many changes to BackupPCd client (BackupPC side of things) check-in: aaba012330 user: rkeene tags: trunk | |
2006-03-14
| ||
10:23 | Added protocol definitions for a "HOSTNAME" command and reply. Updated backuppcd to attempt to be smarter about finding itself. check-in: f9114a0f4a user: rkeene tags: trunk | |
Changes
Changes to backuppcd-client.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include "compat.h" #include <libbackuppcd.h> #define BPC_CLIENT_LIST 0 #define BPC_CLIENT_GET_INCR 1 #define BPC_CLIENT_GET_FULL 2 static char *bpc_hashstr(const unsigned char hash[16]) { static char ret[33]; int i; for (i = 0; i < 16; i++) { sprintf(ret + (i * 2), "%02x", hash[i]); } return(ret); } | > > > > > > > | > > | > > > > | > > > | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include "compat.h" #include "backuppcd-common.h" #include <libbackuppcd.h> #include <libconfig.h> /* XXX: include safety */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #define BPC_CLIENT_LIST 0 #define BPC_CLIENT_GET_INCR 1 #define BPC_CLIENT_GET_FULL 2 static char *bpc_hashstr(const unsigned char hash[16]) { static char ret[33]; int i; for (i = 0; i < 16; i++) { sprintf(ret + (i * 2), "%02x", hash[i]); } return(ret); } static char *bpc_poolpath(const char *pooldir, const unsigned char hash[16], int collidx) { static char ret[8192]; char *hashstr; int snprintf_ret; hashstr = bpc_hashstr(hash); if (collidx < 0) { snprintf_ret = snprintf(ret, sizeof(ret), "%s/%s", pooldir, hashstr); } else { snprintf_ret = snprintf(ret, sizeof(ret), "%s/%s_%i", pooldir, hashstr, collidx); } if (snprintf_ret >= sizeof(ret)) { return(NULL); } return(ret); } static char *bpc_mungepath(const char *path) { static char ret[8192]; char *path_cp, *path_cp_s; char *retptr, *tmpbuf; |
︙ | ︙ | |||
61 62 63 64 65 66 67 68 69 70 71 | } *retptr = '\0'; free(path_cp_s); return(ret); } int main(int argc, char **argv) { BPC_CONN *conn1, *conn2 = NULL; struct bpc_fileinfo *finfo = NULL; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | > > > | | > > > < > > | < > > > > > | > > | | > > > | > > > > | < > > | | > > | < | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | } *retptr = '\0'; free(path_cp_s); return(ret); } static int bpc_fileuptodate(const char *pooldir, const char *datadir, struct bpc_fileinfo *finfo) { struct stat stbuf; char localfile[8192]; char *poolfile; ino_t localinode, poolinode; int retval = 0; int snprintf_ret, stat_ret; int i; snprintf_ret = snprintf(localfile, sizeof(localfile), "%s/%s", datadir, bpc_mungepath(finfo->name)); if (snprintf_ret >= sizeof(localfile)) { CHECKPOINT; return(0); } /* * If the local file does not exist, do no further checking. */ stat_ret = stat(localfile, &stbuf); if (stat_ret < 0) { CHECKPOINT; return(0); } localinode = stbuf.st_ino; /* * Iterate through all the available pool files to see if one matches * our local file's inode */ for (i = -1; i < 0xffff; i++) { poolfile = bpc_poolpath(pooldir, finfo->hash_bpc, i); stat_ret = stat(poolfile, &stbuf); if (stat_ret < 0) { CHECKPOINT; break; } poolinode = stbuf.st_ino; if (poolinode == localinode) { CHECKPOINT; retval = 1; break; } } CHECKPOINT; return(retval); } static int bpc_updatenewfilelist(FILE *fp, struct bpc_fileinfo *finfo) { if (fp == NULL || finfo == NULL) { return(-1); } /* XXX: Check to make sure finfo->hash_bpc isn't non-sense */ /* * Print out the required data */ fprintf(fp, "%s %llu %s\n", bpc_hashstr(finfo->hash_bpc), finfo->size, bpc_mungepath(finfo->name)); return(0); } static int bpc_updatexferlog(FILE *fp, struct bpc_fileinfo *finfo, ...) { return(0); } static int bpc_updateattrib(const char *pathname, struct bpc_fileinfo *finfo) { static FILE *fp; static char *lastdir = NULL; size_t pathname_len; char pathnameparent[16384], attribfile[16384], *tmp; int snprintf_ret; int needopen; if (pathname == NULL || finfo == NULL) { return(-1); } pathname_len = strlen(pathname) + 1; if (pathname_len >= sizeof(pathnameparent)) { return(-1); } memcpy(pathnameparent, pathname, pathname_len); tmp = strrchr(pathnameparent, '/'); if (!tmp) { return(-1); } *tmp = '\0'; needopen = 1; if (lastdir) { if (strcmp(lastdir, pathnameparent) == 0) { needopen = 0; } } if (needopen) { snprintf_ret = snprintf(attribfile, sizeof(attribfile), "%s/attrib", lastdir); if (snprintf_ret >= sizeof(attribfile)) { return(-1); } if (lastdir) { free(lastdir); } if (fp) { fclose(fp); } lastdir = strdup(pathnameparent); fp = fopen(attribfile, "w"); } /* XXX: Write to attrib file */ return(0); } static int print_help(const char *msg) { if (msg) { fprintf(stderr, "%s\n", msg); } return(0); } int main(int argc, char **argv) { BPC_CONN *conn1, *conn2 = NULL; struct bpc_fileinfo *finfo = NULL; char *host = NULL, *command, *username = "anonymous", *password = NULL; char localfile[16384]; int snprintf_ret; int port = BPC_TCP_PORT; int mode; int ret = 0; char *run_curr = "new", *run_last = NULL; int lc_ret; int uptodate; char type_string[][7] = {"dir", "file", "syml", "sock", "fifo", "blk", "chr", "hrdl"}; char *pooldir = NULL; char *datadir = NULL; char lastdir[16384], currdir[16384]; char newfilelistname[16384], xferfilename[16384]; FILE *newfilelistfp = NULL; lc_register_var("Host", LC_VAR_STRING, &host, 'H'); lc_register_var("Port", LC_VAR_INT, &port, 'P'); lc_register_var("User", LC_VAR_STRING, &username, 'U'); lc_register_var("Pass", LC_VAR_STRING, &password, 'p'); lc_register_var("Pool", LC_VAR_STRING, &pooldir, 'S'); lc_register_var("DataDir", LC_VAR_STRING, &datadir, 'D'); lc_register_var("LastRun", LC_VAR_STRING, &run_last, 'r'); lc_register_var("CurrRun", LC_VAR_STRING, &run_curr, 'R'); lc_ret = lc_process(argc, argv, "backuppcdc", LC_CONF_SPACE, NULL); lc_cleanup(); if (lc_ret != 0) { fprintf(stderr, "Error processing configuration: %s\n", lc_geterrstr()); return(EXIT_FAILURE); } if (host == NULL) { print_help("Host is required"); return(EXIT_FAILURE); } if (password == NULL) { print_help("Password is required"); return(EXIT_FAILURE); } if (port < 0) { print_help("Port is required"); return(EXIT_FAILURE); } if (argc == lc_optind) { print_help("Command is required"); return(EXIT_FAILURE); } command = argv[lc_optind]; if (strcasecmp(command, "list") == 0) { mode = BPC_CLIENT_LIST; } else if (strcasecmp(command, "get") == 0) { mode = BPC_CLIENT_GET_INCR; } else if (strcasecmp(command, "getfull") == 0) { mode = BPC_CLIENT_GET_FULL; } else { fprintf(stderr, "Invalid operation: %s\n", command); return(EXIT_FAILURE); } switch (mode) { case BPC_CLIENT_GET_INCR: if (run_last == NULL) { print_help("Last Run is required"); return(EXIT_FAILURE); } if (pooldir == NULL) { print_help("PoolDir is required"); return(EXIT_FAILURE); } case BPC_CLIENT_GET_FULL: if (datadir == NULL) { print_help("DataDir is required"); return(EXIT_FAILURE); } if (run_last != NULL) { snprintf(lastdir, sizeof(lastdir), "%s/%s", datadir, run_last); } snprintf(currdir, sizeof(currdir), "%s/%s", datadir, run_curr); snprintf(newfilelistname, sizeof(newfilelistname), "%s/NewFileList", datadir); snprintf(xferfilename, sizeof(xferfilename), "%s/XferLOG", datadir); newfilelistfp = fopen(newfilelistname, "w"); } conn1 = bpc_connect(host, port, username, password); if (!conn1) { fprintf(stderr, "Failed (connect)\n"); return(EXIT_FAILURE); } /* * Begin operation */ switch (mode) { case BPC_CLIENT_LIST: ret = bpc_list_open(conn1, "/", 1, BPC_HASH_NONE, NULL, NULL); |
︙ | ︙ | |||
170 171 172 173 174 175 176 | } printf("\n"); if (mode == BPC_CLIENT_LIST) { continue; } | | > > > > > | > | > > > > > > | 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | } printf("\n"); if (mode == BPC_CLIENT_LIST) { continue; } snprintf_ret = snprintf(localfile, sizeof(localfile), "%s/%s", currdir, bpc_mungepath(finfo->name)); if (snprintf_ret < 0 || snprintf_ret >= sizeof(localfile)) { PRINTERR("Filename too long. Something is almost definitely wrong, aborting."); ret = 0; CHECKPOINT; break; } switch (mode) { case BPC_CLIENT_GET_INCR: if (finfo->type == BPC_FILE_DIR) { backuppc_mkdir(localfile); } /* * Update attrib file */ bpc_updateattrib(currdir, finfo); if (finfo->type != BPC_FILE_REG) { break; } /* * Check to see if the file is up-to-date */ uptodate = bpc_fileuptodate(pooldir, lastdir, finfo); if (uptodate) { /* If so, don't copy it again. */ break; } /* * Update NewFileList */ bpc_updatenewfilelist(newfilelistfp, finfo); CHECKPOINT; SPOTVAR_S(finfo->name); ret = bpc_get_open(conn2, finfo->name, 0, BPC_HASH_NONE, NULL, NULL); CHECKPOINT; if (!ret) { CHECKPOINT; break; |
︙ | ︙ |