10
10
11
11
Backup single or multiple database tables with ease.
12
12
13
- > Note: if you want a full database backup with many features go for [ Spatie Laravel Backup] ( https://github.com/spatie/laravel-backup ) .
13
+ > [ !NOTE]
14
+ > If you want a full database backup with many features, go
15
+ > for [ Spatie Laravel Backup] ( https://github.com/spatie/laravel-backup ) .
14
16
15
17
## Installation
16
18
@@ -26,6 +28,9 @@ Use the `BackupTables::generateBackup($tableToBackup)` Facade anywhere in your a
26
28
generate ` $tableToBackup_backup_2024_08_22_17_40_01 ` table in the database with all the data and structure. Note that
27
29
the datetime ` 2024_08_22_17_40_01 ` will be varied based on your datetime.
28
30
31
+ You can also use the ` php artisan backup:tables <targets> ` command to back up tables,
32
+ where ` <targets> ` is a space-separated list of table names or models.
33
+
29
34
``` php
30
35
use WatheqAlshowaiter\BackupTables\BackupTables; // import the facade
31
36
@@ -35,14 +40,14 @@ class ChangeSomeData
35
40
{
36
41
BackupTables::generateBackup('users'); // will result: users_backup_2024_08_22_17_40_01
37
42
38
- // change some data..
43
+ // change some data..
39
44
}
40
45
}
41
46
```
42
47
43
48
And More Customizations
44
49
45
- - You can use an array to backup more than one table
50
+ - You can use an array to back up more than one table
46
51
47
52
``` php
48
53
BackupTables::generateBackup(['users', 'posts']);
@@ -55,7 +60,8 @@ BackupTables::generateBackup(['users', 'posts']);
55
60
``` php
56
61
BackupTables::generateBackup(User::class); // users_backup_2024_08_22_17_40_01
57
62
// or
58
- BackupTables::generateBackup([User::class, Post::class]); // users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01
63
+ BackupTables::generateBackup([User::class, Post::class]); //-php artisan backup:tables users posts # users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01
64
+ users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01
59
65
60
66
```
61
67
@@ -65,25 +71,38 @@ BackupTables::generateBackup([User::class, Post::class]); // users_backup_2024_0
65
71
BackupTables::generateBackup('users', 'Y_d_m_H_i'); // users_backup_2024_22_08_17_40
66
72
```
67
73
68
- > * Note: be aware if you customize the datetime to wide datetime the package will check the backup datetime file and
69
- > will be skipped
70
- > the exact same datetime, so most of the time the default will be fine
71
- > For example: if you use this ` Y_d_m_H ` you can not generate the same backup in the same hour
74
+ > [ !WARNING ]
75
+ > When customizing the datetime format, be aware that backups with identical datetime values will be skipped.
76
+ > For example, if you use this ` Y_d_m_H ` you cannot generate the same backup in the same hour.
77
+ > The default format (Y_m_d_H_i_s) is recommended for most cases.
72
78
73
79
``` php
74
80
BackupTables::generateBackup('users', 'Y_d_m_H'); // can not generate the same backup in the same hour
75
81
BackupTables::generateBackup('users', 'Y_d_m'); // can not generate the same backup in the same day
76
82
```
77
83
84
+ - Using the artisan command for one or more tables/models
85
+
86
+ ``` bash
87
+ php artisan backup:tables users posts # users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01
88
+ php artisan backup:tables \\ App\\ Models\\ User \\ App\\ Models\\ Post # users_backup_2024_08_22_17_40_01, posts_backup_2024_08_22_17_40_01
89
+ ```
90
+
78
91
## Why?
79
92
80
- Sometimes you want to backup some database tables before changing data for whatever reason, this package serves this
81
- need. I used it personally before adding foreign keys for tables that required the removal of unlinked fields for parent tables.
82
- You may find some situation where you play with table data or you're afraid of missing data so you backup these tables
93
+ Sometimes you want to back up some database tables before changing data for whatever reason, this package serves this
94
+ need.
95
+
96
+ I used it personally before adding foreign keys to tables that required removing unlinked fields from parent tables.
97
+
98
+ You may find some situation where you play with table data, or you're afraid of missing data, so you back up these
99
+ tables
83
100
beforehand.
84
101
85
102
## Features
86
103
104
+ ✅ Backup tables from the code using (Facade) or from the console command.
105
+
87
106
✅ Supports Laravel versions: 11, 10, 9, 8, 7, and 6.
88
107
89
108
✅ Supports PHP versions: 8.2, 8.1, 8.0, and 7.4.
@@ -102,11 +121,15 @@ composer test
102
121
103
122
## Changelog
104
123
105
- Please see [ CHANGELOG] ( CHANGELOG.md ) for more information on what has changed recently .
124
+ Please see [ CHANGELOG] ( CHANGELOG.md ) for more information on recent changes .
106
125
107
126
## Contributing
108
127
109
- If you have any ideas or suggestions to improve it or fix bugs, your contribution is welcome. I encourage you to look at [ todos] ( ./todos.md ) which are the most important features that need to be added. If you have something different, submit an issue first to discuss or report a bug, then do a pull request.
128
+ If you have any ideas or suggestions to improve it or fix bugs, your contribution is welcome.
129
+
130
+ I encourage you to look at [ todos] ( ./todos.md ) which are the most important features that need to be added.
131
+
132
+ If you have something different, submit an issue first to discuss or report a bug, then do a pull request.
110
133
111
134
## Security Vulnerabilities
112
135
@@ -118,11 +141,9 @@ them.
118
141
- [ Watheq Alshowaiter] ( https://github.com/WatheqAlshowaiter )
119
142
- [ Omar Alalwi] ( https://github.com/omaralalwi ) - This package is based on his initial code.
120
143
- [ All Contributors] ( ../../contributors )
121
-
122
144
123
145
And a special thanks to [ The King Creative] ( https://www.facebook.com/thkingcreative ) for the logo ✨
124
146
125
-
126
147
## License
127
148
128
149
The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information.
0 commit comments