Linux backup policy (version 2), version 2

Source: Internet
Author: User
Tags add time

Linux backup policy (version 2), version 2
Backup Policy

 

Backup ideas

I. potential threats to the System

System hardware faults

Software faults

Power supply faults

User misoperation

Man-made destruction

The content in the cache is not written to the disk in time.

Ø natural disasters

 

Ii. Selection of backup media

Backup media: Hard Disks [commonly used by Linux File Servers] tape [commonly used] removable storage devices

Generally, when selecting backup media, you must weigh the reliability, speed, and price. Generally, choose hard disks and tape drives.

 

Iii. Backup Policy

Full backup

Perform a full backup of the system at intervals. In this way, once a system failure causes data loss, you can use a backup to recover data to the last backup.

 

Ø Incremental Backup

A full backup is performed first, and then a backup is performed at intervals of a short period of time, but only the changes in each short period of time are backed up.

In practice, the two are used in combination.

 

Iv. Backup Classification

System Backup

Back up operating systems and applications

Objective: To quickly and completely recover system operation after system crash

It mainly backs up/etc,/boot,/var/log,/usr/local, and so on. Generally, it is performed only when the system content changes.

 

User backup

Implements the backup/home of user files, and frequent changes to user data

Generally, Incremental backup is used.

 

5. record changes and create backup logs

Record System Changes: record the detailed descriptions of system changes and the reasons for the changes

Create backup log: use the backup log table

Secure

 

[Example of a backup log table]

Machine name, IP address, storage location

Backup time

Backup media and ID

Backup File System

Backup directories and files

Backup Command Used

Backup personnel and others

 

Instance analysis

I. cp command backup example

Cp-Rpu [Backup Directory] [target directory]

-R backs up directories.

-P: Keep the Backup Directory attributes.

-U Incremental Backup

Remote Backup: scp

E. g.

Cp/etc/inittab/backup/inittab_2014092301.bak # the last two digits indicate the number of modifications made on the current day, but the time value of the source file and backup file is inconsistent.

Cp-Rup/etc // backup/etc_2014092301.bak

 

Ii. Example of tar command backup [SAVING file attributes by default]

Backup

1. tar-zcf/backup/sys_20110303.tar.gz/etc/boot # Back Up The/etc and/boot directories. You can package multiple directories at the same time.

2. tar-zcf backup_user_20110303.tar.gz/etc/passwd/etc/shadow/etc/group/etc/gshadow # back up the specified files in the/etc directory

3. tar-ztf backup_user_20110303.tar.gz # Check the files in the backup package if you do not understand the package.

 

Restore

1. tar-zxf/backup/etc_20110303.tar.gz # restore the/etc directory to the package file source directory by default.-C can specify the Restore directory.

Tar-zxvf backup_user_2014092101.tar.gz-C/backup

2. tar-zxf backup_user_20110303.tar.gz etc/group # only restore the specified file in the backup

# Create the etc directory in the current directory and restore the group file to the directory. Note that there is no/symbol before the etc directory. How do I write the files in the tar package, what is recovery!

 

Backup Best Practices

1. tar-rf backup_user_20110303.tar/etc/default/useradd/etc/login. defs

Add the content of/etc/default/useradd and/etc/login.defsto backup_user_20110303.tar.

 

2. tar-uf backup_user_20110303.tar/etc/passwd

Append the modified content in the/etc/passwd directory to the backup file.

 

[*-R and-u options can only be used for tar packages and cannot be used to compress files]

 

3. tar-zcf/backup/etc _ $ (date ready before f).tar.gz/etc

Add time (year, month, and day) for backup file name)

 

4. tar-zcf/backup/etc _ $ (date + % Y. % m. % d-% H: 1_m1_.tar.gz/etc

Add year. Month. Day-hour: minute

 

Backup Process

1. Backup awareness

2. backup partition ro or unmount

Mount-o remount, ro/backup # mount the partition in read-only mode

Umont/backup # unmount the backup partition directly

3. Data Compression

4. Verify md5sum-c

5. gnupg2 asymmetric key encryption

 


Backup policy selected in Linux

Feasible and appropriate. tar is used for backup.
However, pay attention to the backup cycle. For example, if you perform full backup once a week, incremental data is generated every day and the backup history is retained for one month.

How is system logs backed up in linux?

This article is tested in linux and mysql 4.1.14. After modification, it may be applicable to mysql 4.0, 5.0 and other versions.

This article is applicable to mysql that does not enable replication. If replication is started, you may not need to adopt this backup policy or modify relevant parameters.

Each person may have different backup policies. Therefore, Please modify the policies based on actual conditions to avoid copying them, which may cause unnecessary losses.

I hope you understand what the script is!

Script description

All data is backed up once every 7 days, and binlog is backed up every day, that is, Incremental backup.

(If there is little data, you can back up the complete data once a day, and there may be no need for Incremental Backup)

I am not familiar with shell scripts, so I am very stupid in many places :)

Enable bin log

In mysql 4.1, only error logs are generated by default, and no other logs exist. you can modify the configuration to open the bin log. there are many methods, one of which is in/etc/my. add the mysqld part in cnf:

[Mysqld]
Log-bin

This log is mainly used for Incremental backup or replication (it may be used for other purposes ).

To perform Incremental backup, you must enable this log.

For mysql with frequent database operations, this log will become very large and there may be multiple logs.

Flush-logs in the database, or use mysqladmin and mysqldump to call flush-logs and use the delete-master-logs parameter. These log files will disappear, and generate a new log file (which is empty at the beginning ).

Therefore, it is unnecessary to enable the log if the backup is never performed.

You can call flush-logs at the same time as the full backup. Before the Incremental backup, flush-logs is used to back up the latest data.

Full backup script

If there is a large amount of database data, we usually back up the data once a day or a week to avoid affecting application operation. If the data volume is small, it doesn't matter if we back up the data once a day.

#! /Bin/sh

# Mysql data backup script
# By scud
#2005-10-30
#
# Use mysqldump -- help, get more detail.
#

BakDir =/backup/mysql
LogFile =/backup/mysql/mysqlbak. log

DATE = 'date + % Y % m % d'

Echo ""> $ LogFile
Echo ""> $ LogFile
Echo "-----------------------------------------"> $ LogFile
Echo $ (date + "% y-% m-% d % H: % M: % S") >>$ LogFile
Echo "--------------------------"> $ LogFile

Cd $ BakDir

DumpFile = $ DATE. SQL
GZDumpFile = $ DATE. SQL. tgz

Mysqldump -- quick -- all-databases -- flush-logs
-- Delete-master-logs -- lock-all-tables
> $ DumpFile

Echo "Dump Done" >>$ LogFile

Tar czvf $ ...... remaining full text>

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.