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

Commitb92d722

Browse files
author
Michael Paquier
committed
Clean up the snapshot related stuff
This is not really part of the core of pg_rman, rather better tofocus on incremental backup or stuff like that.
1 parentebe2166 commitb92d722

File tree

2 files changed

+0
-536
lines changed

2 files changed

+0
-536
lines changed

‎backup.c

Lines changed: 0 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ static void delete_online_wal_backup(void);
5757

5858
staticbooldirExists(constchar*path);
5959

60-
staticvoidexecute_freeze(void);
61-
staticvoidexecute_unfreeze(void);
62-
staticvoidexecute_split(parray*tblspc_list);
63-
staticvoidexecute_resync(void);
64-
staticvoidexecute_mount(parray*tblspcmp_list);
65-
staticvoidexecute_umount(void);
66-
staticvoidexecute_script(constchar*mode,boolis_cleanup,parray*output);
67-
staticvoidsnapshot_cleanup(boolfatal,void*userdata);
6860
staticvoidadd_files(parray*files,constchar*root,booladd_root,boolis_pgdata);
6961
staticintstrCompare(constvoid*str1,constvoid*str2);
7062
staticvoidcreate_file_list(parray*files,constchar*root,constchar*prefix,boolis_append);
@@ -241,20 +233,6 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
241233
for (i=0;pgdata_exclude[i];i++);/* find first empty slot */
242234
pgdata_exclude[i]=PG_TBLSPC_DIR;
243235

244-
/* set the error processing for the snapshot */
245-
pgut_atexit_push(snapshot_cleanup,cleanup_list);
246-
247-
/* create snapshot volume */
248-
if (!check)
249-
{
250-
/* freeze I/O of the file-system */
251-
execute_freeze();
252-
/* create the snapshot, and obtain the name of TABLESPACE backup from snapshot */
253-
execute_split(tblspc_list);
254-
/* unfreeze I/O of the file-system */
255-
execute_unfreeze();
256-
}
257-
258236
/*
259237
* when DB cluster is not contained in the backup from the snapshot,
260238
* DB cluster is added to the backup file list from non-snapshot.
@@ -315,10 +293,6 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
315293
/* create file list of non-snapshot objects */
316294
create_file_list(files,pgdata,NULL, false);
317295

318-
/* mount snapshot volume to file-system, and obtain that mounted directory */
319-
if (!check)
320-
execute_mount(tblspcmp_list);
321-
322296
/* backup files from snapshot volume */
323297
for (i=0;i<parray_num(tblspcmp_list);i++)
324298
{
@@ -414,17 +388,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
414388
parray_walk(tblspcmp_list,free);
415389
parray_free(tblspcmp_list);
416390

417-
/* snapshot became unnecessary, annul the snapshot */
418-
if (!check)
419-
{
420-
/* unmount directory of mounted snapshot volume */
421-
execute_umount();
422-
/* annul the snapshot */
423-
execute_resync();
424-
}
425391

426-
/* unset the error processing for the snapshot */
427-
pgut_atexit_pop(snapshot_cleanup,cleanup_list);
428392
/* don't use 'parray_walk'. element of parray not allocate memory by malloc */
429393
parray_free(cleanup_list);
430394
PQclear(tblspc_res);
@@ -1557,200 +1521,6 @@ delete_arclog_link(void)
15571521
parray_free(files);
15581522
}
15591523

1560-
/*
1561-
* Execute the command 'freeze' of snapshot-script.
1562-
* When the command ends normally, 'unfreeze' is added to the cleanup list.
1563-
*/
1564-
staticvoid
1565-
execute_freeze(void)
1566-
{
1567-
/* append 'unfreeze' command to cleanup list */
1568-
parray_append(cleanup_list,SNAPSHOT_UNFREEZE);
1569-
1570-
/* execute 'freeze' command */
1571-
execute_script(SNAPSHOT_FREEZE, false,NULL);
1572-
}
1573-
1574-
/*
1575-
* Execute the command 'unfreeze' of snapshot-script.
1576-
* Remove 'unfreeze' from the cleanup list before executing the command
1577-
* when 'unfreeze' is included in the cleanup list.
1578-
*/
1579-
staticvoid
1580-
execute_unfreeze(void)
1581-
{
1582-
inti;
1583-
1584-
/* remove 'unfreeze' command from cleanup list */
1585-
for (i=0;i<parray_num(cleanup_list);i++)
1586-
{
1587-
char*mode;
1588-
1589-
mode= (char*)parray_get(cleanup_list,i);
1590-
if (strcmp(mode,SNAPSHOT_UNFREEZE)==0)
1591-
{
1592-
parray_remove(cleanup_list,i);
1593-
break;
1594-
}
1595-
}
1596-
/* execute 'unfreeze' command */
1597-
execute_script(SNAPSHOT_UNFREEZE, false,NULL);
1598-
}
1599-
1600-
/*
1601-
* Execute the command 'split' of snapshot-script.
1602-
* When the command ends normally, 'resync' is added to the cleanup list.
1603-
*/
1604-
staticvoid
1605-
execute_split(parray*tblspc_list)
1606-
{
1607-
/* append 'resync' command to cleanup list */
1608-
parray_append(cleanup_list,SNAPSHOT_RESYNC);
1609-
1610-
/* execute 'split' command */
1611-
execute_script(SNAPSHOT_SPLIT, false,tblspc_list);
1612-
}
1613-
1614-
/*
1615-
* Execute the command 'resync' of snapshot-script.
1616-
* Remove 'resync' from the cleanup list before executing the command
1617-
* when 'resync' is included in the cleanup list.
1618-
*/
1619-
staticvoid
1620-
execute_resync(void)
1621-
{
1622-
inti;
1623-
1624-
/* remove 'resync' command from cleanup list */
1625-
for (i=0;i<parray_num(cleanup_list);i++)
1626-
{
1627-
char*mode;
1628-
1629-
mode= (char*)parray_get(cleanup_list,i);
1630-
if (strcmp(mode,SNAPSHOT_RESYNC)==0)
1631-
{
1632-
parray_remove(cleanup_list,i);
1633-
break;
1634-
}
1635-
}
1636-
/* execute 'resync' command */
1637-
execute_script(SNAPSHOT_RESYNC, false,NULL);
1638-
}
1639-
1640-
/*
1641-
* Execute the command 'mount' of snapshot-script.
1642-
* When the command ends normally, 'umount' is added to the cleanup list.
1643-
*/
1644-
staticvoid
1645-
execute_mount(parray*tblspcmp_list)
1646-
{
1647-
/* append 'umount' command to cleanup list */
1648-
parray_append(cleanup_list,SNAPSHOT_UMOUNT);
1649-
1650-
/* execute 'mount' command */
1651-
execute_script(SNAPSHOT_MOUNT, false,tblspcmp_list);
1652-
}
1653-
1654-
/*
1655-
* Execute the command 'umount' of snapshot-script.
1656-
* Remove 'umount' from the cleanup list before executing the command
1657-
* when 'umount' is included in the cleanup list.
1658-
*/
1659-
staticvoid
1660-
execute_umount(void)
1661-
{
1662-
inti;
1663-
1664-
/* remove 'umount' command from cleanup list */
1665-
for (i=0;i<parray_num(cleanup_list);i++)
1666-
{
1667-
char*mode= (char*)parray_get(cleanup_list,i);
1668-
1669-
if (strcmp(mode,SNAPSHOT_UMOUNT)==0)
1670-
{
1671-
parray_remove(cleanup_list,i);
1672-
break;
1673-
}
1674-
}
1675-
/* execute 'umount' command */
1676-
execute_script(SNAPSHOT_UMOUNT, false,NULL);
1677-
}
1678-
1679-
/*
1680-
* Execute the snapshot-script in the specified mode.
1681-
* A standard output of snapshot-script is stored in the array given to the parameter.
1682-
* If is_cleanup is TRUE, processing is continued.
1683-
*/
1684-
staticvoid
1685-
execute_script(constchar*mode,boolis_cleanup,parray*output)
1686-
{
1687-
charss_script[MAXPGPATH];
1688-
charcommand[1024];
1689-
charfline[2048];
1690-
intnum;
1691-
FILE*out;
1692-
parray*lines;
1693-
1694-
/* obtain the path of snapshot-script. */
1695-
join_path_components(ss_script,backup_path,SNAPSHOT_SCRIPT_FILE);
1696-
snprintf(command,sizeof(command),
1697-
"%s %s %s",ss_script,mode,is_cleanup ?"cleanup" :"");
1698-
1699-
/* execute snapshot-script */
1700-
out=popen(command,"r");
1701-
if (out==NULL)
1702-
elog(ERROR_SYSTEM,_("could not execute snapshot-script: %s\n"),strerror(errno));
1703-
1704-
/* read STDOUT and store into the array each line */
1705-
lines=parray_new();
1706-
while (fgets(fline,sizeof(fline),out)!=NULL)
1707-
{
1708-
/* remove line separator */
1709-
if (fline[strlen(fline)-1]=='\n')
1710-
fline[strlen(fline)-1]='\0';
1711-
parray_append(lines,pgut_strdup(fline));
1712-
}
1713-
pclose(out);
1714-
1715-
/*
1716-
* status of the command is obtained from the last element of the array
1717-
* if last element is not 'SUCCESS', that means ERROR.
1718-
*/
1719-
num=parray_num(lines);
1720-
if (num <=0||strcmp((char*)parray_get(lines,num-1),"SUCCESS")!=0)
1721-
elog(is_cleanup ?WARNING :ERROR_SYSTEM,_("snapshot-script failed: %s"),mode);
1722-
1723-
/* if output is not NULL, concat array. */
1724-
if (output)
1725-
{
1726-
parray_remove(lines,num-1);/* remove last element, that is command status */
1727-
parray_concat(output,lines);
1728-
}
1729-
/* if output is NULL, clear directory list */
1730-
else
1731-
{
1732-
parray_walk(lines,free);
1733-
parray_free(lines);
1734-
}
1735-
}
1736-
1737-
/*
1738-
* Delete the unnecessary object created by snapshot-script.
1739-
* The command necessary for the deletion is given from the parameter.
1740-
* When the error occurs, this function is called.
1741-
*/
1742-
staticvoid
1743-
snapshot_cleanup(boolfatal,void*userdata)
1744-
{
1745-
parray*cleanup_list;
1746-
inti;
1747-
1748-
/* Execute snapshot-script for cleanup */
1749-
cleanup_list= (parray*)userdata;
1750-
for (i=parray_num(cleanup_list)-1;i >=0;i--)
1751-
execute_script((char*)parray_get(cleanup_list,i), true,NULL);
1752-
}
1753-
17541524
/*
17551525
* Append files to the backup list array.
17561526
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp