A Linux server scheduled backup
The first step is to create a new *.sh file.
New in Home directory
autobackupmysql.sh
#!/bin/sh
# File:/home/mysql/backup.sh
# Database Info
Db_name= "Test"
Db_user= "Root"
db_pass= "Root"
# others VARs
Bin_dir= "/alidata/server/mysql/bin" #这里是mysql Bin directory (delete)
Bck_dir= "/alidata/www/data/mysqldata" #这里是指备份目录 (delete)
Date= ' Date +%f ' #这里是指以时间命名
# TODO
$BIN _dir/mysqldump-u$db_user-p$db_pass--default-character-set=utf8 $DB _name> $BCK _dir/db_$date.sql # This refers to the execution of the command (delete)
Step Two:
Vi/etc/crontab
Add in Blank space:
1 */1 * * mysql/alidata/www/data/autobackupmysql.sh
Represents a little backup every day 0 morning
Windows Server Scheduled backups
1. Copy Date folder Backup
============================
Hypothetical environment:
MySQL Installation Location: C:\MySQL
Forum database name: BBS
Database backup destinations: C:\db_bak\
============================
Create a new Db_bak.bat and write the following code
Code start*****************************
net stop MySQL
xcopy C:\mysql\data\bbs\*.* c:\db_bak\bbs\%date:~0,10%\/s/i
net start MySQL
Code End *****************************
You can then use Windows Scheduled Tasks to execute the batch script at timed intervals. (For example: Perform Back_db.bat 3 o'clock in the morning every day)
Explanation: Backup and restore operations are relatively simple, integrity is relatively high, control backup cycle more flexible, for example, with%date:~0,10%. This method is suitable for users who have a standalone host but have no management experience with MySQL. The disadvantage is to occupy more space, backup period MySQL will be a short period of time disconnect (for example: about 30M database time is about 5s), for the use of%date:~0,10% reference.
2, mysqldump backup into SQL files
==============
Hypothetical environment:
MySQL Installation Location: C:\MySQL
Forum database name: BBS
MySQL Root Password: 123456
Database backup destinations: D:\db_backup\
Script:
REM *******************************code start*****************************
@echo off
Set "ymd=%date:~,4%%date:~5,2%%date:~8,2%"
C:\MySQL\bin\mysqldump--opt-u root--password=123456 bbs > D:\db_backup\bbs_%Ymd%.sql
@echo on
REM *******************************code end*****************************
Save the above code as Backup_db.bat
You can then use Windows Scheduled Tasks to execute the script at timed intervals. (For example: Perform Back_db.bat 5 o'clock in the morning every day)
Note: This method can be used to back up files by the name of each day, without shutting down the database.
The current date is grouped by%date:~5,2%, and the combined effect is the date format of the Yyyymmdd,date command, which defaults to YYYY-MM-DD (if this is not the format you can pause the command line window through the pause command. See through%date:~,20% Gets the current computer date format), so you can get the two characters starting with the fifth character in the date by%date:~5,2%, for example, today is 2009-02-05 and 02 is available through%date:~5,2%. (The subscript for the date's string is starting at 0)
3, using WinRAR to the MySQL database for a scheduled backup.
For MySQL backup, the best way is to directly back up the MySQL database data directory. A method of using WinRAR to perform a scheduled backup of the data directory is provided below.
First of all, of course, install the WinRAR on the computer.
Write the following command to a text file
Code start*****************************
net stop MySQL
C:\progra~1\winrar\winrar a-ag-k-r-s D:\mysql.rar d:\mysql\data
net start MySQL
Code end*****************************
Save, and then modify the extension of the text file to cmd. Enter the control Panel, open the Scheduled task, and double-click Add Scheduled task. In the Scheduled Task Wizard, locate the cmd file just now, and then specify a run-time and run-time account password for this task.
Add a Scheduled task
(1) Program-> attachment-> System Tools-> Task Schedule-> Add Task Schedule
(2) Click Next
Click Browse to select the bat file you just created
(3) Set task execution time
Then click Next to enter the administrator password