📄 full_backup.c
字号:
/****************** Start of $RCSfile: full_backup.c,v $ ****************** $Source: /home/alb/afbackup/afbackup-3.3.8.1/RCS/full_backup.c,v $* $Id: full_backup.c,v 1.9 2005/01/15 08:54:32 alb Exp alb $* $Date: 2005/01/15 08:54:32 $* $Author: alb $********* description *********************************************************************************************************************//* * Preliminary: * * i do not care about little pieces of memory, that are * allocated once during program execution and not used any * longer from some certain time on. E.g. if a string is * allocated via strdup: * * char * str = strdup("some stuff"); * * i'm not always freeing it the next time this pointer will * be assigned a new value. If wasting 100 Bytes is a problem, * buy a new machine. Call me what you like. */#include <conf.h>#include <version.h> static char * fileversion = "$RCSfile: full_backup.c,v $ $Source: /home/alb/afbackup/afbackup-3.3.8.1/RCS/full_backup.c,v $ $Id: full_backup.c,v 1.9 2005/01/15 08:54:32 alb Exp alb $ " PACKAGE " " VERSION_STRING;#include <stdio.h>#include <string.h>#include <signal.h>#include <fcntl.h>#include <sys/utsname.h>#include <pwd.h>#ifdef HAVE_SYS_WAIT_H#include <sys/wait.h>#endif#include <unistd.h>#include <stdarg.h>#include <mvals.h>#include <fileutil.h>#include <sysutils.h>#include <netutils.h>#include <genutils.h>#include <x_regex.h>#include <packer.h>#include "backup.h"#include "server.h"#define CLEANUP { goto cleanup; }#define GETOUT { goto getout; }#define CLEANUPR(rval) { r = rval; goto cleanup; }#define GETOUTR(rval) { r = rval; goto getout; }#define ES ((UChar *) "")#define WS "[ \t]*"/* The following hurts me, but there is no way out */static char *BACKUP_RE = TN_("[ \t]*" "[Bb][Aa][Cc][Kk][Uu][Pp]");static char *CARTRIDGE_RE = TN_("[ \t]*" "[Cc][Aa][Rr][Tt][Rr][Ii][Dd][Gg][Ee]");static char *FILE_RE = TN_("[ \t]*" "[Ff][Ii][Ll][Ee]");static char *SERVER_RE = TN_("[ \t]*" "[Ss][Ee][Rr][Vv][Ee][Rr]");static char *PORT_RE = TN_("[ \t]*" "[Pp][Oo][Rr][Tt]");static char *NCARTS_RE = TN_("[Nn][Uu][Mm]\\([Bb][Ee][Rr]\\)?" "[ \t]*" "[Oo][Ff]" \ "[ \t]*" "[Cc][Aa][Rr][Tt]\\([Rr][Ii][Dd][Gg][Ee]\\)?[Ss]");#define EMREC_PREFIX "@@@===--->>>"#define EMREC_POSTFIX "<<<---===@@@"#define EMREC_PREFIX_RE "^" WS EMREC_PREFIX#define EMREC_TAPE_PREFIX "!#@$%&^*(_)+[;" ",{-<=]'.}>`/|: "#define BU_NO_LOCK 0#define BU_LOCKED 1#define BU_GOT_LOCK 2#define BU_CANT_LOCK 99#define MODE_FULL_BACKUP 0#define MODE_INCR_BACKUP 1#define MODE_RESTORE 2#define MODE_VERIFYBU 3#define MODE_COPY_TAPE 4#define MODE_UPDATE_INDEXES 5#define CLEAR_LIST 0#define ACCESS_POSITION 1#define INSERT_POSITION 2#define INSERT_POS_NEWCART 3#define FIRST_NUM_ARG 1#define IGNORE_NUM_ARG_TRAILERS 2/* eval_index_line returns: -1 empty -2 comment <= -10: not recognized >=0 fileposition*/#define INDEX_FILEENTRY(n) ((n) >= 0) /* might be empty i.e. no filename at this location i.e. '\0' */#define INDEX_EMPTY(n) ((n) == -1)#define INDEX_COMMENT(n) ((n) == -2)#define INDEX_NOCONTENTS(n) (INDEX_EMPTY(n) || INDEX_COMMENT(n))#define INDEX_RECOGNIZED(n) ((n) > -10)#define INDEX_UNRECOGNIZED(n) ((n) <= -10)typedef struct _scandir_args_ { int fd; Flag entry_found; Flag write_failed; Flag have_location; int ctofd; int cfromfd; int cerrfd; UChar *read_data; Int32 read_data_nall; Int32 num_read_data; UChar *read_err; Int32 read_err_nall; Int32 num_read_err;} ScanDirArgs;typedef struct utsname UName;typedef struct bu_tapeentry { UChar *server; Int32 port; Int32 cart; Int32 file; time_t budate; Int32 mode; Int32 bunum; Int32 inscart; Int32 insfile;} BuTapeEntry;typedef struct _datalocator_ { Int32 cart; Int32 file; Int32 efile; UChar *server; Int32 port;} DataLocator;typedef struct streamerstat { UChar devstatus; Int32 serverstatus; Int32 numactive; Int32 numpending; UChar serverid[256]; Uns32Range *needed_tapes; Uns32Range *deleted_tapes;} StreamerStat;typedef struct serveridtab { UChar *servername; Int32 serverport; UChar *serverid;} ServerIdTab;typedef struct _dataarea_ { ServerIdTab serveridtab; Uns32Range *carts;} DataArea;UChar *cmd_res[] = { "[Ff][Uu][Ll][Ll]", "[Ii][Nn][Cc][Rr]", "\\([Bb][Aa][Cc][Kk][Oo][Uu][Tt]\\|[Rr][Ee][Ss][Tt][Oo][Rr][Ee]\\)", "[Vv][Ee][Rr][Ii][Ff][Yy]", "[Cc][Oo][Pp][Yy]", "[Uu][Pp][Dd][Aa][Tt].*[Ii][Nn]?[Dd][Ee]?[Xx]" };UChar *option2prefix[] = { FILECONTOPTION " " FILECONTPREFIX, FILECONTZOPTION " " FILECONTZPREFIX, LOCALDEVOPTION " " LOCALDEVPREFIX, NULL };UChar *default_paramfiles[] = { DEFAULT_CLIENT_CONFIGFILES , NULL };UChar *bindir = NULL;UChar *vardir = NULL;UChar *libdir = NULL;UChar *confdir = NULL;UChar *logdir = NULL;ReplSpec dir_pat_repl[] = { { "%B", NULL, &bindir }, { "%L", NULL, &libdir }, { "%V", NULL, &vardir }, { "%C", NULL, &confdir }, { "%I", NULL, &logdir }, };UChar *paramfile = NULL;UChar *partfile = NULL;UChar *numfile = NULL;UChar *oldmarkfile = NULL;UChar *orgoldmarkfile = NULL;UChar *newmarkfile = NULL;UChar *indexfile = NULL;UChar *cryptfile = NULL;UChar *save_entry_file = NULL;UChar **save_entries = NULL;UChar *level_times_file = NULL;KeyValuePair *level_timespecs = NULL;Int32 num_level_timespecs = 0;UChar *needed_tapes_file = NULL;UChar **needed_tapes_lines = NULL;Int32 num_needed_tapes_lines = 0;UChar *server_ids_file = NULL;UChar *index_ages_file = NULL;UChar *start_pos_file = NULL;Flag use_ctime = NO;UChar *clientprogram = NULL;UChar *piperprogram = NULL;UChar *zprogram = NULL;UChar *backuphostlist = NULL;UChar **backuphosts = NULL;Int32 num_backuphosts = 0;UChar *backupportlist = NULL;UChar **backupportstrs;Int32 *backupports = NULL;Int32 num_backupports = 0;Int32 *msgports = NULL;Int32 serveridx = 0;UChar server_id[512]; /* only needed for backup */UChar *rootdir = NULL;UChar *dirstobackupraw = NULL;UChar **dirstobackup = NULL;UChar *alldirstobackupraw = NULL;UChar **alldirstobackup = NULL;UChar *filestoskipraw = NULL;UChar **filestoskip = NULL;UChar *dirstoskipraw = NULL;UChar **dirstoskip = NULL;UChar **fstypestosave = NULL;UChar **fstypestoskip = NULL;UChar **fstypestoprune = NULL;UChar *fstypesraw = NULL;UChar *indexfilepart = NULL;Int32 numindexestostore = -1;Real32 daystostoreindexes = -1.0;Int32 numindexestoscan = -1;Real32 daystoscanindexes = -1.0;UChar *compresscmd = NULL;UChar *uncompresscmd = NULL;UChar *idxcompresscmd = NULL;UChar *idxuncompresscmd = NULL;Int32 builtin_compr_level = 0;Flag compressbu = YES;UChar *logfile = NULL;Int32 numparts = 1;UChar *startinfoprog = NULL;UChar *initprog = NULL;UChar *exitprog = NULL;UChar *reportfile = NULL;UChar *filelist = NULL;Flag compresslogfiles = YES;UChar **filecontentstobu = NULL;UChar **dont_compress = NULL;Int32 num_dont_compress = 0;UChar *dont_compress_str = NULL;UChar *exclude_filename = NULL;Int32 backup_level = MAXINT;time_t start_time;time_t cmp_time;Flag no_default_backup = NO;UChar *minrestoreinfo = NULL;Int32 mode = -1;int part = 1;int num = 1;Flag keep_counter = NO;Flag keep_timestamp = NO;Flag newcart = NO;Flag remove_lower_levels = NO;/* Comment from Devin Reade: * the variable 'interrupted' should be volatile; it can be changed by * a signal handler, and therefore optimizations can lose information * Comment on Comment (AF): * this is a theoretical consideration without real impact. When the * signal handler terminates, interrupted will be modified and that's * sufficient */int interrupted = 0;int clientpid = -1;Flag logf_lost = NO;int msgprocpid = -1;int msgprocfd = -1;UChar *cartsetlist = NULL;Int32 *cartsets = NULL;Int32 num_cartsets = 0;Flag detach = NO;Flag chksum = NO;Flag chk_perms = NO;Flag verbose = NO;Flag quiet = NO;UChar *msgs_config_str = NULL;Flag output_server_msgs = NO;sigset_t idxproc_blk_sigs;/* for restore */Flag do_counting = NO;Flag do_listing = NO;Flag do_listcarts = NO;Flag do_raw_listing = NO;Flag ign_case = NO;UChar *restoreroot = NULL;Flag restore_all = NO;#define vfy_list_all restore_allInt32 restore_em = 0;Flag restore_emlist = NO;Int32 restore_EM = 0;Flag preserve_existing = NO;UChar *beforestr = NULL;UChar *afterstr = NULL;time_t time_older = 0;time_t time_newer = 0;UChar *restoretapestr = NULL;Uns32Range *restoretapes = NULL;time_t current_bu_time = 0;time_t prev_bu_time = 0;Flag have_timerange = NO;Flag have_mtime_idx = NO;Int32 num_restore_paths = 0;UChar **restore_paths = NULL;Int32 num_prev_backup = 0;UChar *num_prev_backup_str = NULL;Int32 num_prev_run = 0;UChar **indexfiles = NULL, **zindexfiles = NULL;Int32 numidx, num_indexfiles;UChar *formatstr = NULL;ReplSpec *fmt_repls = NULL;Int32 num_fmt_repls = 0;#define FMT_REPL_CHARS "nbhpcfoOmMtT"uid_t curuid;gid_t curgid;gid_t *curgids;int curngids;uid_t ieuid;gid_t iegid;UChar *systemname = NULL;UChar *identity = NULL;Flag identity_from_arg = NO;Flag vardir_from_arg = NO;UName systeminfo;/* for copy_tape */UChar *tmpdir = NULL;RE_cmp_buffer backup_re, cartridge_re, file_re, ncarts_re, server_re, port_re;ScanDirArgs scandir_args;UChar *lockfile = NULL;int lockfd;UChar locked = BU_NO_LOCK;struct flock lockb;#if MAXPATHLEN < 1000#define TMPBUFSIZ 4096#else#define TMPBUFSIZ (MAXPATHLEN * 4 + 100)#endifUChar tmpbuf[TMPBUFSIZ];UChar *lockdirs[] = { "/var/locks", "/var/lock", "/var/spool/locks", "/var/spool/lock", "/var/tmp", "/tmp", NULL,};UChar *tmpdirs[10] = { "pwd - dummy", FN_DIRSEPSTR "tmp" FN_DIRSEPSTR "%N", FN_DIRSEPSTR "var" FN_DIRSEPSTR "tmp" FN_DIRSEPSTR "%N", FN_DIRSEPSTR "temp" FN_DIRSEPSTR "%N", NULL};UChar *tmpfiles[10];ParamFileEntry entries[] = { { &dirstobackupraw, NULL, (UChar *) "^[ \t]*[Dd]ire?c?t?o?r?i?e?s[ \t_-]*[Tt]o[ \t_-]*[Bb]ackup:?[ \t]*", TypeUCharPTR }, { &backuphostlist, NULL, (UChar *) "^[ \t]*[Bb]ackup[ \t_-]*[Hh]osts?:?[ \t]*", TypeUCharPTR }, { &backupportlist, NULL, (UChar *) "^[ \t]*[Bb]ackup[ \t_-]*[Pp]orts?:?[ \t]*", TypeUCharPTR }, { &rootdir, NULL, (UChar *) "^[ \t]*[Rr]oot[ \t_-]*[Dd]ire?c?t?o?r?y?:?[ \t]*", TypeUCharPTR }, { &filestoskipraw, NULL, (UChar *) "^[ \t]*[Ff]iles[ \t_-]*[Tt]o[ \t_-]*[Ss]kip:?[ \t]*", TypeUCharPTR }, { &dirstoskipraw, NULL, (UChar *) "^[ \t]*[Dd]ire?c?t?o?r?i?e?s[ \t_-]*[Tt]o[ \t_-]*[Ss]kip:?[ \t]*", TypeUCharPTR }, { &fstypesraw, NULL, (UChar *) "^[ \t]*[Ff]i?l?e?[ \t_-]*[Ss]y?s?t?e?m?[ \t_-]*[Tt]ypes:?[ \t]*", TypeUCharPTR }, { &indexfilepart, NULL, (UChar *) "^[ \t]*[Ii]ndex[ \t_-]*[Ff]ile[ \t_-]*[Pp]art:?[ \t]*", TypeUCharPTR }, { &numindexestostore, NULL, (UChar *) "^[ \t]*[Nn]um[-_ \t]*[Ii]nd\\(ic\\|ex\\)es[-_ \t]*[Tt]o[ \t_-]*[Ss]tore:?", TypeInt32 }, { &daystostoreindexes, NULL, (UChar *) "^[ \t]*[Dd]ays[-_ \t]*[Tt]o[ \t_-]*[Ss]tore[-_ \t]*[Ii]nd\\(ic\\|ex\\)es:?", TypeReal32 }, { &numindexestoscan, NULL, (UChar *) "^[ \t]*[Nn]um[-_ \t]*[Ii]nd\\(ic\\|ex\\)es[-_ \t]*[Tt]o[ \t_-]*[Ss]can:?", TypeInt32 }, { &daystoscanindexes, NULL, (UChar *) "^[ \t]*[Dd]ays[-_ \t]*[Tt]o[ \t_-]*[Ss]can[-_ \t]*[Ii]nd\\(ic\\|ex\\)es:?", TypeReal32 }, { &compresscmd, NULL, (UChar *) "^[ \t]*\\([Pp]rocess\\|[Cc]ompress\\)[-_ \t]*[Cc]o?m?ma?n?d:?[ \t]*", TypeUCharPTR }, { &uncompresscmd, NULL, (UChar *) "^[ \t]*\\([Uu]nprocess\\|[Uu]ncompress\\)[-_ \t]*[Cc]o?m?ma?n?d:?[ \t]*", TypeUCharPTR }, { &idxcompresscmd, NULL, (UChar *) "^[ \t]*[Ii]ndex[-_ \t]*\\([Pp]rocess\\|[Cc]ompress\\)[-_ \t]*[Cc]o?m?ma?n?d:?[ \t]*", TypeUCharPTR }, { &idxuncompresscmd, NULL, (UChar *) "^[ \t]*[Ii]ndex[-_ \t]*\\([Uu]nprocess\\|[Uu]ncompress\\)[-_ \t]*[Cc]o?m?ma?n?d:?[ \t]*", TypeUCharPTR }, { &builtin_compr_level, NULL, (UChar *) "^[ \t]*[Bb]uilt[-_ \t]*[iI]n[-_ \t]*[Cc]ompre?s?s?i?o?n?[-_ \t]*\\([Ll]evel\\)?:?", TypeInt32 }, { &dont_compress_str, NULL, (UChar *) "^[ \t]*[Dd]o[-_ \t]*[Nn][\'o]?t[-_ \t]*\\([Pp]rocess\\|[Cc]ompress\\):?[ \t]*", TypeUCharPTR }, { &exclude_filename, NULL, (UChar *) "^[ \t]*[Ee]xclu?d?e?[-_ \t]*[Ll]ist[-_ \t]*[Ff]ile[-_ \t]*[Nn]?a?m?e?:?[ \t]*", TypeUCharPTR }, { &logfile, NULL, (UChar *) "^[ \t]*[Ll]ogg?i?n?g?[-_ \t]*[Ff]ile:?[ \t]*", TypeUCharPTR }, { &numparts, NULL, (UChar *) "^[ \t]*[Nn]um[-_ \t]*[Bb]ackup[-_ \t]*[Pp]arts:?", TypeInt32 }, { &cartsets, &num_cartsets, (UChar *) "^[ \t]*[Cc]artr?i?d?g?e?[-_ \t]*[Ss]ets?:?", TypeInt32PTR }, { &startinfoprog, NULL, (UChar *) "^[ \t]*[Ss]tartu?p?[-_ \t]*[Ii]nfo[-_ \t]*[Pp]rogram:?[ \t]*", TypeUCharPTR }, { &initprog, NULL, (UChar *) "^[ \t]*[Ii]nit[-_ \t]*[Pp]rogram:?[ \t]*", TypeUCharPTR }, { &exitprog, NULL, (UChar *) "^[ \t]*[Ee]xit[-_ \t]*[Pp]rogram:?[ \t]*", TypeUCharPTR }, { &compresslogfiles, NULL, (UChar *) "^[ \t]*\\([Pp]rocess\\|[Cc]ompress\\)[-_ \t]*\\([Ll]ogg?i?n?g?[-_ \t]*[Ff]iles?\\|[Ii]n?d\\(e?x\\|i?c\\)e?s?\\([Ff]iles?\\)?\\)[-_ \t]*:?", TypeFlag }, { &compressbu, NULL, (UChar *) "^[ \t]*\\([Pp]rocess\\|[Cc]ompress\\)[-_ \t]*[Bb]ackupe?d?[-_ \t]*\\([Ff]iles\\)?:?", TypeFlag }, { &cryptfile, NULL, (UChar *) "^[ \t]*\\([Ee]n\\)?[Cc]rypti?o?n?[ \t_-]*[Kk]ey[ \t_-]*[Ff]ile:?[ \t]*", TypeUCharPTR }, { &lockfile, NULL, (UChar *) "^[ \t]*[Ll]ocki?n?g?[-_ \t]*[Ff]ile:?[ \t]*", TypeUCharPTR }, { &vardir, NULL, (UChar *) "^[ \t]*[Vv][Aa][Rr][-_ \t]*[Dd]ire?c?t?o?r?y?:?[ \t]*",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -