Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ MySQL database under Linux to achieve automatic backup scheduled backup day     - Teach you how to protect the security of Linux desktop (Linux)

- Security Knowledge: redirection command application security (Linux)

- Sort sql MySQL 5.6 upgrade slow Cause Analysis (Database)

- Linux virtual machine settings network, hostname ssh access (Linux)

- Spring AOP for logging (Programming)

- Create a DLL using MinGW and Attention (Programming)

- Java 8 Lambda principle analysis (Programming)

- linux firewall configuration (Linux)

- JQuery implements the same content merge cells (Programming)

- Upgrading to MySQL 5.7.9 MySQL 5.6.23 (Database)

- Repair Chrome for Linux is (Linux)

- MySQL migration tool used in the production environment (Database)

- A deep understanding of Java enum (Programming)

- Update GAMIT10.6 command (Linux)

- CV: Linux command displays the progress of the run command (Linux)

- 2 minutes to read large data framework Hadoop and Spark similarities and differences (Server)

- About DataGuard three protected mode test (Database)

- Linux configuration startup mount: fstab file (Linux)

- How to Install Puppet in the Ubuntu 15.04 (Server)

- Linux install deploy Ansible (Linux)

  MySQL database under Linux to achieve automatic backup scheduled backup day
  Add Date : 2018-11-21      
Backup is the basis for disaster recovery, it refers to operational errors or system failures occur in order to prevent loss of data systems, and all or part of the data set is copied from the application host's hard disk or other storage arrays to process media. For some sites, systems, databases is everything, so make a backup of the database is essential!

What backup?
Why backup
Disaster recovery program construction

Storage media
Magnetic tape
Hard disk
Disk Array
DAS: Direct Attached Storage
NAS: Network-attached storage
SAN: Storage Area Network
Cloud Storage

Here mainly to local disk as a storage medium to use to talk about to add scheduled tasks, basic backup script, and other storage media access method is the media may not be the same.

1. Check disk space:
Since it is a regular backup, we must choose a space sufficient disk space to avoid backup failure due to lack of space, the consequences of data loss!
Stored to the current disk This is the simplest, but most are not recommended; how the server hard drive, it is best to store the backup to another hard disk; conditional on the choice of better and safer storage medium;

# Df -h
Filesystem Size Used Avail Use% Mounted on
/ Dev / mapper / VolGroup-lv_root 50G 46G 1.6G 97% /
tmpfs 1.9G 92K 1.9G 1% / dev / shm
/ Dev / sda1 485M 39M 421M 9% / boot
/ Dev / mapper / VolGroup-lv_home 534G 3.6G 503G 1% / home

2. Create a backup directory:
Above we see that using the command / home under more adequate space, so you can consider the / home save the backup file;

cd / home
mkdir backup
cd backup

3, create a backup Shell script:
Note that the following command in the DatabaseName replaced by the actual name of the database;
Of course, you can also use the fact of naming!

vi bkDatabaseName.sh

Input / paste the following:

#! / Bin / bash
mysqldump -uusername -ppassword DatabaseName> / home / backup / DatabaseName _ $ (date +% Y% m% d_% H% M% S) .sql

Compression of backups:

#! / Bin / bash
mysqldump -uusername -ppassword DatabaseName | gzip> / home / backup / DatabaseName _ $ (date +% Y% m% d_% H% M% S) .sql.gz

Replace username with the actual user name;
The password with the actual password;
The DatabaseName replaced by the actual name of the database;

4, add executable permissions:
chmod u + x bkDatabaseName.sh
After you add executable permissions to perform to see if there was anything wrong script can not work properly;


5. Add Scheduled Task
Detect or install crontab
Confirm crontab is installed:
Execute crontab command if the message command not found, it indicates not installed

# Crontab
-bash: crontab: command not found1
As there is no installation crontab, you need to install it, please refer to the specific steps:
Under CentOS using yum command to install the Task Scheduler crontab
Use the rpm command crontab from CentOS system disk to install the Task Scheduler

Add Scheduled Task
Excuting an order:

crontab -e

Then just use the vi editor, you can edit the planned tasks.
Enter the following and save:

* / 1 * * * * /home/backup/bkDatabaseName.sh

What exactly does it mean?
Meaning that every minute execute a shell script "/home/backup/bkDatabaseName.sh".

6, whether to perform the test task
Quite simply, we executed several "ls" command to see one minute after the file has not been created on it!

If the task fails, you can view the task log with the following command:

# Tail -f / var / log / cron

Output similar to the following:

Sep 30 14:01:01 bogon run-parts (/etc/cron.hourly) [2503]: starting 0anacron
Sep 30 14:01:01 bogon run-parts (/etc/cron.hourly) [2512]: finished 0anacron
Sep 30 15:01:01 bogon CROND [3092]: (root) CMD (run-parts /etc/cron.hourly)
Sep 30 15:01:01 bogon run-parts (/etc/cron.hourly) [3092]: starting 0anacron
Sep 30 15:01:02 bogon run-parts (/etc/cron.hourly) [3101]: finished 0anacron
Sep 30 15:50:44 bogon crontab [3598]: (root) BEGIN EDIT (root)
Sep 30 16:01:01 bogon CROND [3705]: (root) CMD (run-parts /etc/cron.hourly)
Sep 30 16:01:01 bogon run-parts (/etc/cron.hourly) [3705]: starting 0anacron
Sep 30 16:01:01 bogon run-parts (/etc/cron.hourly) [3714]: finished 0anacron
Sep 30 16:15:29 bogon crontab [3598]: (root) END EDIT (root)
- Android Studio 1.0.2 set the memory size (Linux)
- Using BBED repair ORA-01190 error (Database)
- Linux security concerns again (Linux)
- Linux / Centos anti CC attack script (Linux)
- CentOS 6.5 start ActiveMQ being given to solve (Server)
- CentOS 6.6 installation certification system based on the ftp service (Server)
- Linux System Getting Started Learning: After starting in Ubuntu or Debian, enter the command line (Linux)
- Git large file storage will help handle large binary files (Linux)
- Using PPA to install the lightweight theme software HotShots 2.1.0 under Ubuntu (Linux)
- CentOS 6.5 installation and configuration Cobbler (Server)
- Use PuTTY key authentication mechanism for remote login Linux (Linux)
- CentOS install SVN server configuration and automatically synchronized to the Web directory (Server)
- CentOS6.5 install SVN & visual management tools iF.SVNAdmin (Server)
- Install and manage Java under mac (Linux)
- See how --nand flash timing diagram of a read operation Comments (Programming)
- Linux commands with browsing and downloading files (Linux)
- MongoDB, Cassandra, HBase transaction design strategy (Database)
- To install network scanning and packet sniffer tool Nmap 7.00 under ubuntu (Linux)
- Use small network command to check whether PC Security (Linux)
- Oracle 11g em start newspaper site's security certificate has a solution to the problem (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.