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 |