Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion libcloudforensics/providers/gcp/forensics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import random
import re
import subprocess
import time
from typing import List, Tuple, Optional, Dict, Any, Union, Sequence

from google.auth.exceptions import DefaultCredentialsError
Expand Down Expand Up @@ -90,7 +91,22 @@ def CreateDiskCopy(
disk_type = 'pd-standard'

logger.info('Disk copy of {0:s} started...'.format(disk_to_copy.name))
snapshot, created = disk_to_copy.Snapshot()

attempts = 0
max_attempts = 5
backoff = 1
while attempts < max_attempts:
try:
attempts += 1
snapshot, created = disk_to_copy.Snapshot()
break
except RuntimeError as exception:
if 'RESOURCE_OPERATION_RATE_EXCEEDED' not in str(exception) or attempts >= max_attempts:
raise exception
logger.debug('Snapshot creation throttled: Pausing {0:d} seconds'.format(backoff))
time.sleep(backoff)
backoff ** 2

logger.debug('Snapshot created: {0:s}'.format(snapshot.name))
new_disk = dst_project.compute.CreateDiskFromSnapshot(
snapshot, disk_name_prefix='evidence', disk_type=disk_type)
Expand Down
Loading