Reputation: 99
Hi I am new to Laravel.
In our project ,we have to clone the current database into same server with different name.For example if our current database name is "test" means , I have to clone the database(test) into same server with different name like "test_2018" and I need all the tables in database(test) to our clone database(test_2018).
How can I achieve this in Laravel programmatically and I have used laravel version 5.0.
Upvotes: 9
Views: 2679
Reputation: 1864
I'm assuming you're using a MySql database.
You can create a batch file, then calling the file using the task scheduler in Laravel.
inside your Laravel project in the App\Console\Kernel.php
file, add this line to the schedule function to run the command every year.
protected function schedule(Schedule $schedule)
{
$schedule->exec('/batch.bat')->yearly();
}
You need to create a scheduled task using the task scheduler if you have Windows, and if you have Linux (90% you have Linux especially if your project is running on the hosting server), then you should create a CRON job and place this script inside your script(according to Laravel documentation):
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Then create a batch.bat(Windows) or batch.sh(Linux) file inside your project folder, and place this content inside it:
mysql -u [USER-NAME] -p[PASSWORD] [YOUR-CURRENT-DATABASE-NAME] > /dumpfile.sql
CREATE DATABASE [NEW-DATABASE-NAME];
[NEW-DATABASE-NAME] < /dumpfile.sql
Don't wait and test it manually right away using the command:
php artisan schedule:run
Upvotes: 2