Skip to content

Commit b92d722

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 to focus on incremental backup or stuff like that.
1 parent ebe2166 commit b92d722

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
static bool dirExists(const char *path);
5959

60-
static void execute_freeze(void);
61-
static void execute_unfreeze(void);
62-
static void execute_split(parray *tblspc_list);
63-
static void execute_resync(void);
64-
static void execute_mount(parray *tblspcmp_list);
65-
static void execute_umount(void);
66-
static void execute_script(const char *mode, bool is_cleanup, parray *output);
67-
static void snapshot_cleanup(bool fatal, void *userdata);
6860
static void add_files(parray *files, const char *root, bool add_root, bool is_pgdata);
6961
static int strCompare(const void *str1, const void *str2);
7062
static void create_file_list(parray *files, const char *root, const char *prefix, bool is_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-
static void
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-
static void
1580-
execute_unfreeze(void)
1581-
{
1582-
int i;
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-
static void
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-
static void
1620-
execute_resync(void)
1621-
{
1622-
int i;
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-
static void
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-
static void
1660-
execute_umount(void)
1661-
{
1662-
int i;
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-
static void
1685-
execute_script(const char *mode, bool is_cleanup, parray *output)
1686-
{
1687-
char ss_script[MAXPGPATH];
1688-
char command[1024];
1689-
char fline[2048];
1690-
int num;
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-
static void
1743-
snapshot_cleanup(bool fatal, void *userdata)
1744-
{
1745-
parray *cleanup_list;
1746-
int i;
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy