MCPcopy Create free account
hub / github.com/wal-e/wal-e / database_fetch

Method database_fetch

wal_e/operator/backup.py:71–156  ·  view source on GitHub ↗
(self, pg_cluster_dir, backup_name,
                       blind_restore, restore_spec, pool_size)

Source from the content-addressed store, hash-verified

69 sys.stdout.flush()
70
71 def database_fetch(self, pg_cluster_dir, backup_name,
72 blind_restore, restore_spec, pool_size):
73 if os.path.exists(os.path.join(pg_cluster_dir, 'postmaster.pid')):
74 hint = ('Shut down postgres. If there is a stale lockfile, '
75 'then remove it after being very sure postgres is not '
76 'running.')
77 raise UserException(
78 msg='attempting to overwrite a live data directory',
79 detail='Found a postmaster.pid lockfile, and aborting',
80 hint=hint)
81
82 bl = self._backup_list(False)
83 backups = list(bl.find_all(backup_name))
84
85 assert len(backups) <= 1
86 if len(backups) == 0:
87 raise UserException(
88 msg='no backups found for fetching',
89 detail=('No backup matching the query {0} '
90 'was able to be located.'.format(backup_name)))
91 elif len(backups) > 1:
92 raise UserException(
93 msg='more than one backup found for fetching',
94 detail=('More than one backup matching the query {0} was able '
95 'to be located.'.format(backup_name)),
96 hint='To list qualifying backups, '
97 'try "wal-e backup-list QUERY".')
98
99 # There must be exactly one qualifying backup at this point.
100 assert len(backups) == 1
101 assert backups[0] is not None
102
103 backup_info = backups[0]
104 backup_info.load_detail(self.new_connection())
105 self.layout.basebackup_tar_partition_directory(backup_info)
106
107 if restore_spec is not None:
108 if restore_spec != 'SOURCE':
109 if not os.path.isfile(restore_spec):
110 raise UserException(
111 msg='Restore specification does not exist',
112 detail='File not found: %s'.format(restore_spec),
113 hint=('Provide valid json-formatted restoration '
114 'specification, or pseudo-name "SOURCE" to '
115 'restore using the specification from the '
116 'backup progenitor.'))
117 with open(restore_spec, 'r') as fs:
118 spec = json.load(fs)
119 backup_info.spec.update(spec)
120 if 'base_prefix' not in backup_info.spec \
121 or not backup_info.spec['base_prefix']:
122 backup_info.spec['base_prefix'] = pg_cluster_dir
123 self._build_restore_paths(backup_info.spec)
124 else:
125 # If the user hasn't passed in a restoration specification
126 # use pg_cluster_dir as the resore prefix
127 backup_info.spec['base_prefix'] = pg_cluster_dir
128

Callers 1

mainFunction · 0.80

Calls 11

_backup_listMethod · 0.95
new_connectionMethod · 0.95
_build_restore_pathsMethod · 0.95
_verify_restore_pathsMethod · 0.95
UserExceptionClass · 0.90
find_allMethod · 0.80
formatMethod · 0.80
joinMethod · 0.45
load_detailMethod · 0.45

Tested by

no test coverage detected