Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ce7163

Browse files
committed
Add simple progress bar with option --progress.
1 parent02ac17b commit6ce7163

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
constchar*progname="pg_arman";
3939

4040
/* list of files contained in backup */
41-
parray*backup_files_list;
41+
parray*backup_files_list;
42+
staticvolatileuint32total_copy_files_increment;
43+
staticuint32total_files_num;
4244

4345
typedefstruct
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 @@ boolstream_wal = false;
3939
booldisable_ptrack_clear= false;
4040
staticboolbackup_logs= false;
4141
staticboolbackup_validate= false;
42+
boolprogress= false;
4243

4344
/* restore configuration */
4445
staticchar*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
externintnum_threads;
212212
externboolstream_wal;
213213
externbooldisable_ptrack_clear;
214+
externboolprogress;
214215

215216
/* in backup.c */
216217
externintdo_backup(pgBackupOptionbkupopt);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp