In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "PostgreSQL backup tool pg_basebackup source code in the main function analysis", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn the "PostgreSQL backup tool pg_basebackup source code in the main function analysis" it!
I. data structure
Option
Data structure for storing options when using the tool
# ifndef HAVE_STRUCT_OPTION// tool software option struct option {const char * name;// name whether int has_arg;// contains parameters, no_argument/required_argument/optional_argument int * flag;// tag int val;// parameter value} # define no_argument 0#define required_argument 1#define optional_argument 2 * On OpenBSD and some versions of Solaris, opterr and friends are defined in * core libc rather than in a separate getopt module. Define these variables * only if configure found they aren't there by default; otherwise, this * module and its callers will just use libc's variables. (We assume that * testing opterr is sufficient for all of these.) * / # ifndef HAVE_INT_OPTERRint opterr = 1, / * if error message should be printed * / optind = 1, / * index into parent argv vector * / optopt; / * character checked for validity * / char * optarg / * argument associated with option * / # endif#define BADCH (int)'?'# define BADARG (int)':'# define EMSG "II. Source code interpretation
Pg_basebackup main function, source code is relatively simple, access to options, check, call BaseBackup () function for backup.
Intmain (int argc, char * * argv) {static struct option long_options [] = {{"help", no_argument, NULL,'?'}, {"version", no_argument, NULL,'V'}, {"pgdata", required_argument, NULL,'D'}, {"format", required_argument, NULL,'F'}, {"checkpoint", required_argument, NULL,'c'} {"create-slot", no_argument, NULL,'C'}, {"max-rate", required_argument, NULL,'r'}, {"write-recovery-conf", no_argument, NULL,'R'}, {"slot", required_argument, NULL,'S'}, {"tablespace-mapping", required_argument, NULL,'T'}, {"wal-method", required_argument, NULL 'X'}, {"gzip", no_argument, NULL,' z'}, {"compress", required_argument, NULL,'Z'}, {"label", required_argument, NULL,'l'}, {"no-clean", no_argument, NULL,'n'}, {"no-sync", no_argument, NULL,'N'}, {"dbname", required_argument, NULL 'd'}, {"host", required_argument, NULL,'h'}, {"port", required_argument, NULL,'p'}, {"username", required_argument, NULL,'U'}, {"no-password", no_argument, NULL,'w'}, {"password", no_argument, NULL,'W'}, {"status-interval", required_argument, NULL 's'}, {"verbose", no_argument, NULL,'v'}, {"progress", no_argument, NULL,'P'}, {"waldir", required_argument, NULL, 1}, {"no-slot", no_argument, NULL, 2}, {"no-verify-checksums", no_argument, NULL, 3}, {NULL, 0, NULL, 0}} / / (full) option / / option's ASCII value int c; / / option index number int option_index; / / Program name progname = get_progname (argv [0]); set_pglocale_pgservice (argv [0], PG_TEXTDOMAIN ("pg_basebackup")) If (argc > 1) {/ / display help information if (strcmp (argv [1], "--help") = = 0 | | strcmp (argv [1], "-?") = = 0) {usage (); exit (0) } else if (strcmp (argv [1], "- V") = = 0 | | strcmp (argv [1], "--version") = = 0) {/ / display version information puts ("pg_basebackup (PostgreSQL)" PG_VERSION); exit (0);}} atexit (cleanup_directories_atexit) / / getopt_long-- > get the option while (c = getopt_long (argc, argv, "CD:F:r:RS:T:X:l:nNzZ:d:c:h:p:U:s:wWkvP", long_options) & option_index)! =-1) {switch (c) / / set the parameter {case'Craft: create_slot = true according to the option Break; case'Downs: basedir = pg_strdup (optarg); break; case'Fables: if (strcmp (optarg, "p") = = 0 | | strcmp (optarg, "plain") = = 0) format ='p' / / do not compress else if (strcmp (optarg, "t") = = 0 | | strcmp (optarg, "tar") = = 0) format ='t' / / tar package else {fprintf (stderr, _ ("% s: invalid output format\"% s\ ", must be\" plain\ "or\" tar\ "\ n"), progname, optarg); exit (1) } break; case'ringing: maxrate = parse_max_rate (optarg); break; case'ringing: writerecoveryconf = true; break Case'scars: / * * When specifying replication slot name, use a permanent * slot. * specify the name of the replication slot, then use the persistence slot * / replication_slot = pg_strdup (optarg); temp_replication_slot = false; break; case 2: no_slot = true; break Case'Tables: tablespace_list_append (optarg); break; case'Xboxes: if (strcmp (optarg, "n") = = 0 | | strcmp (optarg, "none") = = 0) {includewal = NO_WAL } else if (strcmp (optarg, "f") = = 0 | | strcmp (optarg, "fetch") = = 0) {includewal = FETCH_WAL } else if (strcmp (optarg, "s") = = 0 | | strcmp (optarg, "stream") = = 0) {includewal = STREAM_WAL } else {fprintf (stderr, _ ("% s: invalid wal-method option\"% s\ ", must be\" fetch\ ",\" stream\ ", or\" none\ "\ n), progname, optarg) Exit (1);} break; case 1: xlog_dir = pg_strdup (optarg); break; case'lame: label = pg_strdup (optarg); break Case'nails: noclean = true; break; case'Names: do_sync = false; break; case 'z':#ifdef HAVE_LIBZ compresslevel = Zhuan DEFAULTING COMPRESSION investors else compresslevel = 1; / * will be rejected below * / # endif break Case'Zhuan: compresslevel = atoi (optarg); if (compresslevel)
< 0 || compresslevel >Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.