Tahinli/forge
public0 watching
★ 0
| 1 | //! Backup sets (phase 1, see `docs/backup-interfaces.md`). |
| 2 | //! |
| 3 | //! A set is a directory `forge-backup-<UTC stamp>/` holding a consistent DB snapshot, one git |
| 4 | //! bundle per non-empty repo, optionally the instance key, and a `manifest.json` with a sha256 for |
| 5 | //! every file. It is written under a `.partial-…` name and renamed into place only when complete. |
| 6 | //! Nothing is written under `/tmp`: scratch repos live next to the output directory. |
| 7 | |
| 8 | |
| 9 | |
| 10 | pub |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | use ; |
| 17 | use Read; |
| 18 | use ; |
| 19 | use ; |
| 20 | |
| 21 | use ; |
| 22 | use GitEnv; |
| 23 | use ; |
| 24 | use ; |
| 25 | |
| 26 | pub use create_backup; |
| 27 | pub use ; |
| 28 | pub use restore_backup; |
| 29 | pub use Jobs; |
| 30 | pub use verify_backup; |
| 31 | |
| 32 | /// Manifest format version. Bump when the layout changes incompatibly. |
| 33 | pub const FORMAT_VERSION: u32 = 1; |
| 34 | pub const MANIFEST_FILE: &str = "manifest.json"; |
| 35 | pub const DB_FILE: &str = "db/forge.db"; |
| 36 | pub const KEY_FILE: &str = "keys/forge.key"; |
| 37 | const BACKUP_DIR_PREFIX: &str = "forge-backup-"; |
| 38 | const PARTIAL_PREFIX: &str = ".partial-"; |
| 39 | const COPY_BUF: usize = 64 * 1024; |
| 40 | |
| 41 | /// What a backup set contains. |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | /// Where a backup reads from. Cheap to build from the server state: `Store` and `GitEnv` clone. |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | /// Outcome of [`verify_backup`]. `problems` lists every failed check. The set is good only when it |
| 85 | /// is empty. |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | /// A wiki repo in a backup set: the same fields as a repo, with the bundle at `repos/<id>.wiki.bundle`. |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | /// Creates a directory with mode 0700. Fails if it already exists. |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | /// Creates `path` and missing parents with mode 0700. Existing directories are left alone. |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | /// Creates a new file with mode 0600 and writes `bytes` to it, then fsyncs it. |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | /// Streams the file through sha256. Returns its size and lowercase hex digest. |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | /// `20260102T030405Z`, the UTC stamp used in set names. |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | /// RFC 3339 UTC, used in the manifest. |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | /// A name that is unique within this process run, for partial and scratch paths. |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | /// Hex-encoded sha256 of zero bytes, the `refs_sha256` of an empty repo. |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | /// Whether `rel` is a file path a set may contain: the fixed names, or a bundle under `repos/` |
| 246 | /// (`<id>.bundle` for a repo, `<id>.wiki.bundle` for its wiki). |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | /// Sort key for files in the manifest: the path as text. |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 |