@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Recommend dumping database backups with "--compress --output X" instead of "| gzip > X"

Summary:
Fixes T13304. Shell pipes and redirects do not have robust behavior when errors occur. We provide "--compress" and "--output" flags as robust alternatives, but do not currently recommend their use.

- Recommend their use, since their error handling behavior is more robust in the face of issues like full disks.
- If "--compress" is provided but won't work because the "zlib" extension is missing, raise an explicit error. I believe this extension is very common and this error should be rare. If that turns out to be untrue, we could take another look at this.
- Also, verify some flag usage sooner so we can exit with an error faster if you mistype a "bin/storage dump" command.

Test Plan: Read documentation, hit affected error cases, did a dump and spot-checked that it came out sane looking.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13304

Differential Revision: https://secure.phabricator.com/D20572

+46 -43
+1 -1
src/docs/user/configuration/configuring_backups.diviner
··· 42 42 Since most of this data is compressible, it may be helpful to run it through 43 43 gzip prior to storage. For example: 44 44 45 - phabricator/ $ ./bin/storage dump | gzip > backup.sql.gz 45 + phabricator/ $ ./bin/storage dump --compress --output backup.sql.gz 46 46 47 47 Then store the backup somewhere safe, like in a box buried under an old tree 48 48 stump. No one will ever think to look for it there.
+45 -42
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php
··· 51 51 } 52 52 53 53 public function didExecute(PhutilArgumentParser $args) { 54 + $output_file = $args->getArg('output'); 55 + $is_compress = $args->getArg('compress'); 56 + $is_overwrite = $args->getArg('overwrite'); 57 + 58 + if ($is_compress) { 59 + if ($output_file === null) { 60 + throw new PhutilArgumentUsageException( 61 + pht( 62 + 'The "--compress" flag can only be used alongside "--output".')); 63 + } 64 + 65 + if (!function_exists('gzopen')) { 66 + throw new PhutilArgumentUsageException( 67 + pht( 68 + 'The "--compress" flag requires the PHP "zlib" extension, but '. 69 + 'that extension is not available. Install the extension or '. 70 + 'omit the "--compress" option.')); 71 + } 72 + } 73 + 74 + if ($is_overwrite) { 75 + if ($output_file === null) { 76 + throw new PhutilArgumentUsageException( 77 + pht( 78 + 'The "--overwrite" flag can only be used alongside "--output".')); 79 + } 80 + } 81 + 82 + if ($output_file !== null) { 83 + if (Filesystem::pathExists($output_file)) { 84 + if (!$is_overwrite) { 85 + throw new PhutilArgumentUsageException( 86 + pht( 87 + 'Output file "%s" already exists. Use "--overwrite" '. 88 + 'to overwrite.', 89 + $output_file)); 90 + } 91 + } 92 + } 93 + 54 94 $api = $this->getSingleAPI(); 55 95 $patches = $this->getPatches(); 56 - 57 - $console = PhutilConsole::getConsole(); 58 96 59 97 $with_indexes = !$args->getArg('no-indexes'); 60 98 61 99 $applied = $api->getAppliedPatches(); 62 100 if ($applied === null) { 63 - $namespace = $api->getNamespace(); 64 - $console->writeErr( 101 + throw new PhutilArgumentUsageException( 65 102 pht( 66 - '**Storage Not Initialized**: There is no database storage '. 67 - 'initialized in this storage namespace ("%s"). Use '. 68 - '**%s** to initialize storage.', 69 - $namespace, 70 - './bin/storage upgrade')); 71 - return 1; 103 + 'There is no database storage initialized in the current storage '. 104 + 'namespace ("%s"). Use "bin/storage upgrade" to initialize '. 105 + 'storage or use "--namespace" to choose a different namespace.', 106 + $api->getNamespace())); 72 107 } 73 108 74 109 $ref = $api->getRef(); ··· 138 173 if ($password) { 139 174 if (strlen($password->openEnvelope())) { 140 175 $has_password = true; 141 - } 142 - } 143 - 144 - $output_file = $args->getArg('output'); 145 - $is_compress = $args->getArg('compress'); 146 - $is_overwrite = $args->getArg('overwrite'); 147 - 148 - if ($is_compress) { 149 - if ($output_file === null) { 150 - throw new PhutilArgumentUsageException( 151 - pht( 152 - 'The "--compress" flag can only be used alongside "--output".')); 153 - } 154 - } 155 - 156 - if ($is_overwrite) { 157 - if ($output_file === null) { 158 - throw new PhutilArgumentUsageException( 159 - pht( 160 - 'The "--overwrite" flag can only be used alongside "--output".')); 161 - } 162 - } 163 - 164 - if ($output_file !== null) { 165 - if (Filesystem::pathExists($output_file)) { 166 - if (!$is_overwrite) { 167 - throw new PhutilArgumentUsageException( 168 - pht( 169 - 'Output file "%s" already exists. Use "--overwrite" '. 170 - 'to overwrite.', 171 - $output_file)); 172 - } 173 176 } 174 177 } 175 178