skcin7 / laravel-backups
用于管理 Laravel 项目中数据库备份的包。可轻松集成 Dropbox 和 AWS S3。
dev-master
2019-09-13 17:32 UTC
Requires
- php: >=5.4.0
- illuminate/support: 5.*
- spatie/flysystem-dropbox: ^1.0
This package is auto-updated.
Last update: 2024-09-14 04:43:55 UTC
README
用于管理 Laravel 项目中数据库备份的包。可轻松集成 Dropbox 和 AWS S3。
此包基于 wladmonax/laravel-db-backup,因此感谢他们的出色工作。
目录
安装
运行 Composer 命令: composer require skcin7/laravel-backups
配置
通过运行以下命令将配置文件复制到您的项目中:
php artisan vendor:publish
这将生成一个如下所示的配置文件
return [ // add a backup folder in the app/database/ or your dump folder 'path' => app_path() . '/database/backup/', // add the path to the restore and backup command of mysql // this exemple is if your are using MAMP server on a mac // on windows: 'C:\\...\\mysql\\bin\\' // on linux: '/usr/bin/' // trailing slash is required 'mysql' => [ 'dump_command_path' => '/Applications/MAMP/Library/bin/', 'restore_command_path' => '/Applications/MAMP/Library/bin/', ], // s3 settings 's3' => [ 'path' => 'your/s3/dump/folder' ] //dropbox settings 'dropbox' => [ 'accessToken' => DROPBOX_ACCESS_TOKEN, 'appSecret' => DROPBOX_APP_SECRET, 'prefix' => DROPBOX_PREFIX, //this is name of your dropbox folder ], //encrypt settings 'encrypt' => [ 'key' => ENCRYPT_KEY ], // Use GZIP compression 'compress' => false, ];
所有设置都是可选的,并具有合理的默认值。
用法
备份
在 app/storage/dumps
中创建一个转储文件
$ php artisan db:backup
使用特定数据库
$ php artisan db:backup --database=mysql
需要加密数据库
$ php artisan db:backup --encrypt
将转储保存到 Dropbox
$ php artisan db:backup --dropbox
您可以使用如下方式合并选项
$ php artisan db:backup --dropbox --encrypt
上传到 AWS S3
$ php artisan db:backup --upload-s3 your-bucket
如果您不想保留 SQL 转储的本地副本,可以使用 --keep-only-s3
选项。
使用 aws/aws-sdk-php-laravel 包,该包需要 配置。
使用 spatie/flysystem-dropbox 包。
恢复
路径相对于 app/storage/dumps 文件夹。
恢复转储
$ php artisan db:restore dump.sql
从最后的备份转储恢复
$ php artisan db:restore --last-dump
从 Dropbox 恢复
$ php artisan db:restore --dropbox-dump=filename.sql
从 Dropbox 最后的转储恢复
$ php artisan db:restore --dropbox-last-dump
列出转储
$ php artisan db:restore