* Receive a tar format stream from the connection to the server, and unpack * the contents of it into a directory. Only files, directories and * symlinks are supported, no other kinds of special files. * * If the data is for the main data directory, it will be restored in the * specified directory. If it's for another tablespace, it will be restored * in the original or mapped directory. */
| 1541 | * in the original or mapped directory. |
| 1542 | */ |
| 1543 | static void |
| 1544 | ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) |
| 1545 | { |
| 1546 | UnpackTarState state; |
| 1547 | bool basetablespace; |
| 1548 | |
| 1549 | memset(&state, 0, sizeof(state)); |
| 1550 | state.tablespacenum = rownum; |
| 1551 | |
| 1552 | basetablespace = PQgetisnull(res, rownum, 0); |
| 1553 | state.basetablespace = basetablespace; |
| 1554 | if (basetablespace) |
| 1555 | strlcpy(state.current_path, basedir, sizeof(state.current_path)); |
| 1556 | else |
| 1557 | { |
| 1558 | strlcpy(state.current_path, |
| 1559 | get_tablespace_mapping(PQgetvalue(res, rownum, 1)), |
| 1560 | sizeof(state.current_path)); |
| 1561 | |
| 1562 | if (target_gp_dbid < 1) |
| 1563 | { |
| 1564 | pg_log_error("cannot restore user-defined tablespaces without the --target-gp-dbid option"); |
| 1565 | exit(1); |
| 1566 | } |
| 1567 | |
| 1568 | /* |
| 1569 | * Construct the new tablespace path using the given target gp dbid |
| 1570 | */ |
| 1571 | snprintf(state.gp_tablespace_filename, sizeof(state.gp_tablespace_filename), |
| 1572 | "%s/%d/%s", |
| 1573 | state.current_path, |
| 1574 | target_gp_dbid, |
| 1575 | GP_TABLESPACE_VERSION_DIRECTORY); |
| 1576 | } |
| 1577 | |
| 1578 | ReceiveCopyData(conn, ReceiveTarAndUnpackCopyChunk, &state); |
| 1579 | |
| 1580 | |
| 1581 | if (state.file) |
| 1582 | fclose(state.file); |
| 1583 | |
| 1584 | progress_report(rownum, state.filename, true, false); |
| 1585 | |
| 1586 | if (state.file != NULL) |
| 1587 | { |
| 1588 | pg_log_error("COPY stream ended before last file was finished"); |
| 1589 | exit(1); |
| 1590 | } |
| 1591 | |
| 1592 | if (basetablespace && writerecoveryconf) |
| 1593 | WriteRecoveryConfig(conn, basedir, recoveryconfcontents); |
| 1594 | |
| 1595 | if (basetablespace) |
| 1596 | WriteInternalConfFile(); |
| 1597 | /* |
| 1598 | * No data is synced here, everything is done for all tablespaces at the |
| 1599 | * end. |
| 1600 | */ |
no test coverage detected