dsfdsfdsfdsf1223 2018-06-12 11:32
浏览 56

使用php代码创建数据库到ftp服务器的自动备份

Needed to create automated backup of sql file to a ftp server.

Below mentioned code i am using for the same

    function backup_db()
    {
    ini_set('memory_limit','100G');
        ini_set('max_input_time', 3000000);  
        ini_set('max_execution_time', 3000000);
        error_reporting(E_ALL);
        ini_set('display_errors', 1);

        //echo 'here';exit;  
        $this->load->dbutil();
        $this->load->helper(array('file', 'download')); 

        $prefs = array(
                'tables'      => array(),   // Array of tables to backup.
                'ignore'      => array('general_ledger'),           // List of tables to omit from the backup
                'format'      => 'zip',             // gzip, zip, txt
                'filename'    => 'mybackup.sql',    // File name - NEEDED ONLY WITH ZIP FILES
                'add_drop'    => TRUE,              // Whether to add DROP TABLE statements to backup file
                'add_insert'  => TRUE,              // Whether to add INSERT data to backup file
                'newline'     => "
"               // Newline character used in backup file
              );


        //$this->db->save_queries = false;
        $backup = $this->dbutil->backup($prefs);
        //echo "in";exit();
        $filename = 'backup-' . date('d_m_Y_H_i_s') . ' .zip';

        write_file('/opt/backups/' . $filename, $backup);
        //force_download($filename, $backup); 



    try{
    $ftp_server = "xyz.xyz.xyz.xyz"; //server Ip
    $ftp_conn = ftp_connect($ftp_server);
    $ftp_username = "user";
    $ftp_userpass = "pass";

    $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

    // open file for reading
    $file = "/opt/backups/".$filename;
    $fp = fopen($file,"r");

    // upload file
    $success=ftp_fput($ftp_conn, "/Live_db_backups/Backup/$filename", $fp, FTP_ASCII);

    // close this connection and file handler
    ftp_close($ftp_conn);
    fclose($fp);
}catch (Exception $e) {
$this->session->set_flashdata('error',"FTP Error for Db backup File Download!!!!");
echo 'FTP Bachup Failed';
}

      echo 'here';  exit;
    }

What actually happening in this code is only half of the database backup is being stored.

Complete database backup is not getting saved to a file.

Tried with increasing ini_set('memory_limit','100G'); ini_set('max_input_time', 3000000);
ini_set('max_execution_time', 3000000)

But still only half of the db value is storing.

What may be the issue?.

Any help appreciated.

  • 写回答

1条回答 默认 最新

  • doucang6739 2018-06-12 11:47
    关注

    ftp_connect has a time out parameter you can set This is from the docs:

    timeout This parameter specifies the timeout in seconds for all subsequent network operations. If omitted, the default value is 90 seconds. The timeout can be changed and queried at any time with ftp_set_option() and ftp_get_option().

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?