📄 sendbackup-gnutar.c
字号:
error(_("error [opening %s: %s]"), amandates_file, strerror(errno)); /*NOTREACHED*/ } amdates = amandates_lookup(disk); prev_dumptime = EPOCH; for(l = 0; l < level; l++) { if(amdates->dates[l] > prev_dumptime) prev_dumptime = amdates->dates[l]; } finish_amandates(); free_amandates(); gmtm = gmtime(&prev_dumptime); g_snprintf(dumptimestr, SIZEOF(dumptimestr), "%04d-%02d-%02d %2d:%02d:%02d GMT", gmtm->tm_year + 1900, gmtm->tm_mon+1, gmtm->tm_mday, gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec); dbprintf(_("gnutar: doing level %d dump from date: %s\n"), level, dumptimestr); dirname = amname_to_dirname(amdevice); cur_dumptime = time(0); cur_level = level; cur_disk = stralloc(disk);#ifdef GNUTAR# define PROGRAM_GNUTAR GNUTAR#else# define PROGRAM_GNUTAR "tar"#endif indexcmd = vstralloc( PROGRAM_GNUTAR, " -tf", " -", " 2>/dev/null", " | sed", " -e", " \'s/^\\.//\'", NULL);#ifdef SAMBA_CLIENT /* { */ /* Use sambatar if the disk to back up is a PC disk */ if (amdevice[0] == '/' && amdevice[1]=='/') { char *sharename = NULL, *user_and_password = NULL, *domain = NULL; char *share = NULL, *subdir = NULL; char *pwtext = NULL; char *taropt; int passwdf = -1; size_t lpass; size_t pwtext_len; char *pw_fd_env; parsesharename(amdevice, &share, &subdir); if (!share) { amfree(share); amfree(subdir); set_pname(error_pn); amfree(error_pn); error(_("cannot parse disk entry %s for share/subdir"), qdisk); /*NOTREACHED*/ } if ((subdir) && (SAMBA_VERSION < 2)) { amfree(share); amfree(subdir); set_pname(error_pn); amfree(error_pn); error(_("subdirectory specified for share %s but samba not v2 or better"), qdisk); /*NOTREACHED*/ } if ((user_and_password = findpass(share, &domain)) == NULL) { if(domain) { memset(domain, '\0', strlen(domain)); amfree(domain); } set_pname(error_pn); amfree(error_pn); error(_("error [invalid samba host or password not found?]")); /*NOTREACHED*/ } lpass = strlen(user_and_password); if ((pwtext = strchr(user_and_password, '%')) == NULL) { memset(user_and_password, '\0', lpass); amfree(user_and_password); if(domain) { memset(domain, '\0', strlen(domain)); amfree(domain); } set_pname(error_pn); amfree(error_pn); error(_("password field not \'user%%pass\' for %s"), qdisk); /*NOTREACHED*/ } *pwtext++ = '\0'; pwtext_len = strlen(pwtext); if ((sharename = makesharename(share, 0)) == 0) { memset(user_and_password, '\0', lpass); amfree(user_and_password); if(domain) { memset(domain, '\0', strlen(domain)); amfree(domain); } set_pname(error_pn); amfree(error_pn); error(_("error [can't make share name of %s]"), share); /*NOTREACHED*/ } taropt = stralloc("-T"); if(options->exclude_file && options->exclude_file->nb_element == 1) { strappend(taropt, "X"); }#if SAMBA_VERSION >= 2 strappend(taropt, "q");#endif strappend(taropt, "c"); if (level != 0) { strappend(taropt, "g"); } else if (!options->no_record) { strappend(taropt, "a"); } if (subdir) { dbprintf(_("gnutar: backup of %s/%s\n"), sharename, subdir); } else { dbprintf(_("gnutar: backup of %s\n"), sharename); } program->backup_name = program->restore_name = SAMBA_CLIENT; cmd = stralloc(program->backup_name); info_tapeheader(); start_index(options->createindex, dumpout, mesgf, indexf, indexcmd); if (pwtext_len > 0) { pw_fd_env = "PASSWD_FD"; } else { pw_fd_env = "dummy_PASSWD_FD"; } dumppid = pipespawn(cmd, STDIN_PIPE|PASSWD_PIPE, &dumpin, &dumpout, &mesgf, pw_fd_env, &passwdf, "smbclient", sharename, *user_and_password ? "-U" : skip_argument, *user_and_password ? user_and_password : skip_argument, "-E", domain ? "-W" : skip_argument, domain ? domain : skip_argument,#if SAMBA_VERSION >= 2 subdir ? "-D" : skip_argument, subdir ? subdir : skip_argument,#endif "-d0", taropt, "-", options->exclude_file && options->exclude_file->nb_element == 1 ? options->exclude_file->first->name : skip_argument, NULL); if(domain) { memset(domain, '\0', strlen(domain)); amfree(domain); } if(pwtext_len > 0 && fullwrite(passwdf, pwtext, pwtext_len) < 0) { int save_errno = errno; aclose(passwdf); memset(user_and_password, '\0', lpass); amfree(user_and_password); set_pname(error_pn); amfree(error_pn); error(_("error [password write failed: %s]"), strerror(save_errno)); /*NOTREACHED*/ } memset(user_and_password, '\0', lpass); amfree(user_and_password); aclose(passwdf); amfree(sharename); amfree(share); amfree(subdir); amfree(taropt); tarpid = dumppid; } else#endif /*end of samba */ { int nb_exclude = 0; int nb_include = 0; char **my_argv; int i = 0; char *file_exclude = NULL; char *file_include = NULL; if(options->exclude_file) nb_exclude+=options->exclude_file->nb_element; if(options->exclude_list) nb_exclude+=options->exclude_list->nb_element; if(options->include_file) nb_include+=options->include_file->nb_element; if(options->include_list) nb_include+=options->include_list->nb_element; if(nb_exclude > 0) file_exclude = build_exclude(disk, amdevice, options, 0); if(nb_include > 0) file_include = build_include(disk, amdevice, options, 0); my_argv = alloc(SIZEOF(char *) * (22 + (nb_exclude*2)+(nb_include*2))); cmd = vstralloc(amlibexecdir, "/", "runtar", versionsuffix(), NULL); info_tapeheader(); start_index(options->createindex, dumpout, mesgf, indexf, indexcmd); my_argv[i++] = "runtar"; if (g_options->config) my_argv[i++] = g_options->config; else my_argv[i++] = "NOCONFIG";#ifdef GNUTAR my_argv[i++] = GNUTAR;#else my_argv[i++] = "tar";#endif my_argv[i++] = "--create"; my_argv[i++] = "--file"; my_argv[i++] = "-"; my_argv[i++] = "--directory"; canonicalize_pathname(dirname, tmppath); my_argv[i++] = tmppath; my_argv[i++] = "--one-file-system"; if (gnutar_list_dir && incrname) { my_argv[i++] = "--listed-incremental"; my_argv[i++] = incrname; } else { my_argv[i++] = "--incremental"; my_argv[i++] = "--newer"; my_argv[i++] = dumptimestr; }#ifdef ENABLE_GNUTAR_ATIME_PRESERVE /* --atime-preserve causes gnutar to call * utime() after reading files in order to * adjust their atime. However, utime() * updates the file's ctime, so incremental * dumps will think the file has changed. */ my_argv[i++] = "--atime-preserve";#endif my_argv[i++] = "--sparse"; my_argv[i++] = "--ignore-failed-read"; my_argv[i++] = "--totals"; if(file_exclude) { my_argv[i++] = "--exclude-from"; my_argv[i++] = file_exclude; } if(file_include) { my_argv[i++] = "--files-from"; my_argv[i++] = file_include; } else { my_argv[i++] = "."; } my_argv[i++] = NULL; dumppid = pipespawnv(cmd, STDIN_PIPE, &dumpin, &dumpout, &mesgf, my_argv); tarpid = dumppid; amfree(file_exclude); amfree(file_include); amfree(my_argv); } dbprintf(_("gnutar: %s: pid %ld\n"), cmd, (long)dumppid); amfree(qdisk); amfree(dirname); amfree(cmd); amfree(indexcmd); amfree(error_pn); /* close the write ends of the pipes */ aclose(dumpin); aclose(dumpout); aclose(compout); aclose(dataf); aclose(mesgf); if (options->createindex) aclose(indexf);}static voidend_backup( int goterror){ if(!options->no_record && !goterror) { if (incrname != NULL && strlen(incrname) > 4) { char *nodotnew; nodotnew = stralloc(incrname); nodotnew[strlen(nodotnew)-4] = '\0'; if (rename(incrname, nodotnew)) { g_fprintf(stderr, _("%s: warning [renaming %s to %s: %s]\n"), get_pname(), incrname, nodotnew, strerror(errno)); } amfree(nodotnew); amfree(incrname); } if(!start_amandates(amandates_file, 1)) { g_fprintf(stderr, _("%s: warning [opening %s: %s]"), get_pname(), amandates_file, strerror(errno)); } else { amandates_updateone(cur_disk, cur_level, cur_dumptime); finish_amandates(); free_amandates(); } }}backup_program_t gnutar_program = { "GNUTAR",#ifdef GNUTAR GNUTAR, GNUTAR,#else "gtar", "gtar",#endif re_table, start_backup, end_backup};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -