Common data backup methods in Linux

Source: Internet
Author: User
Tags openldap qmail
Article Title: common data backup methods in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

As a new-generation network operating system, Linux is widely used in servers. As a dedicated network server, an important function is to back up server data to ensure data security. This article describes some common data backup methods in Linux.

1. Manual data backup on the local machine

The Linux system is equipped with powerful tar commands to flexibly back up data. Tar was originally designed to back up files and directories to tape for tape backup and then extract or restore files from the tape. Of course, now we can use tar to back up data to any storage medium. Tar is very easy to use, stable, and reliable, and has this command on any Linux system. This is the most frequently used backup tool.

(1) Use the tar command to back up data in the following format:

$ Tar cvf backup.tar/home/html

The preceding command is to pack all the files in the/home/html Directory into the tarfile backup.tar.

Cvf is the command parameter of tar.

C Indicates creating an archive file,

V indicates the name of each backup file,

The file name created by f tar.tar is backup.tar,

/Home/html indicates the name of the file or directory to be backed up by tar.

(2) Use the tar command to restore data in the following format:

$ Tar xvf backup.tar

Run the following command to restore the Upload File backup.tar to the current directory.

Generally, tar does not compress files when backing up files. Therefore, the size of the backup files is very large. Run the following command to compress the backup file after the backup is complete.

$ Tar zcvf backup.tar.gz/home/html

In this case, we can get the compressed file backup.tar.gz.

Backup.tar.gz is a compressed backup file.

2. Automatic Backup of local data

Using the above command, we can manually back up data, but daily scheduled operations may be cumbersome. Of course, Linux provides us with powerful tools for automatic backup. This is cron.

Cron is a background process. once started, the task will be executed regularly according to the configuration file. We can write a shell script file to back up the file, and then let cron regularly start the script file to back up the data.

For example, if we back up all the files in the/home/html directory to the/home/admin/backup/backup_xxxx directory every day, xxxx indicates the backup date. You can write the following shell script backup. sh for this task:

#! /Bin/sh

Cd/home/admin/backup

Year = 'date + % y'

Month = 'date + % m'

Day = 'date + % d'

Now = $ year-$ month-$ day

Mkdir backup _ $ now

Tar zcvf backup _ $ now/backup.tar.gz/home/html

This script automatically reads the system date when backing up data, creates a new directory based on the current system date, and packs and compresses the backup data in this directory. We can execute $ sh backup. sh in the system to complete the backup. If you type $ chmod + x backup. sh, you can set backup. sh to run. In this way, you can directly run the backup script file by typing $./backup. sh. Generally, we want to back up data when the system load is not the largest. Generally, we can back up data at every day (during this time, the number of users accessing your server should be minimal ?). Give everything to cron. After cron is started, it checks the configuration file in the/var/spool/cron/directory to find the task to be executed and the time to execute the task, according to these settings, the specified task is executed at the specified time.

The task configuration file can be edited by the crontab-e command.

The format is that each line represents a task and the specified execution time.

Each line consists of six fields:

Minute hour day month week command

The preceding six fields are separated by spaces or tabs:

Minute: minute field. The value ranges from 0 to 59.

Hour: small time domain, value range: 0 to 23

Day of each month: date. The value ranges from 1 to 31.

Month: month. The value ranges from 1 to 12.

Week: Week, the value range is 0 to 6, and the Sunday value is 0.

The command to be run is special. If a domain is '*', it indicates that the command can be executed within all possible values of the domain. If a field is two numbers separated by a hyphen, the command can be executed within the range of two numbers (including the start and end numbers ). If a field is composed of a series of values separated by commas, the command can be executed within the range of these values. Now, we write a file to start the backup shell program at every day.

Type: crontab-e command,

Enter: 0 3 *** backup. sh. After the input is complete, save the disk and exit.

Type crontab-l to check whether the input is correct. So long as the Linux server is not shut down, the backup. sh script will be automatically started at every day to back up the data. You can rest assured.

Backup method of the FMS

I. Backup Data Description:

Data in the Foxmail Server system is divided into the following types:

Email data: it exists in the corresponding directory of the system. This is important data. It mainly stores the mail content, mail Information, email information, and filter information of all users.

The directory structure is: [root directory for storing mail data]/[service domain name]/[lowercase letters for the first user account]/[User Account]/[Mailbox structure]. For example, in the case of default installation, the admin user's email directory in the bodachina.com domain is/home/webmail/bodachina.com/a/adminuser information data: stored in the data warehouse. It stores the user's personal information, such as the user name and password.

User address data: it exists in OPENLDAP. It is mainly used to store users' Address Book information. By default, data is stored in the/usr/local/var/openldap-ldbm log file, including the mail server log file and WEB server log file, exists in various Server directories. By default, the WEB server log files are stored in/usr/local/resin/log; the mail server log files are stored in the/var/log/qmail directory.

Temporary data: stored in the temporary directory of the system, usually the/tmp/webuser directory, used to store temporary data of the system.

Ii. Description of data backup methods

To back up data, follow these steps:

Create a directory for storing backup data and logs. You can store the backup data in/home/foxmail/backup to package the mail data. Depending on the system installation, the mail data directory may be different. By default, the mail data directory is set to/home/webmail. For details, refer to the system installation manual. Packaging command:

Cd/home/

Tar vcvf maildata.tar.gz webmail mv maildata.tar.gz/home/foxmail/backup/xxx_maildata.tar.gz where xxx is an event annotation.

User information is backed up from the database. The specific command is: mysqldump? U [database username]? P [Database Password] [database name]> userdata. SQL

By default, the username, password, and Database Name of the database installed by the system are qmail.

After export, move userdata. SQL to the backup data storage directory. Specific commands:

Cd/home/foxmail/backup

Mysqldump? Uqmail? Pqmail qmail> xxx_userdata. SQL

Or you can directly package and back up the database directory. In the directory where the mysql database stores data, you can see a database named qmail. You can back up data in the qmail database using the preceding packaging method.

Back up the address book data. Package the OPENLDAP data directory. By default, it is the/usr/local/var/directory. The specific command is tar zcvf addrdata.tar.gz [LDAP data directory name], and the data packet is moved to the backup data storage directory, the method is similar to the above. Or you can use the OPENLDAP command for backup: ldapsearch? B 'o = foxmail' objectclass = *-x? H ldap: // 192.168.1.227: 1212> ldapdata. ldif if the user's address book contains too much data, the upper limit of search may occur. You can modify the OPENLDAP configuration file to solve this problem. The modification method is as follows: insert in the/usr/local/etc/openldap/slapd. conf file:

Si zelimit 50000

Back up log files. It is usually used to back up mail server logs and WEB server logs. By default, the mail server log directory is/var/log/qmail/, while the WEB server log is stored in the/usr/local/resin/log/directory. Pack the related files and move them to the log storage directory.

Delete temporary data. After the system has been running for a period of time, the system data directory will accumulate a certain amount of temporary data. To improve system efficiency and free system disk space, delete the temporary data. The specific method is: stop FoxmailServer, run FoxmailServer stop, delete all directories in the temporary directory (under/tmp/webuser/by default), and enter/tmp/webuser /, delete all directories and files in this directory.

Iii. Use cron to back up data in the FMS

1. Add cron records:

Crontab? E

Add record row: 0 3 ***/home/foxmail/bin/backup. sh

2. Create a script:/home/foxmail/bin/backup. sh

#! /Bin/sh

Year = 'date + % y'

Month = 'date + % m'

Day = 'date + % d'

Now = $ year-$ month-$ day

Mkdir/home/foxmail/backup/$ now

Cd/home/mysql/data/

Tar zcvf/home/foxmail/backup/$ now/mysql_qmail.tar.gz qmail

Cd/usr/local/var/

Tar zcvf/home/foxmail/backup/$ now/openldap-ldbm.tar.gz openldap-ldbm

Tar zcvf/home/foxmail/backup/$ now/openldap-slurp.tar.gz openldap-slurp

Cd/home/

Tar zcvf/home/foxmail/backup/$ now/webmail.tar.gz webmail

You can back up the system data three times a day through the above two steps. However, in the case of a large number of users, you do not have to back up webmail every day, this will soon occupy all the hard disk space. You can comment out the corresponding rows in backup. sh.

Data backup method description:

When the system encounters a catastrophic fault, you can restore the system by restoring the backup data. The steps are as follows:

Restore the mail data package maildata.tar to the system's mail data storage directory, and back up the user information file userdata. restore the SQL statement to the database by using the database account (qmail by default). Run the show tables command to obtain information about all tables. Run the drop table [table name] command to delete all tables, exit the database, and run mysql? U [user name]? P [User Password] [database name] <userdata. SQL, re-import the backup data to the database.

Overwrite the original data file with the address book backup information. By default, openldap files under/usr/local/var are used.

Summary

Actual backup script backup. sh:

#! /Bin/sh

Year = 'date + % y'

Month = 'da

Te + % m'

Day = 'date + % d'

Now = $ year-$ month-$ day

Exp tbpf/tbpf @ ora9i file =/home2/tbpf_backup/TbpfDB $ now. dmp owner = tbpf

Cd/home2/tbpf_backup/

Tar zcvf/home2/tbpf_backup/tbpf_backup_tar/tbpfdb1_now.tar.gz TbpfDB $ now. dmp

Rm-rf TbpfDB $ now. dmp

Te + % m'

Day = 'date + % d'

Now = $ year-$ month-$ day

Exp tbpf/tbpf @ ora9i file =/home2/tbpf_backup/TbpfDB $ now. dmp owner = tbpf

Cd/home2/tbpf_backup/

Tar zcvf/home2/tbpf_backup/tbpf_backup_tar/tbpfdb1_now.tar.gz TbpfDB $ now. dmp

Rm-rf TbpfDB $ now. dmp

Original address http://www.diybl.com/course/3_program/shell/shelljs/20090507/166768.html

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.