Linux incremental system backup and partial restore policy

Source: Internet
Author: User
Tags temporary file storage

.

.

.

.

.

Full use of Linux has been nearly half a year, has been trying to backup the data, but has not done, why?

On the one hand is a lot of things, backup a long time, on the other hand is always tangled in which way to back up better.

On the internet casually Google: Linux system backup, you can search more than N articles detailed introduction of the advantages and disadvantages of various backup tools.

Choose to choose the final or choose the Tar method. The reason is simple, from a few years ago when LZ began to use Linux, it has been using the TAR backup system. Although it was Linux white at the time, it did not understand the meaning of the various options when using the tar backup, just copied the commands on the web. But today's understanding of tar is much deeper than that, plus the versatility of the TAR package format, which gives the LZ the most reassurance of the way the TAR is backed up.

Of course, this blog post is not to discuss the kind of backup way better, just to share the idea of LZ backup, so that the garden also encountered this problem of the park friends have a reference.

First look at the data on the disk:

>$sudoFDISK-Ldisk/DEV/SDA:120.0GB,120034123776bytes255Heads theSectors/track,14593Cylinders, Total234441648sectorsunits= Sectors of1* += +bytessector size (logical/physical): +Bytes/ +Bytesi/o Size (minimum/optimal): +Bytes/ +bytesdisk Identifier:0x0008fa39Device Boot Start End Blocks Id System/DEV/SDA1 *2048   234440703   117219328    theLinuxdisk/DEV/SDB:1000.2GB,1000204886016bytes255Heads theSectors/track,121601Cylinders, Total1953525168sectorsunits= Sectors of1* += +bytessector size (logical/physical): +Bytes/4096Bytesi/o Size (minimum/optimal):4096Bytes/4096bytesdisk Identifier:0X000A1DDBDevice Boot Start End Blocks Id System/dev/sdb12048  1922080767   961039360    theLinux/dev/sdb21922082814  1953523711    15720449    5extendedpartition2does not start on physical sector boundary./dev/sdb51922082816  1953523711    15720448    theLinux Swap/Solaris>$

A total of two drives:

SDA is a 120GB SSD with only one partition mounted/file system.

SDB is a 1TB mechanical hard disk, one partition is mounted on the/home directory and the other is SWAP.

>$DF-hfilesystem Size used Avail use%mounted on/DEV/SDA1 111G6.1G 99G6% /None4.0K0  4.0K0%/sys/fs/Cgroupudev3.9G4.0K3.9G1% /Devtmpfs3.9G3.1M  3.9G1% /Tmptmpfs 789M1.3M788M1% /Runnone5.0M     0  5.0M   0%/run/Locknone3.9G 16M3.9G1%/run/shmnone 100M 32K 100M1%/run/Usertmpfs3.9G 812K3.9G1%/var/Logtmpfs3.9G 36K3.9G1%/var/tmp/DEV/SDB1 903G 306G 551G $% /Home>$

/partition uses 306 GB for the 6.1gb,/home partition.

That is to say LZ to back up about 300GB of data. Because of the large amount of data, LZ also want to be able to backup frequently, so can not select full-scale backup, only incremental backup.

LZ once with Windows lost once code, from then on every week to the overall ghost full backup, resulting in the result is 7 days a week, but to take out 1 days to backup. Fortunately lasted a long time, LZ moved to the Linux camp, no ghost This tool for the LZ squandered, so six months has not backed up the system.

Let's look at the incremental backup process for LZ:

1. First insert a 2TB capacity mobile hard drive.

2. Create a folder on your mobile hard drive dedicated to incremental backups, and all incremental backups will be placed in this folder.

3. Wait for the backup to finish.

4. Remove the removable hard drive and keep it safe.

Note that because it is a full-fledged backup, the following command must be ROOT to execute! Otherwise, many system files are not accessible to ordinary users.

>$mkdir/media/yuhuashi/e260733260730d13/Linuxbak>$ cd/media/yuhuashi/e260733260730d13/linuxbak/>$ Time Tar-G INCREMENT-CZVPF alldisk_ 'Date+'%y%m%d'`.Tar. GZ--exclude='/home/yuhuashi/virtualbox\ VMs'--exclude='Lost+found'--exclude='/media'--exclude='/mnt'--exclude='/proc'--exclude='/sys'--exclude='/ tmp'--ignore-failed-read/>$Umount/media/yuhuashi/e260733260730d13/

The most important thing here is the third command, I will introduce it here, the other commands are very simple to say.

Time (1) This command can be written or not, LZ plus it just to calculate how long this backup took.

Tar (1)

Tar Tar Archiving Utility Tar [-] A--catenate--concatenate | C--create | D--diff --compare |    --delete | R--append | T--list | --test-label | U--update | x     --extract--get [options] [pathname ...]

Parameter list:

-G Increment:increment is the name of a file that is generated during the backup process, which is used to record the status of the backup file. The next time the command is executed again, the tar command is the file that distinguishes which files have been modified and which have not been modified, so this is the key to the incremental backup! of course, the file name can be casually written, as long as the-G parameter is specified after the good. don't lose this file , or you won't be able to make incremental backups next time!

-C: Create a file package.

-Z: The package is compressed by gzip, it is the extension. gz.

-V: Displays detailed information about the processing file.

-P: Preserves file permissions.

-F: The name of the package that is followed directly by the zipped file. Notice how LZ writes this parameter?

Alldisk_ ' date + '%y%m%d '. tar.gz
Alldisk_.tar.gz is the invariant in this file name.
` ~ the symbol on the same key.
' Date + '%y%m%d ' indicates that the execution result of the date command is placed in the file name, which is the current year and month date. The full file name generated after the command execution is:alldisk_20150418.tar.gz

--exclude: The directory to exclude when backing up. Because some directories do not need to be backed up, they need to be excluded by this command. The specific need to exclude which directories to decide according to their own circumstances, such as LZ excluded the following directory:

/home/yuhuashi/virtualbox\ Vms:lz excludes the virtual machine directories in their home directory because the LZ does not want to back up the virtual machine data.
Lost+found: Each partition has this directory, which is a partially repaired file in the fsck process, similar to the found (N) folder in Windows, which is generally useless.
/media: Mount the disk with the LZ backup system of the mobile hard drive is mounted here, so of course you can not back it up, otherwise it is a recursive backup. And the data here is not the LZ computer's internal storage data, so skip.
/mnt: As with/media, skip directly. When you use GNOME, you plug in a new storage device and the system automatically mounts it to the/media. and LZ himself need to mount a device, such as a CD-ROM image (ISO) file, lazy to run to/media under the manual creation of a folder, after the use of manually deleted, will be lazy to directly attach it to/mnt below.
/proc: This is the default mount path of the proc virtual file system, where the files you see are not real on disk, and are generally the virtual files that the driver creates to facilitate viewing of device information.
/sys: Similar to/proc, is the default mount path for the SYS virtual file system. /proc The following files are more likely to be shown, while/sys the following files are more likely to be shown to the machine.
/tmp: The location of temporary file storage, no use, skip directly. Because the LZ put/mounted on the SSD, so in order to reduce the write times of/TMP to SSD to improve the life of the SSD, the LZ simply mount it to memory up.

--ignore-failed-read: Ignoring read errors without interrupting backups, the default is to interrupt the backup process when the read file encounters an error. LZ Wood has just started to add this parameter, however, after waiting for one hours, just before the end of the backup, suddenly/run directory has a file Permission denied, although do not know why root read the file will be rejected, but it interrupted the backup process, which allows the LZ This one-hour is a vain waste.

/: It represents the file or directory to be packaged, must be placed at the end of the entire tar command, and no other parameters can be written at any later. LZ fills in the root directory, indicating that all directories and files mounted under the root directory are backed up, in addition to the files or directories specified by the--exclude parameter. Although SDA1 (/) and SDB1 (/home) are partitions on two different disks, SDB1 is now mounted on/below the home directory, so when the backup/time contains the contents of//, it is natural to back up the data on the two disks into the same tar package 。

Mentioned in the previous incremental backup , that is, LZ next time back up the system, only need to mount the mobile hard disk again, and then run the same 4 commands above, the TAR (1) command will automatically find which files in the current system and the backup package files are different, And only these differentiated files are scored in the incremental package.

So how do you do it when you restore? Also very simple, want to revert to which version, directly the version of the previous tar package to extract sequentially.

tar xzvf alldisk_20150418. tar. gz-c/tar xzvf alldisk_20150419. tar. gz-c/tar xzvf alldisk_20150420. tar. Gz-c/....

Do you know all the above parameters? What X and C don't know what that means?

x: Means unpacking, exactly the opposite of the C parameter we specified above, and XC two parameters cannot be used in the same command.

C: Indicates the location of the specified decompression, that is, to unzip the file in the package to/below.

In fact, there is a problem to solve, which is why the LZ finally chose the tar backup one reason.

If the LZ does not want to restore the entire system, but just want to restore their home directory how to do?

It is simple to specify the path to the files in the package after the compressed package.

tar xzvf alldisk_20150418. tar. GZ home/yuhuashi-c/home/yuhuashitar xzvf alldisk_20150419. tar. GZ home/yuhuashi-c/home/yuhuashitar xzvf alldisk_20150420. tar. GZ home/yuhuashi-c/home/yuhuashi ....

If you don't know which path the file is in the package, you can also use the grep (1) command to filter it.

tar xtf alldisk_20150418. Tar grep Yuhuashi

T: Represents the path of the test pack, which prints out all the files in the compressed package. This will then be filtered with the grep (1) command to find the file you want to unzip.

Written at the end: Of course if you are a server administrator, you can also use Crond + tar to incrementally back up your servers so that you can perform backups automatically on a regular basis.

Linux incremental system backup and partial restore policy

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.