Backup your MySQL database from php

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

<?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
  ));
?>
Enjoy this blog? Buy Me A Coffee Donate with PayPal

Leave a reply