Skip to content

Commit 6ce7163

Browse files
committed
Add simple progress bar with option --progress.
1 parent 02ac17b commit 6ce7163

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

backup.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ static XLogRecPtr stop_backup_lsn = InvalidXLogRecPtr;
3838
const char *progname = "pg_arman";
3939

4040
/* list of files contained in backup */
41-
parray *backup_files_list;
41+
parray *backup_files_list;
42+
static volatile uint32 total_copy_files_increment;
43+
static uint32 total_files_num;
4244

4345
typedef struct
4446
{
@@ -309,6 +311,10 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
309311
if (!check)
310312
dir_create_dir(dirpath, DIR_PERMISSION);
311313
}
314+
else
315+
{
316+
total_files_num++;
317+
}
312318
}
313319

314320
if (num_threads < 1)
@@ -337,6 +343,8 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
337343
parray_get(backup_files_list, i));
338344
}
339345

346+
total_copy_files_increment = 0;
347+
340348
/* Run threads */
341349
for (i = 0; i < num_threads; i++)
342350
{
@@ -352,6 +360,9 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
352360
pg_free(backup_threads_args[i]);
353361
}
354362

363+
if (progress)
364+
fprintf(stderr, "\n");
365+
355366
/* Notify end of backup */
356367
pg_stop_backup(&current);
357368

@@ -1014,6 +1025,9 @@ backup_files(void *arg)
10141025
}
10151026
else
10161027
elog(LOG, "unexpected file type %d", buf.st_mode);
1028+
if (progress)
1029+
fprintf(stderr, "\rProgress %i/%u", total_copy_files_increment, total_files_num-1);
1030+
__sync_fetch_and_add(&total_copy_files_increment, 1);
10171031
}
10181032
}
10191033

expected/option.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Common Options:
1818
-c, --check show what would have been done
1919
-j, --threads=NUM num threads for backup and restore
2020
--stream use stream for save/restore WAL during backup
21+
--progress show progress copy files
2122

2223
Backup options:
2324
-b, --backup-mode=MODE full,page,ptrack

pg_arman.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ bool stream_wal = false;
3939
bool disable_ptrack_clear = false;
4040
static bool backup_logs = false;
4141
static bool backup_validate = false;
42+
bool progress = false;
4243

4344
/* restore configuration */
4445
static char *target_time;
@@ -62,6 +63,7 @@ static pgut_option options[] =
6263
{ 'b', 'c', "check", &check },
6364
{ 'i', 'j', "threads", &num_threads },
6465
{ 'b', 8, "stream", &stream_wal },
66+
{ 'b', 11, "progress", &progress },
6567
/* backup options */
6668
{ 'b', 9, "disable-ptrack-clear", &disable_ptrack_clear },
6769
{ 'b', 10, "backup-pg-log", &backup_logs },
@@ -239,6 +241,7 @@ pgut_help(bool details)
239241
printf(_(" -c, --check show what would have been done\n"));
240242
printf(_(" -j, --threads=NUM num threads for backup and restore\n"));
241243
printf(_(" --stream use stream for save/restore WAL during backup\n"));
244+
printf(_(" --progress show progress copy files\n"));
242245
printf(_("\nBackup options:\n"));
243246
printf(_(" -b, --backup-mode=MODE full,page,ptrack\n"));
244247
printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));

pg_arman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ extern parray *backup_files_list;
211211
extern int num_threads;
212212
extern bool stream_wal;
213213
extern bool disable_ptrack_clear;
214+
extern bool progress;
214215

215216
/* in backup.c */
216217
extern int do_backup(pgBackupOption bkupopt);

0 commit comments

Comments
 (0)