CentOS automatically backs up Web sites using crontab timed tasks

Source: Internet
Author: User
Tags mysql backup

Do not need any professional software, use CentOS's own commands and services to complete the daily automatic backup.
Here's a common backup method:

1. File backup

Compress files for backup using the TAR command:
#tar-ZCVF backup.tar.gz Dir1
Dir1 for the directory or file to be backed up
Backup RESTORE command:
#tar-ZXVF backup.tar.gz

2. Database backup

Most database systems have commands to support backup and recovery of databases. For example, MySQL, the database backup command is:

The code is as follows Copy Code

#mysqldump-host=dbhost-user=username-password=password dbname > Db.dump

The restore command for the MySQL backup is:

The code is as follows Copy Code

#mysql-host=dbhost-user=username-password=password dbname < Db.dump

3. Automatic Task Scheduled backup

Use the above command to write a backup script (such as/home/backup/backup.sh), and then use the CRONTAB-E command to edit the timed task, the following is the day 01:30 automatic backup example

The code is as follows Copy Code

* * * */home/backup/backup.sh

4. Name of backup file

You can automatically add a backup time to a daily backup file name, and here is a sample script:

The code is as follows Copy Code

#! /bin/bash
Curr= ' Date +%y%m%d%h%m%s '
Tar czvf backup_$curr.tar.gz dir1 dir2
Mysqldump-host=dbhost-user=username-password=password dbname > Db_$curr.dump

Note that the system does not have crontab class Oh, we need a simple installation

Install Crontab:

The code is as follows Copy Code

[Root@centos ~]# Yum Install Vixie-cron
[Root@centos ~]# Yum Install Crontabs

Description
Vixie-cron packages are Cron's main programs;
The Crontabs package is a program used to install, uninstall, or enumerate the tables used to drive the cron daemon.

Cron is a built-in service for Linux, but it does not automatically get up, you can start and close the service in the following ways:

The code is as follows Copy Code

/sbin/service Crond Start #启动服务
/sbin/service Crond Stop #关闭服务
/sbin/service Crond Restart #重启服务
/sbin/service Crond Reload #重新载入配置

To view the Crontab service status:

The code is as follows Copy Code

Service Crond Status

To manually start the Crontab service:

The code is as follows Copy Code

Service Crond Start

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.