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

Method database_backup

wal_e/operator/backup.py:158–246  ·  view source on GitHub ↗

Uploads a PostgreSQL file cluster to S3 or Windows Azure Blob Service Mechanism: just wraps _upload_pg_cluster_dir with start/stop backup actions with exception handling. In particular there is a 'finally' block to stop the backup in most situations.

(self, data_directory, *args, **kwargs)

Source from the content-addressed store, hash-verified

156 p.join(raise_error=True)
157
158 def database_backup(self, data_directory, *args, **kwargs):
159 """Uploads a PostgreSQL file cluster to S3 or Windows Azure Blob
160 Service
161
162 Mechanism: just wraps _upload_pg_cluster_dir with
163 start/stop backup actions with exception handling.
164
165 In particular there is a 'finally' block to stop the backup in
166 most situations.
167 """
168 upload_good = False
169 backup_stop_good = False
170 while_offline = False
171 start_backup_info = None
172 if 'while_offline' in kwargs:
173 while_offline = kwargs.pop('while_offline')
174
175 try:
176 if not while_offline:
177 start_backup_info = PgBackupStatements.run_start_backup()
178 version = PgBackupStatements.pg_version()['version']
179 else:
180 if os.path.exists(os.path.join(data_directory,
181 'postmaster.pid')):
182 hint = ('Shut down postgres. '
183 'If there is a stale lockfile, '
184 'then remove it after being very sure postgres '
185 'is not running.')
186 raise UserException(
187 msg='while_offline set, but pg looks to be running',
188 detail='Found a postmaster.pid lockfile, and aborting',
189 hint=hint)
190
191 ctrl_data = PgControlDataParser(data_directory)
192 start_backup_info = ctrl_data.last_xlog_file_name_and_offset()
193 version = ctrl_data.pg_version()
194
195 ret_tuple = self._upload_pg_cluster_dir(
196 start_backup_info, data_directory, version=version, *args,
197 **kwargs)
198 spec, uploaded_to, expanded_size_bytes = ret_tuple
199 upload_good = True
200 finally:
201 if not upload_good:
202 logger.warning(
203 'blocking on sending WAL segments',
204 detail=('The backup was not completed successfully, '
205 'but we have to wait anyway. '
206 'See README: TODO about pg_cancel_backup'))
207
208 if not while_offline:
209 stop_backup_info = PgBackupStatements.run_stop_backup()
210 else:
211 stop_backup_info = start_backup_info
212 backup_stop_good = True
213
214 # XXX: Ugly, this is more of a 'worker' task because it might
215 # involve retries and error messages, something that is not

Callers 1

mainFunction · 0.80

Calls 12

pg_versionMethod · 0.95
UserExceptionClass · 0.90
PgControlDataParserClass · 0.90
uri_put_fileFunction · 0.90
UserCriticalClass · 0.90
warningMethod · 0.80
run_start_backupMethod · 0.45
pg_versionMethod · 0.45
joinMethod · 0.45
run_stop_backupMethod · 0.45

Tested by

no test coverage detected