📄 full_backup.c
字号:
* because the subprocesses are started only few times */ sprintf(tmpbuf, "%d", (int) builtin_compr_level); if(compresscmd[0]){ if(!idxcompresscmd) EM__(idxcompresscmd = strchain(piperprogram, " ", compresscmd, " | ", zprogram, " -", tmpbuf, NULL)); EM__(compresscmd = strchain(". ", tmpbuf, " ", compresscmd, NULL)); } else{ if(!idxcompresscmd) EM__(idxcompresscmd = strchain(zprogram, " -", tmpbuf, NULL)); EM__(compresscmd = strapp(". ", tmpbuf)); } if(uncompresscmd[0]){ if(!idxuncompresscmd) EM__(idxuncompresscmd = strchain(piperprogram, " ", zprogram, " -d | ", uncompresscmd, NULL)); } else{ if(!idxuncompresscmd) EM__(idxuncompresscmd = strapp(zprogram, " -d")); uncompresscmd = "."; /* a dummy */ } } if(!compresscmd[0] || !uncompresscmd[0]){ compressbu = NO; } if(!idxcompresscmd || !idxuncompresscmd) idxuncompresscmd = idxcompresscmd = ""; if(!idxcompresscmd[0] || !idxuncompresscmd[0]) idxuncompresscmd = idxcompresscmd = ""; if(!idxcompresscmd[0] || !idxuncompresscmd[0]){ compresslogfiles = NO; } if(!logfile) logfile = strdup(""); massage_string(logfile); if(!logfile[0]) EM__(logfile = strapp(logdir, FN_DIRSEPSTR "backup.log")); if(startinfoprog){ if(empty_string(startinfoprog)){ ZFREE(startinfoprog); } } if(initprog){ if(empty_string(initprog) || (mode != MODE_INCR_BACKUP && mode != MODE_FULL_BACKUP)){ ZFREE(initprog); } } if(exitprog){ if(empty_string(exitprog) || (mode != MODE_INCR_BACKUP && mode != MODE_FULL_BACKUP)){ ZFREE(exitprog); } } if(exclude_filename){ if(empty_string(exclude_filename)){ ZFREE(exclude_filename); } else massage_string(exclude_filename); } massage_string(rootdir); massage_string(indexfilepart); if(identity){ if(empty_string(identity)){ ZFREE(identity); } else massage_string(identity); } if(!identity) identity = systemname; EEM__(repl_dirs(&piperprogram) || repl_dirs(&logfile) || repl_dirs(&cryptfile) || repl_dirs(&indexfilepart) || repl_dirs(&initprog) || repl_dirs(&exitprog) || repl_dirs(&startinfoprog) || repl_dirs(&lockfile)); EM__(reportfile = tmp_name(FN_TMPDIR FN_DIRSEPSTR "afbrep")); /* check encryption keyfile */ if(cryptfile && (i = check_cryptfile(cryptfile)) ){ if(i > 0) logmsg(T_("Warning concerning encryption key file `%s': %s.\n"), cryptfile, check_cryptfile_msg(i)); else errmsg(T_("Error concerning encryption key file `%s': %s.\n"), cryptfile, check_cryptfile_msg(i)); if(i < 0) exit(11); logmsg(T_("Warning: Ignoring file `%s', using compiled-in key.\n"), cryptfile); ZFREE(cryptfile); } /* determine the lock file pathname if not explicitly specified */ if(!lockfile){ for(cpptr = lockdirs; *cpptr; cpptr++){ i = stat(*cpptr, &statb); EM__(cptr = strchain(*cpptr, FN_DIRSEPSTR, DEFAULT_CLIENTLOCKFILE, NULL)); if(!i){ if(! access(*cpptr, W_OK) || ! stat(cptr, &statb2)){ lockfile = cptr; break; } else{ i = setgid(statb.st_gid); if(! access(*cpptr, W_OK)){ lockfile = cptr; break; } } } } } massage_string(lockfile); if(mode == MODE_COPY_TAPE) copy_tape(argc, argv); /* will exec */ lck = set_lock(); if(lck != BU_GOT_LOCK){ /* * If we can't get the lock, use the kill(2) call to verify if the * pid listed in the lock file (or any process in the same process * group -- ie: pipe chain) is still running. If we can't read the * pid, assume that the process exists. */ j = 0; pid = -1; i = read_pint_file(lockfile, &pid); if(!i){ j = ! kill(pid, 0); } else{ j = 1; } if(j){ errmsg(T_("Error: An application seems to hold a lock on this functionality.\n")); if(pid >= 0){ sprintf(tmpbuf, "%d", pid); errmsg(T_(" The process ID is %s.\n"), tmpbuf); } else{ errmsg(T_(" Cannot determine process-ID.\n")); } fprintf(stderr, T_("Please check if this process is an obstacle to continue.\n")); fprintf(stderr, T_("Do you want to continue anyway ? (y/N) ")); if(!isatty(0)){ errmsg(T_("\nCannot read confirmation from TTY. Exiting.\n")); exit(39); } if(wait_for_input(0, 120) < 1){ fprintf(stderr, T_("\nTimeout on input, exiting.\n")); exit(40); } tmpbuf[0] = '\0'; fgets(tmpbuf, 10, stdin); cptr = tmpbuf; while(isspace(*cptr) && *cptr) cptr++; if(*cptr != 'y' && *cptr != 'Y') exit(99); } if(unlink(lockfile)){ errmsg(T_("Warning: Cannot remove lockfile `%s'.\n"), lockfile); } lck = set_lock(); } if(lck != BU_GOT_LOCK){ fprintf(stderr, T_("Warning: Cannot set lock. Continue anyway ? (y/N) ")); if(!isatty(0)){ fprintf(stderr, T_("\nCannot read confirmation from TTY. Exiting.\n")); exit(38); } if(wait_for_input(0, 120) < 1){ fprintf(stderr, T_("Timeout on input, exiting.\n")); exit(41); } tmpbuf[0] = '\0'; fgets(tmpbuf, 10, stdin); cptr = tmpbuf; while(isspace(*cptr) && *cptr) cptr++; if(*cptr != 'y' && *cptr != 'Y') exit(99); } if(mode == MODE_INCR_BACKUP || mode == MODE_RESTORE || mode == MODE_VERIFYBU || mode == MODE_UPDATE_INDEXES){ if( (i = read_pint_file(numfile, &num)) ) cptr = numfile; last_idx_num = num; if(mode == MODE_RESTORE || mode == MODE_VERIFYBU || mode == MODE_UPDATE_INDEXES){ if(! restore_em && ! restore_emlist && ! restore_EM){ if(i){ errmsg(T_("Error: Cannot read file `%s'.\n"), numfile); do_exit(9); } } } else{ /* MODE_INCR_BACKUP */ if(access(oldmarkfile, R_OK)){ i = 1; cptr = oldmarkfile; } if(i){ errmsg(T_("Warning: Cannot read file `%s', switching to full backup.\n"), cptr); mode = MODE_FULL_BACKUP; } } } part = 1; if(numparts > 1){ read_pint_file(partfile, &part); if(mode == MODE_FULL_BACKUP){ part++; if(part > numparts) part = 1; } } /* read the number of the backup, if file present */ if(mode == MODE_FULL_BACKUP){ if(read_pint_file(numfile, &num)) /* set num to 0 if file absent */ part = 1; last_idx_num = num; if(part == 1 && ! keep_counter) num++; } if(daystostoreindexes >= 0.0){ /* set numindexestostore from it */ time_t read_time, cmp_time; cmp_time = time(NULL) - (time_t)(daystostoreindexes * 86400.0); for(i = num - 1; ; i--){ read_time = (time_t) 0; sprintf(tmpbuf, "%d:", (int) i); cptr = kfile_get(index_ages_file, tmpbuf, KFILE_LOCKED); if(cptr){ read_time = strint2time(cptr); free(cptr); } else{ /* timestamp not in index ages file -> read index to find the */ pid = -1; /* latest timestamp in there, save and use it */ fd = open_idxfile_read(i, &pid, NULL, YES); if(fd >= 0){ cptr = NULL; n = 0; fp = fdopen(fd, "r"); while(!feof(fp)){ if(fget_realloc_str(fp, &cptr, &n)) continue; if(INDEX_COMMENT( eval_index_line(cptr, NULL, NULL, NULL, NULL, NULL, NULL)) && !strncmp(first_nospace(cptr), "##", 2)) read_header_line(cptr, NULL, &read_time, NULL, NULL, NULL); } ZFREE(cptr); fclose(fp); if(pid >= 0) waitpid(pid, &pst, 0); if(read_time != (time_t) 0){ sprintf(tmpbuf, "%d:", (int) i); time_t_to_intstr(read_time, tmpbuf + 20); kfile_insert(index_ages_file, tmpbuf, tmpbuf + 20, KFILE_SORTN | KFILE_LOCKED); } } } if(read_time < cmp_time){ i = num - 1 - i; if(i > numindexestostore) numindexestostore = i; break; } } } /* GDR: left off here */ if(mode == MODE_RESTORE) restore(argc, argv); /* will exit */ save_entry_file = strapp(vardir, FN_DIRSEPSTR SAVE_ENTRIES_FILE); level_times_file = strapp(vardir, FN_DIRSEPSTR LEVEL_TIMESTAMPS_FILE); needed_tapes_file = strapp(vardir, FN_DIRSEPSTR NEEDED_TAPES_FILE); start_pos_file = strapp(vardir, FN_DIRSEPSTR START_POSITIONS_FILE); if(!save_entry_file || !level_times_file || !needed_tapes_file || !start_pos_file) ENM__; if(mode == MODE_UPDATE_INDEXES) goto poll_servers; /* skip a lot of stuff */ /* change to the root directory */ if(chdir(rootdir)){ errmsg(T_("Error: Cannot change to directory `%s'.\n"), rootdir); do_exit(7); } if(mode == MODE_VERIFYBU) verifybu(argc, argv); if(mode == MODE_INCR_BACKUP && backup_level == MAXINT) backup_level = 0; if(numparts > 1){ ParamFileEntry *dirsparams; UChar **partdirstobackupraw = NULL, *cptr; /* collect all stuff, that must go into backup */ dirsparams = NEWP(ParamFileEntry, numparts); partdirstobackupraw = NEWP(UChar *, numparts); if(!dirsparams || !partdirstobackupraw) ENM__; for(i = 0; i < numparts; i++){ sprintf(tmpbuf, "%d:", (int) (i + 1)); dirsparams[i].pattern = repl_substring_safe(entries[0].pattern, ":", tmpbuf); dirsparams[i].entry_ptr = partdirstobackupraw + i; dirsparams[i].num_entries = NULL; dirsparams[i].type = TypeUCharPTR; EM__(partdirstobackupraw[i] = strdup("")); } i = read_param_file(paramfile, dirsparams, numparts, NULL, NULL); if(i){ errmsg(T_("Error: Cannot read parameter file.\n")); do_exit(6); } ZFREE(alldirstobackupraw); EM__(alldirstobackupraw = strdup("")); for(i = 0; i < numparts; i++){ replace_if_pipe(&(partdirstobackupraw[i]), mode, backup_level, part); EM__(cptr = strchain(alldirstobackupraw, " ", partdirstobackupraw[i], NULL)); free(alldirstobackupraw); alldirstobackupraw = cptr; free(partdirstobackupraw[i]); free(dirsparams[i].pattern); } free(partdirstobackupraw); free(dirsparams); } else{ replace_if_pipe(&dirstobackupraw, mode, backup_level, 0); EM__(alldirstobackupraw = strdup(dirstobackupraw)); } ZFREE(dirstobackupraw); EM__(dirstobackupraw = strdup(alldirstobackupraw)); /* if backup is split in pieces, get again the directories to backup */ if(numparts > 1 && mode == MODE_FULL_BACKUP){ ParamFileEntry dirsparam; UChar *partdirstobackupraw = NULL; sprintf(tmpbuf, "%d:", part); dirsparam.pattern = repl_substring_safe(entries[0].pattern, ":", tmpbuf); dirsparam.entry_ptr = &partdirstobackupraw; dirsparam.num_entries = NULL; dirsparam.type = TypeUCharPTR; i = read_param_file(paramfile, &dirsparam, 1, NULL, NULL); if(i){ errmsg(T_("Error: Cannot read parameter file.\n")); do_exit(6); } free(dirsparam.pattern); if(partdirstobackupraw){ ZFREE(dirstobackupraw); dirstobackupraw = partdirstobackupraw; replace_if_pipe(&dirstobackupraw, mode, backup_level, part); } } if(!access(save_entry_file, R_OK) && !no_default_backup){ EM__(save_entries = read_asc_file(save_entry_file, NULL)); } if(!access(level_times_file, R_OK)){ EM__(level_timespecs = kfile_getall(level_times_file, &num_level_timespecs, KFILE_LOCKED)); } /* convert the strings (containing lists) to string arrays */ if(str2wordsq(&dirstobackup, dirstobackupraw ? dirstobackupraw : ES) < 0 || str2wordsq(&dirstoskip, dirstoskipraw ? dirstoskipraw : ES) < 0 || str2wordsq(&filestoskip, filestoskipraw ? filestoskipraw : ES) < 0 || str2wordsq(&alldirstobackup, alldirstobackupraw ? alldirstobackupraw : ES) < 0) ENM__; if(fstypesraw){ while( (cptr = strchr(fstypesraw, ',')) ) *cptr = ' '; for(i = 0; (cptr = strword(fstypesraw, i)); i++){ if(strchr("+-/", c = cptr[0])) memmove(cptr, cptr + 1, strlen(cptr) * sizeof(UChar)); if(c == '-') cppptr = &fstypestoskip; else if(c == '/') cppptr = &fstypestoprune; else cppptr = &fstypestosave; j = 0; if(*cppptr) for(j = 0, cpptr = *cppptr; *cpptr; j++, cpptr++); EM__(*cppptr = ZRENEWP(*cppptr, UChar *, j + 2)); (*cppptr)[j] = cptr; (*cppptr)[j + 1] = NULL; } } dirlists[0] = dirstobackup; dirlists[1] = alldirstobackup; for(cpptr = filestoskip; *cpptr; cpptr++) cleanpath(*cpptr); for(cppptr = dirlists; *cppptr; cppptr++){ for(cpptr = *cppptr; *cpptr; cpptr++){ if(!strncmp(*cpptr, FILECONTPREFIX, i = strlen(FILECONTPREFIX))){ cleanpath(*cpptr + i); } else if(!strncmp(*cpptr, FILECONTZPREFIX, i = strlen(FILECONTZPREFIX))){ cleanpath(*cpptr + i); } else if(!strncmp(*cpptr, LOCALDEVPREFIX, i = strlen(LOCALDEVPREFIX))){ cleanpath(*cpptr + i); } else{ cleanpath(*cpptr); } }#if 0 /* don't do this: it's dangerous, when paths are symlinked or cross-filesystem *//* FIXME: work this through for dirstobackup -> *cppptr */ /* resolve glob patterns */ EM__(alldirs = NEWP(UChar *, 1)); *alldirs = NULL; num_alldirs = 0; for(cpptr = dirstobackup; *cpptr; cpptr++){ cpptr2 = fng
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -