Linux system backup and Restore tool 2 (tar/compression tool)

Source: Internet
Author: User
Tags prepare

The TAR compression Restore tool is more compact and flexible than the DD Backup Restore tool, but it cannot back up the MBR. Of course, you can fix this problem with the MBR by reinstalling Grub. At the same time, Tar's approach is officially recommended.

Note: A hard drive is up-to-date through the MBR (only 512KB), and then the MBR points to the operating system grub (that is, the kernel's boot program).

Prepare for backup

In order to prepare a full backup of the system, it is best to empty the trash and remove any unwanted files and programs from the current installation. This includes a home folder that can populate many files that are not needed. Doing so reduces the size of the archive you create, which is how much space is freed up.

An example is listed below, which can be used to determine the applicable example:

    • Delete all e-mail messages.
    • Wipe your saved browser profile and search history.
      • If you are not concerned about security issues, this step is not required. Many users explicitly require backup of their email and browser settings.

    • Uninstall any external drives, and remove any discs or discs that you do not want to include in the backup.
      • This will reduce the number of exclusions you enter later in this procedure.
    • through /Home in the contents of the user folder, Delete all the unwanted files in the subdirectory, usually people download the files and forget them.

Backup

to start, please open a terminal in Ubuntu which can be passed Application Menu - Accessories - Terminal Completion . Some directories require root or superuser read and write privileges (backup required) to understand why filepermissions is seen.  to get temporary root privileges, simply describe any commands you want to publish, as described in Rootsudo .

for this example, we changed the directory to root. This is where the backup is. This is an arbitrary decision and you should create a backup somewhere else. for example, for an external hard drive that is installed, you can use another partition or disk that is connected internally, and you can even use a folder in the home directory. In all cases, make sure that you have sufficient space for the archive archive location. just use the CD command to navigate there.

Cd

The following is an exemplary command of how to archive a system.

backup. tar.gz--exclude=/Backup

To understand what's going on, we'll dissect each part of the command.

  • tar  -is a command to create an archive. Each letter of the is immediately followed by a modification, and each letter is described below.

    • C  -Create a new backup archive.

    • v   -Verbose mode, tar will print its work on the screen.

    • P   -Retains the right to place files in the file for later recovery.

    • z   -Compress backup files with ' gzip ' to make them smaller.

    • F <filename> The  -specifies the location where the backup is stored, and backup.tar.gz is the file name used in this example. It is stored in the current working directory, which is the directory that is set when the CD command is used.

  • --exclude=/example/path  -the option after this model indicates what directory is tar does not Backup. We do not want to back everything up because some directories are not very useful to include. The first exclusion rule for indicates that tar does not automatically recover, which is important to avoid errors during the operation.

  • --one-file-system  -do not include files on different file systems. If you want other file systems (such as /home partitions) or are mounted in /media outside of Media Backup, you need to back up or omit this flag separately. If you omit this flag, you will need to add more -exclude= parameters to avoid the file system you don't want. These will be root /proc , /sys , / MNT , /media , /run and /dev directories. /proc and /sys are the variables that make the virtual file system available to the running kernel, so you do not want to attempt to back up or restore them.   /dev is a TMPFS whose content is dynamically created and deleted by Udev, so you do not want to back it up or restore it. Similarly, /run is a tmpfs that holds variables for running systems that do not need to be backed up.

  • It is important to note that these exclusions are recursive. This means that all folders that are located in all folders that are excluded will also be ignored. In this example, the exclude /media folder does not include all installed drives and media.

    • If you want to in/media to back up some partitions , simply remove the exclusions and write a new partition that does not include the partitions that you do not want to back up stored in. for example

      • backup. tar.gz--exclude=/Backup
  • / -All options are directories to be backed up. because we want to back up everything on the system, we use / as the root directory. like exclusions, this recursively includes each folder in the root directory that is not included in exclusions or other options.

Once the command is fulfilled, execute it and wait for it to complete. The duration of the operation depends on the number of files and the compression selection. once done, check the directory you set up to find the archive. in Our example, backup.tar.gz will be located in the / directory once completed. This archive can then be moved to any other directory for long-term storage.

Note: At the end of the process, you may receive a message that says "Tar: Error exits from a previous error" or something, but in most cases, you can ignore the message.

Standby backup

--one-file-system The "problem" option will be that you must include/boot/home or another partition.

The following is a tar example that contains additional recommendations for exclusions to make the resulting archive smaller. Before using this example, review and understand what is not included and modify it as needed.

CD/# ThisCDis IMPORTANT the following LONGCOMMANDIsRUNFrom/Tar-cvpzfBackup. tar.gz \--exclude=/Backup. tar.gz \--exclude=/proc \--exclude=/TMP \--exclude=/MNT \--exclude=/dev \--exclude=/sys \--exclude=/Run\--exclude=/media \--exclude=/var/log \--exclude=/var/Cache/apt/archives \--exclude=/usr/src/linux-headers* \--exclude=/HOME/*/.GVFS \--exclude=/home/*/.Cache\--exclude=/home/*/.local/share/trash/
    • /var/log does not include logs that you may or may not want to back up the log. general recommendations-skip them on the desktop, but include them on the server.
    • /var/cache/apt/archives excludes any. deb downloaded by apt. This saves a lot of space.
    • /usr/src/linux-headers* is again a space saver.
    • /home/*/{.cache,.gvfs,.local/share/trash} may not need to back up these files at all.

Additional hints

    • In order to maintain a good record, you should include the date and description of the backup in the file name.
    • Another option is to use bzip2 to compress your backups instead of gzip. The BZIP2 provides a higher compression ratio at the expense of speed. If compression is important to you, simply replace z in the command with J , and change the file name to . tar.bz2 . the remainder of this guide uses gzip to make subsequent changes before using the sample.

    • If you want to exclude all other installers except the current-this means to mount the partition to the directory-and then use the Exclude rule Attach of the --one-file-system Options. This has the effect of stopping tar from any other directory (including/MNT or/media) to any other installation location. For example, many users Create a separate mount for /home to separate the user folder from the root, Adding this option to our original example will completely exclude family content.

Archive split

if you want to burn an archive to a disc, or transfer it to the file system's maximum file size limit (for example, FAT32, each file is limited to 4GB), you will have to split the file during or after the archive creation process. A simple tactic is to use the split command. the Following are examples of two scenarios. More information is not just conveyed here, it can be found in the paging hand page, where people split up and read on the docks . Make sure that you keep all of these files in the directory you later tag extracts from. Once the files are divided into the appropriate size, they can be burned to the disc at once.

Split during compression

Tar-cvpz <put Options Here>/| Split-d-B 3900m-/name/of/backup
    • until the first half of the pipeline (|) is the same as our previous example except the F option is omitted. without this, tar will output the archive to standard output and then transfer it to the split command.
    • -D  -This option means that the archive suffix will be a number instead of alphabetical order, with each split starting in 01 order and incremented with each new split file.

    • -B  -This option specifies the size to split, in this example, I have set it to 3900mB to accommodate the FAT32 partition.

    • -   -The hyphen is a placeholder for the input file (usually the actual file that was created) and indicates a split to use standard input.  

    • /name/of/ Backup.tar.gz. is the prefix that will be applied to all generated split files. It should go directly to the archive folder you want. In our example, the first split archive will be in/name/of/and named backup.tar.gz.01.

Split after compression complete

Split-d-B 3900m/path/to/backup. tar.gz/name/of/backup. tar.gz.
    • Instead of using standard input, you simply split the existing file specified by/path/to/backup.tar.gz.

Rebuilding archives

Refactoring the full archive is easy, first the CD-ROM is loaded to keep the directory of the split archive. Then simply use cat to write all the archives to one and send the standard output to tar to extract to the specified directory.

Cat *tar.gz* | TAR-XVPZF-C/  
    • Before and after tar.gz, use * As a wildcard, tell the cat to start with the first matching file, and add a match to each one, a process called catenation, and the command how to get its name.
    • Later, in this example, it passes all of the standard output to tar to extract it to the root directory.
    • for a more complete description of recovery, see recovery .

Backup over the network

The command tar itself does not include network support, but when used in conjunction with other programs, this functionality can be implemented. Two common options are Netcat (NC) and SSH.

Netcat

Command NC is designed as a universal network tool. It establishes a simple connection between two networked machines. This connection exists until the user disconnects manually, unlike a regular connection like TCP, which terminates when the file completes.

Receiving computer

on the receiving side, you will set up Netcat to write the backup file, as shown in the following example. This command sets a machine to receive standard input from the network to port 1024 and then writes it to the file backup.tar.gz. The choice of port is entirely up to the user, as long as it is 1024 or greater. A simple example:

Backup

Send Computer

on the machine to be backed up, the tar command is piped to the NC and then sent over the network to the relevant port to write to the file. Note that in the < receive host > location, replace the name of the computer on the network. The F option is omitted because we do not write to the local file, but instead move the archive through standard output. Here is an example:

If all goes well, the backup will be piped through the network without touching the file system being read.

Ssh

You can also use SSH. for a complete description of its proper use, see SSH. the following commands are possible examples.

Tar-cvpz <all Those other options like above>/| SSH <backuphost> "(Cat > Ssh_backup.tar.gz)"

In the example:

    • The tar half of the command is the same as above, omitting the F option, managing the file to SSH via standard output and connecting to a networked computer.
    • ssh_backup.tar.gz The name of the file that will be created on the specified computer.

    • <backuphost> -The name of the computer on which the problem should be replaced on the network.

Recovery

you will be restoring from the Live CD. If necessary, first partition and format the drive. You can use gparted to do this . then simply mount the partition you want to recover. If you open the drive in Nautilus, it will be automatically installed under /media . see where to find out:

Ls/media

Restore Your backups

sudo tar-xvpzf/path/to/backup. tar.gz-c/media/whatever--numeric-owner

Brief description:

    • x -Tell Tar to immediately extract the file specified by the F option. In this case, the file is /home/test/backup.tar.gz

    • - C <directory> -This option tells Tar to change to a specific directory before extracting it. In this example, we are recovering to the root directory (/).

    • --numeric-owner -This option instructs Tar to restore the digital owner of the archive, rather than matching any user name in the environment that you are restoring. This is because the user ID in the system you are restoring does not necessarily match the system you are using to restore (for example, Live CD).

this overwrites the files in each file and directory on the specified mount. Any files created after the archive will not have an equivalent in the archive and will therefore remain unchanged

the time that is required to allow the recovery to complete. Once the extraction is complete, you may need to recreate the directories that are not included in the original archive because they are excluded using --exclude . This does not apply to file systems that are excluded using--one-file-system . This can be done with the following command:

Mkdir

Once completed and restarted, everything should be restored to the state of the system when you make a backup.

Restore Grub

to start the system, you need to restore grub. to do this, you will need to reconfigure in chroot:

sudo-s  for  do Mount--bind/$f/media/whatever/$f;  /media/whateverdpkg-reconfigure grub-pc

you will get a menu asking what drives you should install. Select any drives that the computer will start.

For more information about repairing grub, see Grubhowto

Restore over the network

This short guide assumes that you are using NC to perform the original backup as described above.

Receiving computer

Make sure that the disk is installed, and use the following command to accept the input on the network, and then extract it to the indicated path. In this example, the directory /mnt/disk will be extracted to.

Send Computer

On the computer where you want to send the archive, use the following command:

Backup

Several comments:

    • Section in one command of the - The word appears tells Tar to accept input from a standard input rather than a file.  In this case, the input comes from the pipeline.

    • The backup file will be extended and will not be saved on the disk of the receiving computer, as it was during the backup.

Reference:

Https://help.ubuntu.com/community/BackupYourSystem/TAR (Official TAR backup restore Tutorial)

http://blog.csdn.net/zeg635702733/article/details/53992224 (Tar reverts to a hard disk with inconsistent size)

http://www.linuxfly.org/post/493/(Migrating Linux)

http://www.jiazhoulvke.com/2014/10/27/linux/(HDD Migration)

Http://www.linuxidc.com/Linux/2015-04/116451.htm (replace motherboard)

Linux system backup and Restore tool 2 (tar/compression tool)

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.