如何使用 cronjob 备份 MySQL 数据库 laravel 4.2
How to backup MySQL Database laravel 4.2 with cronjob
我有一个项目laravel 4.2,现在我会每周自动备份数据库。
我找到了脚本,但它不起作用
public function fire()
{
try {
$this->process = new Process(sprintf(
'mysqldump -u%s -p%s %s > %s',
config('database.connections.mysql.username'),
config('database.connections.mysql.password'),
config('database.connections.mysql.database'),
storage_path('backups/backup.sql')
));
$this->info('The backup has been proceed successfully.');
} catch (ProcessFailedException $exception) {
$this->error('The backup process has been failed.');
}
}
protected function getArguments()
{
return array();
}
显示错误
PHP Fatal error: Call to undefined function config() in /var/www/html/guitarni_portal/app/commands/BackupDatabase.php on line 25
Error in exception handler: The stream or file "/var/www/html/guitarni_portal/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/guitarni_portal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
您使用的太旧 laravel。但是,您仍然可以使用,
Config::get
而不是 config
.
应该可以。
我有一个项目laravel 4.2,现在我会每周自动备份数据库。
我找到了脚本,但它不起作用
public function fire()
{
try {
$this->process = new Process(sprintf(
'mysqldump -u%s -p%s %s > %s',
config('database.connections.mysql.username'),
config('database.connections.mysql.password'),
config('database.connections.mysql.database'),
storage_path('backups/backup.sql')
));
$this->info('The backup has been proceed successfully.');
} catch (ProcessFailedException $exception) {
$this->error('The backup process has been failed.');
}
}
protected function getArguments()
{
return array();
}
显示错误
PHP Fatal error: Call to undefined function config() in /var/www/html/guitarni_portal/app/commands/BackupDatabase.php on line 25 Error in exception handler: The stream or file "/var/www/html/guitarni_portal/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/guitarni_portal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
您使用的太旧 laravel。但是,您仍然可以使用,
Config::get
而不是 config
.
应该可以。