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

Commit9f2ad9d

Browse files
committed
Remove date range and start use base36 from start_time as backup ID.
1 parentd3f3110 commit9f2ad9d

File tree

10 files changed

+77
-197
lines changed

10 files changed

+77
-197
lines changed

‎backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ do_backup(pgBackupOption bkupopt)
497497
elog(LOG,"backup destination is initialized");
498498

499499
/* get list of backups already taken */
500-
backup_list=catalog_get_backup_list(NULL);
500+
backup_list=catalog_get_backup_list(0);
501501
if (!backup_list)
502502
elog(ERROR,"cannot process any more");
503503

‎catalog.c

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,14 @@ IsDir(const char *dirpath, const char *entry)
106106
* The list is sorted in order of descending start time.
107107
*/
108108
parray*
109-
catalog_get_backup_list(constpgBackupRange*range)
109+
catalog_get_backup_list(time_tbackup_id)
110110
{
111-
constpgBackupRangerange_all= {0,0 };
112111
DIR*date_dir=NULL;
113112
structdirent*date_ent=NULL;
114113
DIR*time_dir=NULL;
115-
structdirent*time_ent=NULL;
116114
chardate_path[MAXPGPATH];
117115
parray*backups=NULL;
118116
pgBackup*backup=NULL;
119-
structtm*tm;
120-
charbegin_date[100];
121-
charbegin_time[100];
122-
charend_date[100];
123-
charend_time[100];
124-
125-
if (range==NULL)
126-
range=&range_all;
127-
128-
/* make date/time string */
129-
tm=localtime(&range->begin);
130-
strftime(begin_date,lengthof(begin_date),"%Y%m%d",tm);
131-
strftime(begin_time,lengthof(begin_time),"%H%M%S",tm);
132-
tm=localtime(&range->end);
133-
strftime(end_date,lengthof(end_date),"%Y%m%d",tm);
134-
strftime(end_time,lengthof(end_time),"%H%M%S",tm);
135117

136118
/* open backup root directory */
137119
date_dir=opendir(backup_path);
@@ -146,6 +128,8 @@ catalog_get_backup_list(const pgBackupRange *range)
146128
backups=parray_new();
147129
for (; (date_ent=readdir(date_dir))!=NULL;errno=0)
148130
{
131+
charini_path[MAXPGPATH];
132+
149133
/* skip not-directory entries and hidden entries */
150134
if (!IsDir(backup_path,date_ent->d_name)||date_ent->d_name[0]=='.')
151135
continue;
@@ -154,55 +138,30 @@ catalog_get_backup_list(const pgBackupRange *range)
154138
if (strcmp(date_ent->d_name,RESTORE_WORK_DIR)==0)
155139
continue;
156140

157-
/* If the date is out of range, skip it. */
158-
if (pgBackupRangeIsValid(range)&&
159-
(strcmp(begin_date,date_ent->d_name)>0||
160-
strcmp(end_date,date_ent->d_name)<0))
161-
continue;
162-
163141
/* open subdirectory (date directory) and search time directory */
164142
join_path_components(date_path,backup_path,date_ent->d_name);
165-
time_dir=opendir(date_path);
166-
if (time_dir==NULL)
167-
{
168-
elog(WARNING,"cannot open directory \"%s\": %s",
169-
date_ent->d_name,strerror(errno));
170-
gotoerr_proc;
171-
}
172-
for (; (time_ent=readdir(time_dir))!=NULL;errno=0)
173-
{
174-
charini_path[MAXPGPATH];
175143

176-
/* skip entries that are directories and hidden directories */
177-
if (!IsDir(date_path,time_ent->d_name)||time_ent->d_name[0]=='.')
178-
continue;
179-
180-
/* If the time is out of range, skip it. */
181-
if (pgBackupRangeIsValid(range)&&
182-
(strcmp(begin_time,time_ent->d_name)>0||
183-
strcmp(end_time,time_ent->d_name)<0))
184-
continue;
185-
186-
/* read backup information from backup.ini */
187-
snprintf(ini_path,MAXPGPATH,"%s/%s/%s",date_path,
188-
time_ent->d_name,BACKUP_INI_FILE);
189-
backup=catalog_read_ini(ini_path);
144+
/* read backup information from backup.ini */
145+
snprintf(ini_path,MAXPGPATH,"%s/%s",date_path,BACKUP_INI_FILE);
146+
backup=catalog_read_ini(ini_path);
190147

191-
/* ignore corrupted backup */
192-
if (backup)
148+
/* ignore corrupted backup */
149+
if (backup)
150+
{
151+
if (backup_id!=0&&backup_id!=backup->start_time)
193152
{
194-
parray_append(backups,backup);
195-
backup=NULL;
153+
pgBackupFree(backup);
154+
continue;
196155
}
156+
parray_append(backups,backup);
157+
backup=NULL;
197158
}
198159
if (errno&&errno!=ENOENT)
199160
{
200161
elog(WARNING,"cannot read date directory \"%s\": %s",
201162
date_ent->d_name,strerror(errno));
202163
gotoerr_proc;
203164
}
204-
closedir(time_dir);
205-
time_dir=NULL;
206165
}
207166
if (errno)
208167
{
@@ -526,16 +485,14 @@ pgBackupCompareIdDesc(const void *l, const void *r)
526485
void
527486
pgBackupGetPath(constpgBackup*backup,char*path,size_tlen,constchar*subdir)
528487
{
529-
chardatetime[20];
530-
structtm*tm;
488+
char*datetime;
531489

532-
/* generate $BACKUP_PATH/date/time path */
533-
tm=localtime(&backup->start_time);
534-
strftime(datetime,lengthof(datetime),"%Y%m%d/%H%M%S",tm);
490+
datetime=base36enc(backup->start_time);
535491
if (subdir)
536492
snprintf(path,len,"%s/%s/%s",backup_path,datetime,subdir);
537493
else
538494
snprintf(path,len,"%s/%s",backup_path,datetime);
495+
free(datetime);
539496
}
540497

541498
void

‎delete.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
staticintpgBackupDeleteFiles(pgBackup*backup);
1616

1717
int
18-
do_delete(pgBackupRange*range)
18+
do_delete(time_tbackup_id)
1919
{
2020
inti;
2121
intret;
22-
parray*backup_list;
22+
parray*backup_list;
2323
booldo_delete= false;
2424
XLogRecPtroldest_lsn=InvalidXLogRecPtr;
2525
TimeLineIDoldest_tli;
2626

2727
/* DATE are always required */
28-
if (!pgBackupRangeIsValid(range))
28+
if (backup_id==0)
2929
elog(ERROR,"required delete range option not specified: delete DATE");
3030

3131
/* Lock backup catalog */
@@ -37,7 +37,7 @@ do_delete(pgBackupRange *range)
3737
"another pg_arman is running, stop delete.");
3838

3939
/* Get complete list of backups */
40-
backup_list=catalog_get_backup_list(NULL);
40+
backup_list=catalog_get_backup_list(0);
4141
if (!backup_list)
4242
elog(ERROR,"No backup list found, can't process any more.");
4343

@@ -60,7 +60,7 @@ do_delete(pgBackupRange *range)
6060
/* Found the latest full backup */
6161
if (backup->backup_mode >=BACKUP_MODE_FULL&&
6262
backup->status==BACKUP_STATUS_OK&&
63-
backup->start_time <=range->begin)
63+
backup->start_time <=backup_id)
6464
{
6565
do_delete= true;
6666
oldest_lsn=backup->start_lsn;
@@ -192,7 +192,7 @@ pgBackupDelete(int keep_generations, int keep_days)
192192
}
193193

194194
/* Get a complete list of backups. */
195-
backup_list=catalog_get_backup_list(NULL);
195+
backup_list=catalog_get_backup_list(0);
196196

197197
/* Find target backups to be deleted */
198198
backup_num=0;

‎pg_arman.c

Lines changed: 10 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ static TimeLineIDtarget_tli;
5050
staticboolshow_all= false;
5151

5252
staticvoidopt_backup_mode(pgut_option*opt,constchar*arg);
53-
staticvoidparse_range(pgBackupRange*range,constchar*arg1,constchar*arg2);
5453

5554
staticpgut_optionoptions[]=
5655
{
@@ -87,9 +86,8 @@ int
8786
main(intargc,char*argv[])
8887
{
8988
constchar*cmd=NULL;
90-
constchar*range1=NULL;
91-
constchar*range2=NULL;
92-
pgBackupRangerange;
89+
constchar*backup_id_string=NULL;
90+
time_tbackup_id=0;
9391
inti;
9492

9593
/* do not buffer progress messages */
@@ -110,10 +108,8 @@ main(int argc, char *argv[])
110108
strcmp(cmd,"validate")!=0&&
111109
strcmp(cmd,"delete")!=0)
112110
break;
113-
}elseif (range1==NULL)
114-
range1=argv[i];
115-
elseif (range2==NULL)
116-
range2=argv[i];
111+
}elseif (backup_id_string==NULL)
112+
backup_id_string=argv[i];
117113
else
118114
elog(ERROR,"too many arguments");
119115
}
@@ -125,13 +121,8 @@ main(int argc, char *argv[])
125121
return1;
126122
}
127123

128-
/* get object range argument if any */
129-
if (range1&&range2)
130-
parse_range(&range,range1,range2);
131-
elseif (range1)
132-
parse_range(&range,range1,"");
133-
else
134-
range.begin=range.end=0;
124+
if (backup_id_string!=NULL)
125+
backup_id=base36dec(backup_id_string);
135126

136127
/* Read default configuration from file. */
137128
if (backup_path)
@@ -195,20 +186,17 @@ main(int argc, char *argv[])
195186
if (res!=0)
196187
returnres;
197188

198-
/* If validation has been requested, do it */
199-
range.begin=current.start_time;
200-
range.end=current.start_time+1;
201-
do_validate(&range);
189+
do_validate(current.start_time);
202190
}
203191
elseif (pg_strcasecmp(cmd,"restore")==0)
204192
returndo_restore(target_time,target_xid,
205193
target_inclusive,target_tli);
206194
elseif (pg_strcasecmp(cmd,"show")==0)
207-
returndo_show(&range,show_all);
195+
returndo_show(backup_id,show_all);
208196
elseif (pg_strcasecmp(cmd,"validate")==0)
209-
returndo_validate(&range);
197+
returndo_validate(backup_id);
210198
elseif (pg_strcasecmp(cmd,"delete")==0)
211-
returndo_delete(&range);
199+
returndo_delete(backup_id);
212200
else
213201
elog(ERROR,"invalid command \"%s\"",cmd);
214202

@@ -253,83 +241,6 @@ pgut_help(bool details)
253241
printf(_(" -a, --show-all show deleted backup too\n"));
254242
}
255243

256-
/*
257-
* Create range object from one or two arguments.
258-
* All not-digit characters in the argument(s) are ignored.
259-
* Both arg1 and arg2 must be valid pointer.
260-
*/
261-
staticvoid
262-
parse_range(pgBackupRange*range,constchar*arg1,constchar*arg2)
263-
{
264-
size_tlen=strlen(arg1)+strlen(arg2)+1;
265-
char*tmp;
266-
intnum;
267-
structtmtm;
268-
269-
tmp=pgut_malloc(len);
270-
tmp[0]='\0';
271-
if (arg1!=NULL)
272-
remove_not_digit(tmp,len,arg1);
273-
if (arg2!=NULL)
274-
remove_not_digit(tmp+strlen(tmp),len-strlen(tmp),arg2);
275-
276-
memset(&tm,0,sizeof(tm));
277-
tm.tm_year=0;/* tm_year is year - 1900 */
278-
tm.tm_mon=0;/* tm_mon is 0 - 11 */
279-
tm.tm_mday=1;/* tm_mday is 1 - 31 */
280-
tm.tm_hour=0;
281-
tm.tm_min=0;
282-
tm.tm_sec=0;
283-
num=sscanf(tmp,"%04d %02d %02d %02d %02d %02d",
284-
&tm.tm_year,&tm.tm_mon,&tm.tm_mday,
285-
&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
286-
287-
if (num<1)
288-
{
289-
if (strcmp(tmp,"")!=0)
290-
elog(ERROR,"supplied id(%s) is invalid",tmp);
291-
else
292-
elog(ERROR,"arguments are invalid. near \"%s\"",arg1);
293-
}
294-
295-
free(tmp);
296-
297-
/* adjust year and month to convert to time_t */
298-
tm.tm_year-=1900;
299-
if (num>1)
300-
tm.tm_mon-=1;
301-
tm.tm_isdst=-1;
302-
303-
if (!IsValidTime(tm))
304-
elog(ERROR,"supplied time(%s) is invalid.",arg1);
305-
306-
range->begin=mktime(&tm);
307-
308-
switch (num)
309-
{
310-
case1:
311-
tm.tm_year++;
312-
break;
313-
case2:
314-
tm.tm_mon++;
315-
break;
316-
case3:
317-
tm.tm_mday++;
318-
break;
319-
case4:
320-
tm.tm_hour++;
321-
break;
322-
case5:
323-
tm.tm_min++;
324-
break;
325-
case6:
326-
tm.tm_sec++;
327-
break;
328-
}
329-
range->end=mktime(&tm);
330-
range->end--;
331-
}
332-
333244
staticvoid
334245
opt_backup_mode(pgut_option*opt,constchar*arg)
335246
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp