The crontab command automatically backs up the mysql database of the remote server, crontabmysql

Source: Internet
Author: User

The crontab command automatically backs up the mysql database of the remote server, crontabmysql

Today, I used the information collected on the Internet and my own practices to organize and use the crontab command to back up a database on a remote server, hoping to be useful to everyone.


The procedure is as follows:

1. Open Putty, enter the password here, and enter:


2. create and save the backup file path/mysqldata: Enter the following information in the green area of the second figure above. After creating the file, you can see the mysqldata folder in the root directory (in the same directory as var and usr)

# Mkdir/mysqldata

3. Create the/usr/sbin/bakmysql file.

# Vi/usr/sbin/bakmysql

Input

Rq = 'date + % Y % m % d'

Tar zcvf/mysqldata/mysql1_rq.tar.gz/var/lib/mysql

Or write it

Rq = 'date + % Y % m % d'

Mysqldump -- all-databases-u root-p password>/mysqldata/mysql $ rq. SQL

/Var/lib/mysql is the directory of your database files. Some users are/usr/local/mysql/data.

/Mysqldata/indicates the directory where the backup file is saved. This can be done according to your requirements.

Note: You can view the bakmysql file in the/usr/sbin/directory. After creating bakmysql, you can copy the content you want to input to bakmysql.

4. Modify the file attributes to make them executable:

# Chmod + x/usr/sbin/bakmysql


5. Modify/etc/crontab

Input # vi/etc/crontab

After entering the preceding command, you can see the following interface:


Add a field in the red box (for how to add it, see my blog crontab and regularly execute php)

10 1 *** root/usr/sbin/bakmysql

Indicates that a backup is performed at 01:10 every day.


6. Restart crond.

#/Etc/rc. d/init. d/crond restart



How does one automatically back up mysql databases on the remote server every day?

Use the mysqldump command.
 
How does mysql automatically back up databases?

Windows:
Specifically, if you need to use the task scheduler to run automatically, perform the following steps:

1. click Start, select "program"> "attachment"> "System Tools"> "task plan" (or "set"> "Control Panel"> "Task Plan "), start the task scheduler Management Program for Windows 2000.

2. in the "Task Scheduler" window, double-click the "add Task Scheduler" icon to start the "Task Scheduler wizard" of the system, and then click the "Next" button, select the application to be automatically run in the program list, and click "Next.
Set the appropriate task plan name and select the time frequency for Automatic Execution of the task (such as daily, weekly, monthly, one-time, every start of the computer, and every login time ), click "Next.
At this time, the system will require the user to set the specific time for the program to run, such as the number, the number of minutes, and the time period to run. We only need to set the time according to our own needs.

4. The system will ask the user to set the appropriate user name and password (as shown in Figure 5) so that the system can run automatically in the future.

5. finally, you only need to click the "finish" button to add the corresponding task to the task scheduler in Windows 2000. Then it will automatically "remember" The task, once the system time and related conditions are consistent with the user-defined plan, it automatically calls the user-specified application, which is very convenient (every time Windows 2000 is started, the task scheduler will be automatically started and run in the background to ensure that your plans can be executed on time ).

Now let's test whether the task we just created is successful. Right-click the "php" program icon (6) and select "run" in the pop-up menu ". In general, the program icon can be started as long as it is activated and running. If the operation fails, check whether the user and password are correctly set, and check whether the "Task Scheduler" service has been started. I turned it off to save system resources, causing the operation to fail, I have been searching for it for a long time. In addition, you can view the cause of the failure in the system log.

Now we have discussed the application of such a multi-task plan. Here are two examples:

1. run PHP regularly!
1. Edit the following code and save it as test. php:
<? Php
$ Fp = @ fopen ("test.txt", "a + ");
Fwrite ($ fp, date ("Y-m-d H: I: s"). "Let PHP run regularly! \ N ");
Fclose ($ fp );
?>

2. Add a task scheduler. in step 2, enter the command D: \ php4 \ php.exe-q D: \ php4 \ test. php.

3. Set the time to run the task once every one minute and then run the task.

4. Now let's see if the content in the d: \ php4 \ test.txt file is successful. If the content is as follows, congratulations.

11:08:01 let PHP run on a regular basis!
11:09:02 let PHP run on a regular basis!
11:10:01 let PHP run on a regular basis!
...... The remaining full text>

Related Article

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.