Table of Contents
Problem Description
Solution
Home Operation and Maintenance Linux Operation and Maintenance How to use MySQL automatic backup script under Linux server

How to use MySQL automatic backup script under Linux server

May 31, 2017 am 11:32 AM

Problem Description


How to automatically back up MySQL deployed in the ECS Linux system.

Solution


The MySQL service is built in the ECS Linux system. Users can use the following script to implement regular automatic backup of MySQL.

The usage method is as follows:

1. Copy the following script to the local, upload to the server, and the name is "autoback.sh"

#!/bin/bash
#-----------------------------------------------#
#This is a  free GNU GPL version 3.0 or abover
#Copyright (C) 2008 06 05
#mysql_backup Dedicated copyright by My
#-----------------------------------------------#
echo -e [`date +"%Y-%m-%d %H:%M:%S"`] start
#system time
time=`date +"%y-%m-%d"`
#host IP
host="127.0.0.1"
#database backup user
user="root"
#database password
passwd="yourpasswd"
#Create a backup directory
mkdir -p /backup/db/"$time"
#list database name
all_database=`/usr/bin/mysql -u$user -p$passwd -Bse 'show databases'`
#in the table from the database backup
for i in $all_database
do
/usr/bin/mysqldump -u$user -p$passwd $i > /backup/db/"$time"/"$i"_"$time".sql
done
echo -e [`date +"%Y-%m-%d %H:%M:%S"`]  end
exit 0

The database name and database password in the script are based on the database information that the user needs to back up and need to be modified by the user.

2. Run crontab -e and write the following content:

30 5 * * * root sh /root/autobackup.sh >/dev/null 2>&1

Save Exit, and then the database will be automatically backed up at 5:30 every morning. .

Note: Backup will occupy disk space, clean up unnecessary data or expand disk space in time.

The above is the detailed content of How to use MySQL automatic backup script under Linux server. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1596
276
What is the difference between UNION and UNION ALL in MySQL? What is the difference between UNION and UNION ALL in MySQL? Aug 14, 2025 pm 05:25 PM

UNIONremovesduplicateswhileUNIONALLkeepsallrowsincludingduplicates;1.UNIONperformsdeduplicationbysortingandcomparingrows,returningonlyuniqueresults,whichmakesitsloweronlargedatasets;2.UNIONALLincludeseveryrowfromeachquerywithoutcheckingforduplicates,

How to clean up your Linux system How to clean up your Linux system Aug 22, 2025 am 07:42 AM

Removeunusedpackagesanddependencieswithsudoaptautoremove,cleanpackagecacheusingsudoaptcleanorautoclean,andremoveoldkernelsviasudoaptautoremove--purge.2.Clearsystemlogswithsudojournalctl--vacuum-time=7d,deletearchivedlogsin/var/log,andempty/tmpand/var

How to change the GROUP_CONCAT separator in MySQL How to change the GROUP_CONCAT separator in MySQL Aug 22, 2025 am 10:58 AM

You can customize the separator by using the SEPARATOR keyword in the GROUP_CONCAT() function; 1. Use SEPARATOR to specify a custom separator, such as SEPARATOR'; 'The separator can be changed to a semicolon and plus space; 2. Common examples include using the pipe character '|', space'', line break character '\n' or custom string '->' as the separator; 3. Note that the separator must be a string literal or expression, and the result length is limited by the group_concat_max_len variable, which can be adjusted by SETSESSIONgroup_concat_max_len=10000; 4. SEPARATOR is optional

How to lock tables in MySQL How to lock tables in MySQL Aug 15, 2025 am 04:04 AM

The table can be locked manually using LOCKTABLES. The READ lock allows multiple sessions to read but cannot be written. The WRITE lock provides exclusive read and write permissions for the current session and other sessions cannot read and write. 2. The lock is only for the current connection. Execution of STARTTRANSACTION and other commands will implicitly release the lock. After locking, it can only access the locked table; 3. Only use it in specific scenarios such as MyISAM table maintenance and data backup. InnoDB should give priority to using transaction and row-level locks such as SELECT...FORUPDATE to avoid performance problems; 4. After the operation is completed, UNLOCKTABLES must be explicitly released, otherwise resource blockage may occur.

How to work with JSON data in MySQL? How to work with JSON data in MySQL? Aug 17, 2025 am 11:21 AM

Use MySQL to process JSON data to directly store, query and operate semi-structured data in relational databases. Since version 5.7, JSON types are supported; columns are defined through JSON data types and legal JSON values are inserted, MySQL will automatically verify the syntax; data can be extracted using JSON_EXTRACT() or -> (returns quoted strings) and ->> (returns unquoted values), such as profile->> "$.city" to obtain city names; support filtering JSON values through WHERE clauses, and it is recommended to use generated columns and indexes to improve performance, such as ADDcityVARCHAR(50)GENERA

How to select data from a table in MySQL? How to select data from a table in MySQL? Aug 19, 2025 pm 01:47 PM

To select data from MySQL table, you should use SELECT statement, 1. Use SELECTcolumn1, column2FROMtable_name to obtain the specified column, or use SELECT* to obtain all columns; 2. Use WHERE clause to filter rows, such as SELECTname, ageFROMusersWHEREage>25; 3. Use ORDERBY to sort the results, such as ORDERBYageDESC, representing descending order of age; 4. Use LIMIT to limit the number of rows, such as LIMIT5 to return the first 5 rows, or use LIMIT10OFFSET20 to implement paging; 5. Use AND, OR and parentheses to combine

how to create an alias in linux how to create an alias in linux Aug 19, 2025 pm 08:13 PM

The steps to set up alias in Linux are as follows: 1. Temporarily set the use of the alias command such as aliasll='ls-la'; 2. Permanently set the shell configuration file, such as ~/.bashrc, and then execute the source to take effect; 3. Be careful to avoid overwriting the original command and the different shell configurations are independent. Alias can simplify complex commands and improve efficiency, but only after the current shell environment takes effect and closes the terminal, it needs to be reasonably defined and regularly checked for configuration.

How to use IFNULL() in MySQL? How to use IFNULL() in MySQL? Aug 22, 2025 pm 02:00 PM

IFNULL()inMySQLreturnsthefirstexpressionifitisnotNULL,otherwisereturnsthesecondexpression,makingitidealforreplacingNULLvalueswithdefaults;forexample,IFNULL(middle_name,'N/A')displays'N/A'whenmiddle_nameisNULL,IFNULL(discount,0)ensurescalculationslike

See all articles