Skip to content

Commit 8ac62cb

Browse files
feat: add support for Cross region backup proto changes (#691)
* Synchronize new proto/yaml changes. PiperOrigin-RevId: 436114471 Source-Link: googleapis/googleapis@6379d5f Source-Link: googleapis/googleapis-gen@a59984b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTU5OTg0YjRjYjcxMWVlYjE4NmJjYTRmNWIzNWFkYmZlNjA4MjVkZiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 8c3f25f commit 8ac62cb

File tree

15 files changed

+1050
-7
lines changed

15 files changed

+1050
-7
lines changed

google/cloud/spanner_admin_database_v1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
from .types.backup import Backup
2121
from .types.backup import BackupInfo
22+
from .types.backup import CopyBackupEncryptionConfig
23+
from .types.backup import CopyBackupMetadata
24+
from .types.backup import CopyBackupRequest
2225
from .types.backup import CreateBackupEncryptionConfig
2326
from .types.backup import CreateBackupMetadata
2427
from .types.backup import CreateBackupRequest
@@ -57,6 +60,9 @@
5760
"DatabaseAdminAsyncClient",
5861
"Backup",
5962
"BackupInfo",
63+
"CopyBackupEncryptionConfig",
64+
"CopyBackupMetadata",
65+
"CopyBackupRequest",
6066
"CreateBackupEncryptionConfig",
6167
"CreateBackupMetadata",
6268
"CreateBackupRequest",

google/cloud/spanner_admin_database_v1/gapic_metadata.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"grpc": {
1111
"libraryClient": "DatabaseAdminClient",
1212
"rpcs": {
13+
"CopyBackup": {
14+
"methods": [
15+
"copy_backup"
16+
]
17+
},
1318
"CreateBackup": {
1419
"methods": [
1520
"create_backup"
@@ -100,6 +105,11 @@
100105
"grpc-async": {
101106
"libraryClient": "DatabaseAdminAsyncClient",
102107
"rpcs": {
108+
"CopyBackup": {
109+
"methods": [
110+
"copy_backup"
111+
]
112+
},
103113
"CreateBackup": {
104114
"methods": [
105115
"create_backup"

google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,168 @@ def sample_create_backup():
15061506
# Done; return the response.
15071507
return response
15081508

1509+
async def copy_backup(
1510+
self,
1511+
request: Union[backup.CopyBackupRequest, dict] = None,
1512+
*,
1513+
parent: str = None,
1514+
backup_id: str = None,
1515+
source_backup: str = None,
1516+
expire_time: timestamp_pb2.Timestamp = None,
1517+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1518+
timeout: float = None,
1519+
metadata: Sequence[Tuple[str, str]] = (),
1520+
) -> operation_async.AsyncOperation:
1521+
r"""Starts copying a Cloud Spanner Backup. The returned backup
1522+
[long-running operation][google.longrunning.Operation] will have
1523+
a name of the format
1524+
``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>``
1525+
and can be used to track copying of the backup. The operation is
1526+
associated with the destination backup. The
1527+
[metadata][google.longrunning.Operation.metadata] field type is
1528+
[CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata].
1529+
The [response][google.longrunning.Operation.response] field type
1530+
is [Backup][google.spanner.admin.database.v1.Backup], if
1531+
successful. Cancelling the returned operation will stop the
1532+
copying and delete the backup. Concurrent CopyBackup requests
1533+
can run on the same source backup.
1534+
1535+
1536+
.. code-block:: python
1537+
1538+
from google.cloud import spanner_admin_database_v1
1539+
1540+
def sample_copy_backup():
1541+
# Create a client
1542+
client = spanner_admin_database_v1.DatabaseAdminClient()
1543+
1544+
# Initialize request argument(s)
1545+
request = spanner_admin_database_v1.CopyBackupRequest(
1546+
parent="parent_value",
1547+
backup_id="backup_id_value",
1548+
source_backup="source_backup_value",
1549+
)
1550+
1551+
# Make the request
1552+
operation = client.copy_backup(request=request)
1553+
1554+
print("Waiting for operation to complete...")
1555+
1556+
response = operation.result()
1557+
1558+
# Handle the response
1559+
print(response)
1560+
1561+
Args:
1562+
request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]):
1563+
The request object. The request for
1564+
[CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup].
1565+
parent (:class:`str`):
1566+
Required. The name of the destination instance that will
1567+
contain the backup copy. Values are of the form:
1568+
``projects/<project>/instances/<instance>``.
1569+
1570+
This corresponds to the ``parent`` field
1571+
on the ``request`` instance; if ``request`` is provided, this
1572+
should not be set.
1573+
backup_id (:class:`str`):
1574+
Required. The id of the backup copy. The ``backup_id``
1575+
appended to ``parent`` forms the full backup_uri of the
1576+
form
1577+
``projects/<project>/instances/<instance>/backups/<backup>``.
1578+
1579+
This corresponds to the ``backup_id`` field
1580+
on the ``request`` instance; if ``request`` is provided, this
1581+
should not be set.
1582+
source_backup (:class:`str`):
1583+
Required. The source backup to be copied. The source
1584+
backup needs to be in READY state for it to be copied.
1585+
Once CopyBackup is in progress, the source backup cannot
1586+
be deleted or cleaned up on expiration until CopyBackup
1587+
is finished. Values are of the form:
1588+
``projects/<project>/instances/<instance>/backups/<backup>``.
1589+
1590+
This corresponds to the ``source_backup`` field
1591+
on the ``request`` instance; if ``request`` is provided, this
1592+
should not be set.
1593+
expire_time (:class:`google.protobuf.timestamp_pb2.Timestamp`):
1594+
Required. The expiration time of the backup in
1595+
microsecond granularity. The expiration time must be at
1596+
least 6 hours and at most 366 days from the
1597+
``create_time`` of the source backup. Once the
1598+
``expire_time`` has passed, the backup is eligible to be
1599+
automatically deleted by Cloud Spanner to free the
1600+
resources used by the backup.
1601+
1602+
This corresponds to the ``expire_time`` field
1603+
on the ``request`` instance; if ``request`` is provided, this
1604+
should not be set.
1605+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
1606+
should be retried.
1607+
timeout (float): The timeout for this request.
1608+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1609+
sent along with the request as metadata.
1610+
1611+
Returns:
1612+
google.api_core.operation_async.AsyncOperation:
1613+
An object representing a long-running operation.
1614+
1615+
The result type for the operation will be
1616+
:class:`google.cloud.spanner_admin_database_v1.types.Backup`
1617+
A backup of a Cloud Spanner database.
1618+
1619+
"""
1620+
# Create or coerce a protobuf request object.
1621+
# Quick check: If we got a request object, we should *not* have
1622+
# gotten any keyword arguments that map to the request.
1623+
has_flattened_params = any([parent, backup_id, source_backup, expire_time])
1624+
if request is not None and has_flattened_params:
1625+
raise ValueError(
1626+
"If the `request` argument is set, then none of "
1627+
"the individual field arguments should be set."
1628+
)
1629+
1630+
request = backup.CopyBackupRequest(request)
1631+
1632+
# If we have keyword arguments corresponding to fields on the
1633+
# request, apply these.
1634+
if parent is not None:
1635+
request.parent = parent
1636+
if backup_id is not None:
1637+
request.backup_id = backup_id
1638+
if source_backup is not None:
1639+
request.source_backup = source_backup
1640+
if expire_time is not None:
1641+
request.expire_time = expire_time
1642+
1643+
# Wrap the RPC method; this adds retry and timeout information,
1644+
# and friendly error handling.
1645+
rpc = gapic_v1.method_async.wrap_method(
1646+
self._client._transport.copy_backup,
1647+
default_timeout=3600.0,
1648+
client_info=DEFAULT_CLIENT_INFO,
1649+
)
1650+
1651+
# Certain fields should be provided within the metadata header;
1652+
# add these here.
1653+
metadata = tuple(metadata) + (
1654+
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1655+
)
1656+
1657+
# Send the request.
1658+
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
1659+
1660+
# Wrap the response in an operation future.
1661+
response = operation_async.from_gapic(
1662+
response,
1663+
self._client._transport.operations_client,
1664+
backup.Backup,
1665+
metadata_type=backup.CopyBackupMetadata,
1666+
)
1667+
1668+
# Done; return the response.
1669+
return response
1670+
15091671
async def get_backup(
15101672
self,
15111673
request: Union[backup.GetBackupRequest, dict] = None,

google/cloud/spanner_admin_database_v1/services/database_admin/client.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,168 @@ def sample_create_backup():
17041704
# Done; return the response.
17051705
return response
17061706

1707+
def copy_backup(
1708+
self,
1709+
request: Union[backup.CopyBackupRequest, dict] = None,
1710+
*,
1711+
parent: str = None,
1712+
backup_id: str = None,
1713+
source_backup: str = None,
1714+
expire_time: timestamp_pb2.Timestamp = None,
1715+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1716+
timeout: float = None,
1717+
metadata: Sequence[Tuple[str, str]] = (),
1718+
) -> operation.Operation:
1719+
r"""Starts copying a Cloud Spanner Backup. The returned backup
1720+
[long-running operation][google.longrunning.Operation] will have
1721+
a name of the format
1722+
``projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>``
1723+
and can be used to track copying of the backup. The operation is
1724+
associated with the destination backup. The
1725+
[metadata][google.longrunning.Operation.metadata] field type is
1726+
[CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata].
1727+
The [response][google.longrunning.Operation.response] field type
1728+
is [Backup][google.spanner.admin.database.v1.Backup], if
1729+
successful. Cancelling the returned operation will stop the
1730+
copying and delete the backup. Concurrent CopyBackup requests
1731+
can run on the same source backup.
1732+
1733+
1734+
.. code-block:: python
1735+
1736+
from google.cloud import spanner_admin_database_v1
1737+
1738+
def sample_copy_backup():
1739+
# Create a client
1740+
client = spanner_admin_database_v1.DatabaseAdminClient()
1741+
1742+
# Initialize request argument(s)
1743+
request = spanner_admin_database_v1.CopyBackupRequest(
1744+
parent="parent_value",
1745+
backup_id="backup_id_value",
1746+
source_backup="source_backup_value",
1747+
)
1748+
1749+
# Make the request
1750+
operation = client.copy_backup(request=request)
1751+
1752+
print("Waiting for operation to complete...")
1753+
1754+
response = operation.result()
1755+
1756+
# Handle the response
1757+
print(response)
1758+
1759+
Args:
1760+
request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]):
1761+
The request object. The request for
1762+
[CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup].
1763+
parent (str):
1764+
Required. The name of the destination instance that will
1765+
contain the backup copy. Values are of the form:
1766+
``projects/<project>/instances/<instance>``.
1767+
1768+
This corresponds to the ``parent`` field
1769+
on the ``request`` instance; if ``request`` is provided, this
1770+
should not be set.
1771+
backup_id (str):
1772+
Required. The id of the backup copy. The ``backup_id``
1773+
appended to ``parent`` forms the full backup_uri of the
1774+
form
1775+
``projects/<project>/instances/<instance>/backups/<backup>``.
1776+
1777+
This corresponds to the ``backup_id`` field
1778+
on the ``request`` instance; if ``request`` is provided, this
1779+
should not be set.
1780+
source_backup (str):
1781+
Required. The source backup to be copied. The source
1782+
backup needs to be in READY state for it to be copied.
1783+
Once CopyBackup is in progress, the source backup cannot
1784+
be deleted or cleaned up on expiration until CopyBackup
1785+
is finished. Values are of the form:
1786+
``projects/<project>/instances/<instance>/backups/<backup>``.
1787+
1788+
This corresponds to the ``source_backup`` field
1789+
on the ``request`` instance; if ``request`` is provided, this
1790+
should not be set.
1791+
expire_time (google.protobuf.timestamp_pb2.Timestamp):
1792+
Required. The expiration time of the backup in
1793+
microsecond granularity. The expiration time must be at
1794+
least 6 hours and at most 366 days from the
1795+
``create_time`` of the source backup. Once the
1796+
``expire_time`` has passed, the backup is eligible to be
1797+
automatically deleted by Cloud Spanner to free the
1798+
resources used by the backup.
1799+
1800+
This corresponds to the ``expire_time`` field
1801+
on the ``request`` instance; if ``request`` is provided, this
1802+
should not be set.
1803+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
1804+
should be retried.
1805+
timeout (float): The timeout for this request.
1806+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1807+
sent along with the request as metadata.
1808+
1809+
Returns:
1810+
google.api_core.operation.Operation:
1811+
An object representing a long-running operation.
1812+
1813+
The result type for the operation will be
1814+
:class:`google.cloud.spanner_admin_database_v1.types.Backup`
1815+
A backup of a Cloud Spanner database.
1816+
1817+
"""
1818+
# Create or coerce a protobuf request object.
1819+
# Quick check: If we got a request object, we should *not* have
1820+
# gotten any keyword arguments that map to the request.
1821+
has_flattened_params = any([parent, backup_id, source_backup, expire_time])
1822+
if request is not None and has_flattened_params:
1823+
raise ValueError(
1824+
"If the `request` argument is set, then none of "
1825+
"the individual field arguments should be set."
1826+
)
1827+
1828+
# Minor optimization to avoid making a copy if the user passes
1829+
# in a backup.CopyBackupRequest.
1830+
# There's no risk of modifying the input as we've already verified
1831+
# there are no flattened fields.
1832+
if not isinstance(request, backup.CopyBackupRequest):
1833+
request = backup.CopyBackupRequest(request)
1834+
# If we have keyword arguments corresponding to fields on the
1835+
# request, apply these.
1836+
if parent is not None:
1837+
request.parent = parent
1838+
if backup_id is not None:
1839+
request.backup_id = backup_id
1840+
if source_backup is not None:
1841+
request.source_backup = source_backup
1842+
if expire_time is not None:
1843+
request.expire_time = expire_time
1844+
1845+
# Wrap the RPC method; this adds retry and timeout information,
1846+
# and friendly error handling.
1847+
rpc = self._transport._wrapped_methods[self._transport.copy_backup]
1848+
1849+
# Certain fields should be provided within the metadata header;
1850+
# add these here.
1851+
metadata = tuple(metadata) + (
1852+
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
1853+
)
1854+
1855+
# Send the request.
1856+
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
1857+
1858+
# Wrap the response in an operation future.
1859+
response = operation.from_gapic(
1860+
response,
1861+
self._transport.operations_client,
1862+
backup.Backup,
1863+
metadata_type=backup.CopyBackupMetadata,
1864+
)
1865+
1866+
# Done; return the response.
1867+
return response
1868+
17071869
def get_backup(
17081870
self,
17091871
request: Union[backup.GetBackupRequest, dict] = None,

0 commit comments

Comments
 (0)