Skip to content

Commit 52d657c

Browse files
Add some docs
1 parent 83eb95f commit 52d657c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

docs/pages/.vitepress/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export default defineConfig({
3232
{ text: "Metadata", link: "/metadata.md" },
3333
],
3434
},
35+
{
36+
text: "Advanced",
37+
items: [{ text: "Naming backups", link: "/naming-backups.md" }],
38+
},
3539
],
3640

3741
search: {

docs/pages/naming-backups.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Naming backups
2+
3+
If you want to customize how backups are named and "discovered", you can!
4+
5+
The default naming scheme will be:
6+
7+
```
8+
{app.name}-{timestamp}-{id}.zip
9+
```
10+
11+
## Customizing
12+
13+
You can customize the naming by providing your own `BackupNameResolver` implementation.
14+
15+
This class is responsible for generating filenames and parsing files into identifiable information and required metadata in the form of `ResolvedBackupData`.
16+
So when making your own implementation, you need to make sure that your generate and parseFilename methods work togheter or it will not work.
17+
18+
Here is an example of a custom `BackupNameResolver` implementation:
19+
20+
```php
21+
use Carbon\CarbonImmutable;
22+
use Itiden\Backup\Contracts\BackupNameResolver;
23+
use Itiden\Backup\DataTransferObjects\ResolvedBackupData;
24+
25+
final readonly class MyAppSpecificBackupNameResolver implements BackupNameResolver
26+
{
27+
private const string Separator = '---';
28+
29+
// return a custom filename, the ".zip" extension will be added automatically if it is missing
30+
public function generateFilename(CarbonImmutable $createdAt, string $id): string
31+
{
32+
$parts = [
33+
"some-testest-that-implies-something",
34+
$createdAt->format('Y-m-d'),
35+
$id,
36+
];
37+
38+
return implode(self::Separator, $parts);
39+
}
40+
41+
public function parseFilename(string $path): ?ResolvedBackupData
42+
{
43+
$filename = pathinfo($path, PATHINFO_FILENAME);
44+
45+
$parts = explode(self::Separator, $filename);
46+
47+
// if the filename cannot be parsed, return null
48+
if (count($parts) !== 3) {
49+
return null;
50+
}
51+
52+
[$name, $date, $identifier] = $parts;
53+
54+
$createdAt = CarbonImmutable::createFromFormat('Y-m-d', $date);
55+
56+
return new ResolvedBackupData(
57+
createdAt: $createdAt,
58+
id: $identifier,
59+
name: $name
60+
);
61+
}
62+
}
63+
```

0 commit comments

Comments
 (0)