Backup your MySQL database from php

 
 
  • Gérald Barré

Here is a PHP script to save a database in a gzip archive.

PHP
<?php
  // change the following values
  $host= '';
  $user= '';
  $pass= '';
  $db=   '';
  $d=    date('Y-m-d-H-i');

  $backup_folder= 'backup';

  system(sprintf(
    'mysqldump --opt -h%s -u%s -p"%s" %s | gzip > %s/db-%s.sql.gz',
    $host,
    $user,
    $pass,
    $db,
    $backup_folder,
    $d
  ));
?>

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub