The linux server automatically backs up the mysql database and saves the script for one week to automatically delete the previous backup.

Source: Internet
Author: User
Some time ago, I helped a school server Configure Automatic mysql database backup. I wanted to back up the database once a day and only save the backup for the last seven days. The implementation principle is very simple. Just run shell scripts. I hope my friends can help me to find out. The content is from the linux security net www.linuxso.com. Please indicate. # backup. sh in rootbackup. sh #.

Some time ago, I helped a school server Configure Automatic mysql database backup.

You want to back up the data once a day and only save the backup for the last seven days.

The implementation principle is very simple. directly use shell scripts. Hope you can help me.

The content is from linux security network www.linuxso.com.

 

# Put backup. sh in/root/backup. sh

# From linux security network www.linuxso.com

 

#! /Bin/bash

LANG = c

Tar-czf/data/backup/mysql -'Date+%Y-policm-policd-polica'.tar.gz/var/lib/mysql 2>/root/mysqlbackup. log

 

If test $? -Eq 0

Then

Echo "backupSuCcess! 'Date' ">/root/mysqlbackup. log

ELsE

Echo "backup failEd! 'Date' ">/root/mysqlbackup. log

#Sleep20

Fi

 

 

 

 

ThenCrontab-E: Edit and add a scheduled task as follows:

 

00 1 ** 0Rm-F/data/backup/* Sunday.tar.gz

00 1 ** 1 rm-f/data/backup/* Monday.tar.gz

00 1 ** 2 rm-f/data/backup/* Tuesday.tar.gz

00 1 ** 3 rm-f/data/backup/* Wednesday.tar.gz

00 1 ** 4 rm-f/data/backup/* Thursday.tar.gz

00 1 ** 5 rm-f/data/backup/* FrIdAy.tar.gz

00 1 ** 6 rm-f/data/backup/* Saturday.tar.gz

00 3 ***/root/backup. sh

Last week's backup is deleted at every night, and the backup is repackaged.

 

 

 

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.