Skip to content

Commit 31efd8f

Browse files
committed
Format change: file_database.txt is renamed to backup_content.control. Now it has json format.
1 parent f833ca6 commit 31efd8f

File tree

2 files changed

+60
-85
lines changed

2 files changed

+60
-85
lines changed

dir.c

Lines changed: 59 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
327327
parray_qsort(files, pgFileComparePath);
328328
}
329329

330+
/*
331+
* TODO Add comment, review
332+
* TODO if met file of unusual format throw a WARNING and don't add to list.
333+
*/
330334
static void
331335
dir_list_file_internal(parray *files, const char *root, bool exclude,
332336
bool omit_symlink, bool add_root, parray *black_list)
@@ -623,9 +627,7 @@ read_tablespace_map(parray *files, const char *backup_dir)
623627
}
624628

625629
/*
626-
* Print file list.
627-
* TODO review
628-
* TODO invent more convenient format?
630+
* Print backup content list.
629631
*/
630632
void
631633
print_file_list(FILE *out, const parray *files, const char *root)
@@ -637,38 +639,33 @@ print_file_list(FILE *out, const parray *files, const char *root)
637639
{
638640
pgFile *file = (pgFile *) parray_get(files, i);
639641
char *path = file->path;
640-
char type;
641642

642643
/* omit root directory portion */
643644
if (root && strstr(path, root) == path)
644645
path = GetRelativePath(path, root);
645646

646-
/* TODO create an enum for file mode constants */
647-
if (S_ISREG(file->mode) && file->is_datafile)
648-
type = 'F';
649-
else if (S_ISREG(file->mode) && !file->is_datafile)
650-
type = 'f';
651-
else if (S_ISDIR(file->mode))
652-
type = 'd';
653-
else if (S_ISLNK(file->mode))
654-
type = 'l';
655-
else
656-
type = '?';
647+
fprintf(out, "{\"path\":\"%s\", \"size\":\"%lu\",\"mode\":\"%u\","
648+
"\"is_datafile\":\"%u\" \"crc\":\"%u\"",
649+
path, (unsigned long) file->write_size, file->mode,
650+
file->is_datafile?1:0, file->crc);
657651

658-
fprintf(out, "%s %c %lu %u 0%o", path, type,
659-
(unsigned long) file->write_size,
660-
file->crc, file->mode & (S_IRWXU | S_IRWXG | S_IRWXO));
652+
if (file->is_datafile)
653+
fprintf(out, ",\"segno\":\"%d\"", file->segno);
661654

655+
/* TODO What for do we write it to file? */
662656
if (S_ISLNK(file->mode))
663-
fprintf(out, " %s", file->linked);
657+
fprintf(out, ",\"linked\":\"%s\"", file->linked);
664658

665-
fprintf(out, " " UINT64_FORMAT " %d\n",
659+
#ifdef PGPRO_EE
660+
fprintf(out, ",\"CFS_generation\":\"" UINT64_FORMAT "\",\"is_partial_copy\":\"%d\"",
666661
file->generation, file->is_partial_copy);
662+
#endif
663+
fprintf(out, "}\n");
667664
}
668665
}
669666

670667
/*
671-
* Construct parray of pgFile from the file list.
668+
* Construct parray of pgFile from the backup content list.
672669
* If root is not NULL, path will be absolute path.
673670
*/
674671
parray *
@@ -688,83 +685,61 @@ dir_read_file_list(const char *root, const char *file_txt)
688685
while (fgets(buf, lengthof(buf), fp))
689686
{
690687
char path[MAXPGPATH];
691-
char type;
692-
int generation = -1;
688+
char filepath[MAXPGPATH];
689+
char linked[MAXPGPATH];
690+
uint64 generation = -1;
693691
int is_partial_copy = 0;
694692
unsigned long write_size;
695693
pg_crc32 crc;
696694
unsigned int mode; /* bit length of mode_t depends on platforms */
697695
pgFile *file;
696+
char *ptr;
697+
unsigned int is_datafile;
698+
int segno = 0;
699+
700+
ptr = strstr(buf,"path");
701+
sscanf(buf, "path:%s", path);
702+
ptr = strstr(buf,"size");
703+
sscanf(buf, "size:%lu", &write_size);
704+
ptr = strstr(buf,"mode");
705+
sscanf(buf, "mode:%u", &mode);
706+
ptr = strstr(buf,"is_datafile");
707+
sscanf(buf, "is_datafile:%u", &is_datafile);
708+
ptr = strstr(buf,"crc");
709+
sscanf(buf, "crc:%u", &crc);
710+
/* optional fields */
711+
ptr = strstr(buf,"linked");
712+
if (ptr)
713+
sscanf(buf, "linked:%s", linked);
714+
ptr = strstr(buf,"segno");
715+
if (ptr)
716+
sscanf(buf, "linked:%s", linked);
717+
#ifdef PGPRO_EE
718+
ptr = strstr(buf,"CFS_generation");
719+
sscanf(buf, "CFS_generation:%lu", &generation);
720+
ptr = strstr(buf,"is_partial_copy");
721+
sscanf(buf, "is_partial_copy:%d", &is_partial_copy);
722+
#endif
723+
if (root)
724+
sprintf(filepath, "%s/%s", root, path);
725+
else
726+
strcpy(filepath, path);
698727

699-
if (sscanf(buf, "%s %c %lu %u %o %d %d",
700-
path, &type, &write_size, &crc, &mode,
701-
&generation, &is_partial_copy) != 8)
702-
{
703-
elog(ERROR, "invalid format found in \"%s\"",
704-
file_txt);
705-
}
706-
707-
if (type != 'f' && type != 'F' && type != 'd' && type != 'l')
708-
{
709-
elog(ERROR, "invalid type '%c' found in \"%s\"",
710-
type, file_txt);
711-
}
712-
713-
file = (pgFile *) pgut_malloc(sizeof(pgFile));
714-
file->path = pgut_malloc((root ? strlen(root) + 1 : 0) + strlen(path) + 1);
715-
file->ptrack_path = NULL;
716-
file->segno = 0;
717-
file->pagemap.bitmap = NULL;
718-
file->pagemap.bitmapsize = 0;
728+
file = pgFileNew(filepath, false);
719729

720-
file->mode = mode |
721-
((type == 'f' || type == 'F') ? S_IFREG :
722-
type == 'd' ? S_IFDIR : type == 'l' ? S_IFLNK : 0);
723-
file->generation = generation;
724-
file->is_partial_copy = is_partial_copy;
725-
file->size = 0;
726-
file->read_size = 0;
727730
file->write_size = write_size;
731+
file->mode = mode;
732+
file->is_datafile = is_datafile ? true : false;
728733
file->crc = crc;
729-
file->is_datafile = (type == 'F' ? true : false);
730-
file->linked = NULL;
731-
if (root)
732-
sprintf(file->path, "%s/%s", root, path);
733-
else
734-
strcpy(file->path, path);
734+
file->linked = NULL; /* TODO Why don't read it? */
735+
file->segno = segno;
736+
file->generation = generation;
737+
file->is_partial_copy = is_partial_copy;
735738

736739
parray_append(files, file);
737-
738-
if(file->is_datafile)
739-
{
740-
int find_dot;
741-
int check_digit;
742-
char *text_segno;
743-
size_t path_len = strlen(file->path);
744-
for(find_dot = path_len-1; file->path[find_dot] != '.' && find_dot >= 0; find_dot--);
745-
if (find_dot <= 0)
746-
continue;
747-
748-
text_segno = file->path + find_dot + 1;
749-
for(check_digit=0; text_segno[check_digit] != '\0'; check_digit++)
750-
if (!isdigit(text_segno[check_digit]))
751-
{
752-
check_digit = -1;
753-
break;
754-
}
755-
756-
if (check_digit == -1)
757-
continue;
758-
759-
file->segno = (int) strtol(text_segno, NULL, 10);
760-
}
761740
}
762741

763742
fclose(fp);
764-
765-
/* file.txt is sorted, so this qsort is redundant */
766-
parray_qsort(files, pgFileComparePath);
767-
768743
return files;
769744
}
770745

pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define BACKUP_CONF_FILE "backup.conf"
4040
#define BACKUP_CATALOG_CONF_FILE "pg_probackup.conf"
4141
#define BACKUP_CATALOG_PID "pg_probackup.pid"
42-
#define DATABASE_FILE_LIST "file_database.txt"
42+
#define DATABASE_FILE_LIST "backup_content.control"
4343
#define PG_BACKUP_LABEL_FILE "backup_label"
4444
#define PG_BLACK_LIST "black_list"
4545
#define PG_TABLESPACE_MAP_FILE "tablespace_map"

0 commit comments

Comments
 (0)