Determine what to back up
The file-based nature of Linux is a great advantage when backing up and restoring a system. In Windows systems, the registry is very relevant to the system. Configuration and software installation is more than just putting files on the system. Therefore, restoring a system requires software that can handle the features of Windows. In Linux, the situation is different. Configuration files are text-based and, in addition to working directly with the hardware, are largely system-independent. The modern approach to hardware drivers is to make them available in the form of dynamically loaded modules so that the kernel becomes more system independent. Unlike the complex details that make a backup have to deal with how the operating system is installed on the system and hardware, Linux backup processes the packaging and unpacking of files.
In general, the following directories need to be backed up:
- /etc
Contains all core configuration files. This includes network configuration, system name, firewall rules, users, groups, and other global system entries.
- /var
Contains information that is used by the system Daemon (service), including DNS configuration, DHCP tenancy, mail buffer files, HTTP server files, DB2 instance configuration, and so on.
- /home
Contains the default user home directory for all users. This includes their personal settings, downloaded files, and other information that the user does not want to lose.
- /root
is the root (root) user's home directory.
- /opt
is where many non-system files are installed. The IBM software is installed here. OpenOffice, JDK, and other software are also installed here by default.
Some directories should be considered for non -backup.
- /proc
You should never back up this directory. It is not a real file system, but a virtualized view that runs the kernel and environment. It includes files such as/proc/kcore, which are virtual views of the entire running memory. Backing up these files is just a waste of resources.
- /dev
Contains the file representation of the hardware device. If you plan to restore to a blank system, you can back up/dev. However, if you plan to restore to an installed Linux system, it is not necessary to back up/dev.
The other directories contain system files and installed packages. In a server environment, much of this information is not customized. Most customizations occur in the/etc and/home directories. However, for completeness, you might want to back them up.
In a production environment, I wanted to make sure that the data was not lost, so I backed up the entire system except for the/proc directory. If you are most concerned about users and configurations, I will only back up the/etc,/Var,/home, and/root directories.
Back to top of page
Backup tools
As mentioned earlier, Linux backup is to a large extent packaged and unpacked files. This allows the use of existing system utilities and scripts to perform backups without the need to purchase commercially available packages. In many cases, this type of backup will be sufficient and gives administrators great control. Backup scripts can be cron
automated using commands that control the scheduled events in Linux.
Tar
tar
is a classic UNIX command that has been ported to Linux. tar
is the abbreviation for Tape archive (tape archive), originally designed to package files on tape. If you have downloaded the Linux source code, you may have encountered a tar file. This is a file-based command, which is essentially a sequential, end-to-end stack of files.
Use tar
can package the entire directory tree, which makes it particularly suitable for backup. The archive can be restored in its entirety, or a separate file and directory will be expanded from it. Backups can be saved to a file-based device or tape device. Files can be redirected at restore time so that they are re-placed in a different directory (or system) than the directory (or system) in which they were originally saved. is not related to tar
the file system. It can be used on ext2, ext3, JFS, Reiser, and other file systems.
Use tar
a file utility that is very similar to using files such as PKZip. Just point it to a purpose (which can be a file or device), and then specify the files you want to package. You can compress the archive dynamically with a standard compression type, or specify an external compression program of your choice. To compress or unzip a file by bzip2, you can use the tar -z
command.
To use tar
to back up the entire file system except the/proc directory to a SCSI tape device:
Tar-cpf/dev/st0/--exclude=/proc
In the example above, the -c
switch indicates that the archive file is being created. The -p
switch indicates that we want to keep the file permissions, which is critical for good backups. The -f
switch points to the file name of the archive file. In this example, we are using the original tape device/dev/st0. /indicates what we want to back up. Since we want to back up the entire system, this switch is specified as root (root). When tar
you point to a directory (at/end), it automatically recursively. Finally, we exclude the/proc directory because it does not contain anything that needs to be saved. If the single-cassette tape does not fit this backup, we need to add a -M
switch (not shown in this example) for a multi-volume backup.
Case
Don't forget that Linux is case-sensitive. For example, a tar
command should always be executed in lowercase. Command-line switches can be in uppercase, lowercase, or case-sensitive blending. For example, -t
and -T
perform different functions. File or directory names can be mixed with case, and are case-sensitive like command and command-line switches.
To restore one or more files, you can use the command with the extract switch ( -x
) tar
:
TAR-XPF/DEV/ST0-C/
The -f
switch here also points to the archive, and the -p
switch indicates that we want to restore the archived permissions. The -x
switch indicates that the file was extracted from the archive. -C /
indicates that we want to get the restore from/to start. tar
typically revert to the directory where this command is run. -C
The switch makes our current directory no longer relevant.
The other two commands you may often use tar
are -t
and -d
switches. -t
switch lists the contents of an archive file. The -d
switch compares the contents of the archive file with the current file on the system.
For ease of operation and editing, you can put the files and directories you want to archive in a text file, and then reference the text file on the command line via a -T
switch. These files and directories can be combined with other directories listed on the command line. The following command line backs up all the files and directories listed in MyFiles, the/root directory, and all ISO files in the/tmp directory.
Tar-cpf/dev/st0-t Myfiles/root/tmp/*.iso
A file list is just a text file that lists files or directories. Here is an example:
/etc
/var
/home
/usr/local
/opt
Note that the tar -T
(or files-from
) command cannot accept wildcard characters. The file must be explicitly listed. The example above shows a way to refer to a file separately. You can also execute a script to search the system and then create a list. Here is an example of such a script:
#!/bin/sh
Cat MyFiles > Templist
Find/usr/share-iname *.png >> templist
Find/tmp-iname *.iso >> templist
Tar-cpzmf/dev/st0-t templist
The above script first copies all the existing file lists in MyFiles to Templist. It then executes two find
commands to search files in the file system that match a pattern and attach them to the templist. The first time is to search all the files in the/usr/share directory tree to .png
end. The second is to search .iso
all files at the end of the/tmp directory tree. After the list is established, tar
a new archive file is created on the file device/dev/st0 (the first SCSI tape device), which is compressed using the G- zIP format and retains all file permissions. The archive file will span multiple volumes. The name of the file to be archived is extracted from the Templist file.
You can also use scripts to perform finer-grained operations, such as incremental backups. Gerhard Mourani a good script in his securing and optimizing Linux book, and you can find information about this book in resources at the end of this article.
You can also write a script to restore the file, although the restore is usually done manually. As mentioned above, the switch used to extract the file instead of the -x
-c
switch. You can restore the entire archive, or restore the specified individual files or directories. It is possible to use wildcards to refer to files in an archive file. You can also use switches to dump and restore.
Back to top of page
Dump and restore
dump
You can perform tar
a similar function. However, there dump
is a tendency to consider file systems rather than individual files. Here's what's quoted in the Dump manual file: "Dump checks the files on the ext2 file system and determines which files need to be backed up." These files will be copied to a given disk, tape, or other storage media for security protection ... Dumps larger than the output media capacity are divided into multiple volumes. On most media, the capacity is determined by writing until a End-of-media tag is returned. ”
The program that mates with dump
is restore
that it is used to restore files from the dump image.
restore
command to perform the reverse function of the dump. A full backup of the file system can be restored first, and subsequent incremental backups can be overwritten on top of the restored full backup. You can restore a separate file or directory tree from a full or partial backup.
dump
And restore
both can be run on the network, so you can back up or restore from a remote device. dump
and restore
use tape drives and file devices that offer a wide range of options. However, both are limited to ext2 and Ext3 file systems. If you are using JFS, Reiser, or other file systems, you will need other utilities, such as tar
.
Back to top of page
Perform a backup using dump
Using dump
the perform backup is fairly straightforward. The following command performs a full Linux backup, which backs up all ext2 and ext3 file systems to a SCSI tape device.
Dump 0f/dev/nst0/boot
Dump 0F/DEV/NST0/
In this example, there are two file systems in the system. One for/boot, the other for / , this is a common configuration. They must be referenced separately when performing a backup. The/dev/nst0 refers to the first SCSI tape drive, but is referenced in a non-heavy-wound mode. This ensures that each volume is arranged one by one on the tape.
dump
An interesting feature of this is its built-in incremental backup functionality. In the example above, 0 indicates a level 0 or basic level backup. This is a full system backup that you want to perform periodically to save the entire system. For subsequent backups, you can use a different number (1-9) instead of 0 to change the backup level. A Level 1 backup saves all files that have been changed since the level 0 backup was performed. A Level 2 backup saves all files that have been changed since the level 1 backup was performed, and so on. tar
the same functionality can be performed by using and scripting, but requires the script creator to provide a mechanism to determine when the last backup was performed. dump
has its own mechanism, that is, it outputs an update file (/etc/dumpupdates) when performing a backup. This update file will be reset each time a level 0 backup is performed. Subsequent levels of backups retain their marks until another level 0 backup is performed. If you are performing a tape-based backup, dump
multiple volumes are automatically tracked.
Skip a file
It dump
is possible to mark files and directories that will be skipped. The command to accomplish this is chattr
to change the extended properties on the ext2 and ext3 file systems.
Chattr +d <filename>
The above command adds a tag to the file so that dump
the file is skipped when the backup is performed.
Back to top of page
To perform a restore by using restore
To restore dump
the use of saved information, you can use the restore
command. Like tar
, the dump
ability to list ( -t
) The contents of an archived file and compare it to the current file ( -C
). dump
the place to use caution is to restore the data. There are two very different ways to restore, and you must use the correct method to get predictable results.
Rebuild (-R)
Remember, the design is dump
more about file systems than individual files. Therefore, there are two different types of file restore styles. To rebuild a file system, use a -r
command-line switch. The purpose of the design rebuild is to be able to operate on an empty file system and restore it to a saved state. You should have created, formatted, and mounted (mount) the file system before performing the rebuild. You should not perform a rebuild on the file system that contains the file.
The following is an example of a full rebuild using the dump performed above.
Restore-rf/dev/nst0
The above command needs to be executed separately for each file system to be restored.
You can repeat this process to add incremental backups when needed.
Extract (-X)
If you need to use separate files instead of the entire file system, you must use -x
switches to extract them. For example, to extract the/etc directory from our tape backup only, use the following command:
Restore-xf/dev/nst0/etc
Interactive Restore (-i)
restore
Another feature provided is the interactive mode. Use the command:
Restore-if/dev/nst0
You will be placed in an interactive shell and also display the items contained in the archive. Typing "help" will display a list of commands. You can then browse and select the items you want to extract. It is important to remember that any files that you extract are entered into the current directory.
Back to top of page
Dump and Tar
dump
And tar
all have a group of advocates. Both have advantages and disadvantages. If you are running any file system other than ext2 or ext3, dump
you will not be available to you. If this is not the case, however, you can run with the fewest scripts dump
and dump
have interactive patterns that you can use to help with the restore.
I tend to use it tar
because I like to write scripts to get extra levels of control. There are also multi-platform tools for manipulating. tar files.
Linux Backup and Recovery