Php backup mysql instance project_php tutorial

Source: Internet
Author: User
Back up mysql instance programs in php. We need to use the scheduled task function of the system to back up mysql in php. The following describes how to back up mysql instances in php in linux. # Back up all backup files to the specified directory. for example, to back up php to back up mysql, we need to use the scheduled task function of the system. next I will introduce how to back up mysql instances in php in linux.

# Back up all backup files to the specified directory, such as/backup/mysql_data_backup

The code is as follows:

Mkdir/backup/mysql_data_backup-p
Cd/backup/mysql_data_backup
Wget/backmysql.txt-O backmysql. php
Chmod + x backmysql. php
Crontab-e

Add a task line

The code is as follows:
0 13 ***/usr/bin/php/backup/mysql_data_backup/backmysql. php

Run the backup command in php at 00:13 every night.

The code is as follows:
#! /Usr/bin/php
<? Php

// Generate a storage directory
$ Path = dirname (_ FILE _). '/'. date ("Ym ");
$ Filename = sprintf ("% s/%s. SQL .gz", $ path, date ("YmdHis "));

If (! Is_dir ($ path ))
Mkdir ($ path );

// Export and compress all databases
$ Cmd = sprintf ("/usr/bin/mysqldump-uroot-ppassword -- all-databases |/bin/gzip> % s", $ filename );
Echo "backuping... n ";
'$ Cmd ';
Echo "backup done. n ";

Note: The plan information is processed here. if you want to execute the php file, you need to write one by yourself.

Bytes. # Back up all backup files to the specified directory, such as/backup /...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.