MySQL database on Linux remote server scheduled backup and removal tutorial

Source: Internet
Author: User
Tags ssh

1.Linux server is generally SSH protocol, if the local is also a Linux environment, you can directly through the shell Connection, command:

Ssh-l root-p 8080 202.***.***.***

Where Root is the user name, generally root,8080 for the port, 202.***.***.*** for the server IP address;

Next will prompt you to enter the password, the input is correct then enters the server;

2. Then you need to create a folder where database backup data is stored;

Mkdir/mysql/mysqldata_bakeup

/mysql/mysqldata_bakeup for the path created, can be customized;

3. Create and edit files in the path/usr/sbin/bakmysql, command:

Vi/usr/sbin/bakmysql

At this point, the Bakmysql file is created under the/usr/sbin/path and entered Bakmysql edit state, then input;

fn = ' Date +%y%m%d '
Tar Zcvf/mysql/mysqldata_bakeup/mysql$fn.tar.gz/mysql/data

Or

Mysqldump-u root-ppassword/mysql/data/yourdatabase >/mysql/mysqldata_bakeup/mysql$fn.sql

Find $fn-name "mysql*.tar.gz"-type f-mtime +7-exec fm{}; >/dev/null 2>&1

Or

Find $fn-name "Mysql*.sql"-type f-mtime +7-exec fm{}; >/dev/null 2>&1

/mysql/mysqldata_bakeup/saves the path for the backup data, msql$fn.tar.gz the name of the backup data according to the date number,/mysql/data the data path for the server database, yourdatabase the name of the database you want to back up;

Note that the first command is not a single quotation mark, but a symbol above the TAB key, and a space is required before and after date;

The second command has two methods, the first direct backup and compressed database data source files, the second is to use MySQL with the command mysqldump export database yourdatabase SQL files;

The third sentence is to delete the backup file 7 days ago, the filename is written corresponding to the second sentence.

4. Modify the file Bakmysql property to make it executable;

chmod +x/usr/sbin/bakmysql

5. Modify/etc/crontab:

Vi/etc/crontab

Go to edit state and add at the bottom:

3 * * * root/usr/sbin/bakmysql

01 3 is executed every 3:01 bakmysql documents;

6. Regarding the reboot sometimes does not need, if the server has the Crond service under the/etc/rc.d/init.d/path, may choose to reboot the Crond, the command:

/etc/rc.d/init.d/crond restart

7. Last Exit Server command: Exit

Summary:This article is based on the client local is also a Linux environment case, if the local is a Windows environment, you can install a client to remotely manage Linux, and then the procedures are basically the same, I hope this article will help you.

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.