We're doing some real stupid garbage in the Phacility deployment scripts right now to get a safe database dump:
// NOTE: We're using `set -o pipefail` so this command fails if any // part (in particular, the `bin/storage dump`) fails. This is specific // to bash and the default shell is dash under Ubuntu, so we need to // invoke bash explicitly. $command = csprintf( 'set -o pipefail && PHACILITY_INSTANCE=%s %s dump | gzip > %s', $instance, $this->getPath('lib/phabricator/bin/storage'), $database_path); $t_start = microtime(true); try { execx('/bin/bash -c %s', $command); } catch (CommandException $ex) { try { // Try to remove the possibly-empty but certainly-invalid file, if // it exists. Filesystem::remove($database_path); } catch (Exception $ex) { // If anything went wrong, ignore the cleanup failure; we just want // to raise the root cause. } throw $ex; } $t_end = microtime(true);
This would be enormously cleaner (and more portable) as:
bin/storage dump --gzip --outfile <filename>
One tricky bit is that we should ideally handle this in a stream-oriented way -- not by buffering the entire dump into memory, gzipping it, and then writing it to disk. This may be a little tricky to do safely since I don't think we do anything similar elsewhere yet.