• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
database table backup and duplicate

#1
Hello

Is there a solution for duplicate a table from a database to an other and for backup a database in codeigniter 4
Reply

#2
@paul,

The short answer is no. CI does however give you the ability to create/integrate libraries or plugins that can do that for you. Check the forums to see if anyone has such a solution. Please keep in mind that CI4 is basically relatively a new version.
Reply

#3
@paul

I have created a command for that. I decide to use this package. Maybe it will be helpful for you:


PHP Code:
<?php namespace Bundles\Core\Backup\Commands;

use \
CodeIgniter\CLI\BaseCommand;
use \
CodeIgniter\CLI\CLI;

class 
DatabaseBackupCommand extends BaseCommand
{
    /**
     * The group the command is lumped under
     * when listing commands.
     *
     * @var string
     */
    protected $group 'Core';

    /**
     * The Command's name
     *
     * @var string
     */
    protected $name 'core:backup:database';

    /**
     * The Command's short description
     *
     * @var string
     */
    protected $description 'Dump the contents of a database';

    /**
     * The Command's usage
     *
     * @var string
     */
    protected $usage 'core:backup:database';

    /**
     * The Command's Arguments
     *
     * @var array
     */
    protected $arguments = [];

    /**
     * The Command's Options
     *
     * @var array
     */
    protected $options = [];

    public function run(array $params)
    {
        // Get benchmark tool
        $benchmark = \Config\Services::timer();
        $benchmark->start('core:database:backup');

        // Get database configuration
        $config = new \Config\Database;

        // The name of the directory where we need to save backup.
        $directoryName WRITEPATH 'backup/database';

        // Check if the directory already exists.
        if(!is_dir($directoryName))
        {
            // Directory does not exist, so lets create it.
            mkdir($directoryName0755true);
        }

        \Spatie\DbDumper\Databases\MySql::create()
            ->setDbName($config->default['database'])
            ->setUserName($config->default['username'])
            ->setPassword($config->default['password'])
            ->addExtraOption('--host ' $config->default['hostname'])
            ->dumpToFile(sprintf('%s/%s-%s.sql'$directoryName$config->default['database'], date('d-m-Y-H:i')));

        $benchmark->stop('core:database:backup');

        // Show command execution details
        CLI::write('Total execution time: 'CLI::color($benchmark->getElapsedTime('core:database:backup'), 'yellow'));
    }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.