Compression and backup of files under Linux / HEIYELUREN
The backup and compression of the document is the primary issue encountered by the administrator. I just learned Linux, summarize the methods on the book and the network. (This article is based on redhat9)
First, use the tar command to back up
The TAR command has the original role is to put a lot of files in a small file, but it can also compress files. So, in general, we all use Tar.
Partial finishing and compression.
/ * Confuse / root's entire directory to compress backup * / # tar cvzf /tmp/Root_backup_1215.tar.gz / root
Then we can store /tmp/root_backup_1215.tar.gz, such as saving to the tape drive.
Description: The usual extension of the compressed TAR file is tar.gz, TGZ, or TAR.BZ2. The first two extensions typically use the gzip command to compress the TAR file, the latter extension is
Based on BZIP2 compression, because of the cause of the compression algorithm, the latter compression is stronger.
At the same time, we are also very easy to recover the files that have been compressed:
/ * Restore from the backup file * / # tar tkvzf root_backup_1215.tar.gz
Note: The tar command is related to the path. If you save your files to a directory (that is, the beginning is a bevel, such as / home / mj), you can use the text from any location on your computer.
Parts are restored to this directory. If you use a relative path (no bench, such as / home / mj), the file does not necessarily return to its original site, but depends on the current working directory.
/ * Release the backup file * / # tar zxvf root_backup_1215.tar.gz
/ * Back up / root directory and compress * / # tar czvf root_backup_1215.tar.gz / root
TAR command option ----------------------------------------------- ---- Options Features -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----- C Generates the file D comparison profile to use the file f File f Behind the file name J compressed into the BZIP2 format K without overwrite the current file R See the file Add to the file end T list the current archive The file V is lengthy, list all the files for entering and exporting zip, compresses the file x from the backup file in the normal Gzip format ------------------------------------------------------- ------------------------------ only part of the common option, please refer to the manual for more details
Second, using the CPIO Backup Archive CPIO (Copy IN / OUT) command can establish an archive, unlike TAR, it can handle the standard input output. As the name suggests, copy, input, and output. If you want to back up the root file, use the following command:
# Find / root | CPIO -O> /TMP/Root_Backup_1215.cpio
The CPIO can set a set of files to standard input using a wildcard. For example, see all .tif files to create a file:
# Find * .tif | CPIO -O> /TMP/back.cpio
Remember, the Find command is flexible, the following command archives all the .tif files in the system:
# Find / -Name '* .tif' | cpio -o> /tmp/back_tif.cpio simultaneously, it is also easy to recover files from the CPIO file. The following command restores the files in back_tif.cpio:
# cpio -i Like the TAR command, the cpio command restores the file saved from the directory depends on the relative path or absolute road. Another advantage of the cpio command is that the file can be sent directly to the external source, for example, the following command restores the file in the / root home directory, and send the file to the SCSI tape drive: # Find / root | CPIO -O -> / dev / ST0 # cpio -i dev / ST0 CPIO Command Options ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----- Options Features ------------------------------------------- ------- -A Add to the end of the archive, specify the file name with the -f -F, can be replaced with reverse arrows> -i to copy -O to file files or devices or Equipment -U replaces all files to update -V lengthy mode ------------------------------------------------------------------------------------------------------------------ --------------- Third, the tape transition and recovery DUMP and the restore command make it easy for the increment backup and difference backup. DUMP can get the directory content, RESTORE can interactively return the backup file to the original site. Although these commands are most commonly used for the tape drive, it is also suitable for other media, such as backup to the floppy disk. 1. There are three basic options with DUMP archive DUMP, you can set a series of commands, backup from the main directory, differential backup. For example, we have to back up the / home / mao directory to / devnst0 tape drive: # Dump 0f / dev / nst0 / home / mao # dump 1f / dev / nst0 / home / mao # dump 2f / dev / nst0 / home / mao # dump 3f / dev / nst0 / home / mao # dump 4f / dev / NST0 / HOME / MAO # Dump 5F / DEV / NST0 / HOME / MAO The first command # dump 0f / dev / nst0 / home / mao is a full backup of the / home / mao directory, and the back command is running, only the file that is changed after the discussion backup. Difference backup. Tip: In order to speed up the backup, the maximum block allowed by the tape drive can be used. For example, the block length used by the command # dump 0f / dev / nst0 / home / mao -b 2048 is 2048 bytes. can Use a larger block length to reduce backup time, but also to use the block you want to adapt when the restore command is used. If you want to back up the entire system, you can use u options, for example: # Dump 0uf / dev / nst0 / DUMP command option -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------- Options ---------------------------------- -------------------------- 0 ~ 9 dump level, 0 = complete backup, the difference backup is increment (1, 2, 3 .. ), And incremental backup storage numbers are decremented (8, 7, 6..) A Declaration Backup Directory Table F Compresss backups write files or devices J Level compressed, only definitely compressed, such as 2 or 4 t Date Specify Date, without using the date in / etc / dumpddates displayed U back up successfully updated / etc / dumpdates --------------------------- -------------------------------- 2, use the restore to restore the file list of the dump command backup using the restore command . E.g: # Restore -tf / dev / fd0 You can also search for the current backup with recovery search. RESTORE Command Options ----------------------------------------------- --------- Options --------------------------------------- ---------------- -C Comparison Backup and Current File -f Specified File-I Allows Backup Interaction Recovery, Several Commands in Recovery Mode - R in a new format partition Rebuild data - T list file name in the backup ------------------------------------- ----------------- end: I finally ended, although many problems didn't make it clear, I didn't say anything to burn backups using the CD, I have studied it myself. Improving. . . :-) In addition, some command references and references: http://www.jlu.edu.cn/~wyr/newcourse/linux/243.htmhttp://www.rlinux.net/index.php? Index = article_list & type = type_2 & type_2_id = 4 & Type_1_id = 5Http://www.douzhe.com/docs/rh9/rhl-gsg-en_cn-9/s1-managing-compressing-archiving.html Writetime: 2004-12-14 16:40 pm