You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/naming-backups.md
+56-15Lines changed: 56 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,51 @@
1
1
# Naming backups
2
2
3
-
If you want to customize how backups are named and "discovered", you can!
3
+
Sometimes you need to customize the naming of your backupfiles, maybe you download them often and want to have "prettier" names for them, or maybe you want to have a specific naming scheme for your backups due to some other reason.
4
+
This package provides a way to customize the naming of your backup files.
4
5
5
-
The default naming scheme will be:
6
+
You can customize the naming by providing your own `BackupNameResolver` implementation, [Read more](#making-your-own-implementation).
7
+
8
+
## Default naming scheme
9
+
10
+
The default driver for naming backups is `Itiden\Backup\GenericBackupNameResolver`, which will generate filenames like this:
6
11
7
12
```
8
-
{app.name}-{timestamp}-{id}.zip
13
+
{app.name}---{timestamp}---{id}.zip
9
14
```
10
15
11
-
## Customizing
16
+
The reason for this format is that it is easy to parse and it contains all the information you need to identify the backup.
17
+
18
+
> [!INFO]
19
+
> When you upload a backup, it will be renamed with with the naming scheme of the driver you are using.
20
+
21
+
## The inner workings
22
+
23
+
### `generateFilename`
12
24
13
-
You can customize the naming by providing your own `BackupNameResolver` implementation.
25
+
Will be provided with a `CarbonImmutable` and a `string` identifier (ulid), the returned string can be a path and the `zip` extension will be appended if it isn't there already.
14
26
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.
27
+
> [!CAUTION]
28
+
> The provided identifier MUST be included in the filename since it will be used to find the backup after creation.
29
+
30
+
### `parseFilename`
31
+
32
+
Will be provided with storages path to the file, this path is relative to the configured backup location, so it will look something like this:
> If you only want to parse the filename, you can use `pathinfo($path, PATHINFO_FILENAME)` to get the filename.
40
+
41
+
It should return a `ResolvedBackupData` dto with the must-have information about the backup, or null if the data couldn't be resolved and the path should be ignored.
42
+
43
+
## Making your own implementation
44
+
45
+
When making your own `BackupNameResolver` implementation, it is important that your `generateFilename` and `parseFilename` methods work togheter or your backups might become undiscoverable.
46
+
47
+
> [!TIP]
48
+
> The `parseFilename` method will be provided a "relative" path for each file in the configured backup location, so you can save and resolve backups in subdirectories!
17
49
18
50
Here is an example of a custom `BackupNameResolver` implementation:
19
51
@@ -26,37 +58,46 @@ final readonly class MyAppSpecificBackupNameResolver implements BackupNameResolv
0 commit comments