Configure swap space and file system backup, and configure swap space backup

Source: Internet
Author: User
Tags rewind account security

Configure swap space and file system backup, and configure swap space backup

1. Overview of swap space:

Swap Space is a mechanism used by Linux to temporarily supplement physical memory to provide more memory Space. Swap Space is helpful for computers with limited memory, but cannot replace physical memory, because it is located on the hard disk, the access speed of the hard disk is several orders of magnitude slower than the memory. When many programs run at the same time and they cannot be loaded into the memory at the same time, the use of swap space is a very effective method, and the user can quickly switch between these programs, there may be a significant delay, Linux supports two forms of swap space: dedicated disk partitioning and file swap; High Disk partitioning efficiency, recommended, and more flexible swap files, but low efficiency, Linux can have up to 32 swap space, the maximum size of each swap space is 2 GB;

The recommended system swap space is as follows:

Swap space recommended by physical memory

No more than 4 GB at least 2 GB

4 ~ 16 GB at least 4 GB

16 ~ 64 GB at least 8 GB

64 ~ 256 GB at least 16 GB

256 ~ 512 GB at least 32 GB

1> increase swap space:

The adjustment of the system's physical memory, or operations that require a large amount of memory or running programs that require a large amount of memory, usually requires increased swap space. There are three ways to choose from: Create a swap partition, create a swap file and expand swap partitions on the existing LVM logical volume (this method is recommended );

1) Create an swap file for the swap space:

(1) determine the block size and number of new swap files. For example, the block size is 1 MB, the number of blocks is 200, and the entire space is 200 MB;

(2) Use the dd command to create a swap file, where of specifies the file name, bs and count are the block size and quantity;

(3) Use the mkswap command to create a swap space based on the above files:

                    

(4) use the swapon command to enable the swap space:

(5) run the swapon-s command to view all the currently enabled swap spaces. It can be seen that the new swap space/tmp/swapfile has been enabled, but the priority is low;

Of course, you can also use the free command to view the current swap memory size. The swap space set above is temporary and should be enabled automatically when the system starts, the corresponding definition must be added to the/etc/fstab file;

2> Expand the swap space based on logical volumes:

During Red Hat Enterprise Linux 5 installation, swap partitions are created on/dev/VolGroup00/LogVol0l logical volumes by default, and the swap space can be flexibly expanded using the features of logical volumes;

1) Disable swap space based on the corresponding logical volume:

Swapoff-v/dev/VolGroup00/LogVo101

2) increase space for existing logical volumes (256 MB)

Lvm lvresize/dev/VolGroup00/LogVo101 + 256 MB

3) re-create a swap space:

Mkswap/dev/VolGroup00/LogVo101

4) run the swapon-va command to enable the extended logical volume for swap space;

5) run the command cat/proc/swaps or free to check whether the extension based on the logical volume swap space is enabled properly;

3> Create a logical volume for the swap space:

Generally, logical volumes are created as swap spaces;

1) create a logical volume. The logical volume is named/dev/VolGroup00/LogVol02 and the size is 256 MB;

Lvm lvcreate VolGroup00-n LogVol02-L 256 M

2) use the mkswap command to format the new swap space:

Mkswap/dev/VolGroup00/LogVol02

3) Add the following entries to the/etc/fstab file so that the file system is automatically mounted when the system starts;

/Dev/VolGroup00/LogVol02 swap defaults 0 0

4) run the swapon-va command to enable the extended logical volume for swap space;

5) run the command cat/proc/swaps or free to check whether the swap space based on logical volumes is normally used;

4> reduce swap space:

Sometimes it is necessary to reduce swap space, such as reducing the physical memory and correspondingly reducing the swap space. There are also three options to choose from: delete all the entire LVM logical volumes in the SWAp partition, delete swap files or reduce swap space on existing LVM logical volumes;

1) Delete the swap file:

(1) run the swapoff command to stop the swap space;

                      

(2) Delete entries in the swap space from the/etc/fstab file;

(3) Use the rm command to delete the swap file itself;

2) reduce swap space based on logical volumes;

(1) disable the swap space of the corresponding logical volume;

Swapoff-v/dev/VolGroup00/LogVol01

(2) reduce the logical volume size:

Lvreduce/dev/VolGroup00/LogVol01-L-512 M

(3) reformat the new swap space:

Mkswap/dev/VolGroup00/LogVol01

(4) enable the logical volume for swap space and then test it;

3) delete a swap space based on logical volumes:

(1) disable the swap space of the logical volume:

Swapoff-v/dev/VolGroup00/LogVol02

(2) Delete the logical volume:

Lvremove/dev/VolGroup00/LogVol02

(3) Delete entries in the swap space from the/etc/fstab file;

2. File System Backup:

Backup is to keep a backup system, so that it is ready for use. It is one of the most important daily management tasks of the system administrator. Recovery is to restore data to the status before the accident. To ensure data integrity, back up the system;

1> Backup content:

In Linux, backups are classified into system backup and user Backup Based on the backup content. system backup is a backup of the operating system and applications, so that the system can quickly crash, simple and complete recovery of system operation, the most effective way is to back up only the data necessary for recovery after the system crash; user backup is different from system backup, the reason is that user data changes are more frequent. When user data is backed up, it only provides users with a virtual security network space to properly store backups of Recent user data files, in case of any problems, such as accidental deletion of certain files or hard disks, you can restore your data. User backup should be more frequent than system backup, data can be backed up by automatically running a program on a regular basis;

2> backup policy:

Before performing a backup, you must first select an appropriate backup policy to determine when the backup is required and how the backup is restored in case of a fault. The following backup methods are generally used:

1) Full backup:

A full backup of the system. If data loss or other problems occur during the backup interval, you can use the last backup to restore data to the data status before the backup. This method takes the longest time, however, the minimum recovery time and the most convenient operation are provided. When the data volume in the system is small, full backup is the most reliable;

2) Incremental Backup:

Only the added and modified data after the last backup can be backed up. This method can shorten the backup time and quickly complete the backup. However, the reliability is poor and there are too many copies of the backup data, this method is rarely used;

3) Differential backup:

Backup of newly added or modified data after the last full backup (instead of the last backup). This method has the advantages of full backup and Incremental backup, which takes a short time and saves space, the recovery is convenient. The system administrator only needs two copies of data to completely restore the system. This method is applicable to various backup scenarios;

3> Backup Planning

Professional backup work needs to be carefully planned, taking into account security and efficiency, rather than simply executing the backup program. The actual backup work mainly adopts the following two solutions:

Simple full backup:

This is the simplest backup solution, because each backup time, all files will be backed up. Each backup takes a long time, which is suitable for situations where the data volume is small or the data changes frequently;

Full backup combined with differential backup:

Perform full backup in a long period of time, and perform differential backup in a short period of time. For example, perform a standard backup every Saturday night and perform a differential backup every night, restore the last full backup Before restoring the full backup. if an accident occurs on Wednesday, the data can be restored to the status on Tuesday evening, restore the original full backup on Saturday, and then restore the differential backup on Tuesday;

3 Data backup operations:

In Linux, multiple tools and storage media can be used for backup;

1> use the tar command for backup:

Directly saving data occupies a lot of space. Therefore, backup files are often compressed to save storage space. tar is a command line tool used to package files, you can archive a series of files into a large file, or unbind the recovered data from the file as a common backup tool. The syntax format of tar is as follows:

Tar [Option] file or directory list

To back up files in your zhongxp home directory, run the following command:

Tar-czvf zxpbak.tar/home/zhongxp

The above command archives all the files in the/home/zhongxpdirectory (package them to the zxpbak.tarfile (the extension name is generally .tar), compress the data while archiving (Use Option-z );

To restore a file backed up by using the tar command (unbind the file), use option-x

Tar-xzvf zxpbak.tar

By default, tar restores the file to the current working directory. You can also use option-C to specify the directory to be restored;

2> using dump and restore for backup and recovery:

Dump is a professional backup tool that backs up all types of files, even devices. It supports full backup, Incremental backup, and differential backup, and cross-volume tape backup, retain the attributes and permission settings of the backed up files to correctly process file blocks (holes) that never contain any data. restore is the corresponding recovery tool, the dump and restore tools are installed in Red Hat 5 by default;

1) Use the dump command to back up data:

When using dump for backup, you must specify a backup level, which is an integer between 0 and 9, dump with level N backs up all files modified since the last dump with level less than N, and level 0 backs up completely, incremental backup, differential backup, and even daily backup can be easily implemented;

For example, the following command counts the space required for full backup/dev/sda1 to prevent the tape or disk space from being insufficient. Level 0 indicates full backup, and option-s indicates counting the space required for backup:

Dump-0 s/dev/sda1

Option-f specifies the path and name of the backup file.-A indicates updating the database file/etc/dumpdates (recording the file date, storage level, file system, and other information );

Dump-0u-f/tmp/boot. dump/boot

                            

                  

If-u is not used, all storage will change to level 0 because no records of the current file system have been backed up previously;

Level 1 only backs up changed files after full backup;

To implement Incremental backup, you can select level 0 for the first backup, and use Level 1, level 2, and level 3 for each Incremental backup;

Dump-0u-f/tmp/boot0.dump/boot

Dump-1u-f/tmp/boot1.dump/boot

Dump-2u-f/tmp/boot2.dump/boot

Dump-3u-f/tmp/boot3.dump/boot

To implement differential backup, you can select level 0 for full backup, and then use the same level greater than 0 each time, such as Level 1 each time:

Dump-0u-f/tmp/boot0.dump/boot

Dump-1u-f/tmp/boot1.dump/boot

Dump-1u-f/tmp/boot2.dump/boot

Dump-1u-f/tmp/boot3.dump/boot

Dump can store backups on tapes. in Linux,/dev/st0 is usually used to represent a rewind device, And/dev/nst0 is used to represent a non-Rewind device, as shown below:

Dump 0f/dev/nst0/boot

When a tape is used for storage, it is automatically replayed and then stored when the tape is used up. This overwrites the previous data, causing the risk of losing existing data;

2) use the restore command to restore:

You can use the restore command to recover data from a dump backup in two ways: Interactive and direct recovery. The administrator can also decide to recover the entire backup, or restore only the required files, Before restoring the data, to browse the data in the backup file, run the following command (-t option indicates viewing ):

                      

To restore a backup, run the following command (-r indicates reconstruction ):

Restore-rf/tmp/boot. dump

Run the following command to enter the interactive recovery mode:

Restore-if/tmp/boot. dump

3> Cd backup:

Red Hat 5 is installed with the cdrecord software package. You can use it to create and manage the disc media and use the disc for data backup. You must first create a disc image file and then write the image file to the disc:

For example, to back up data in the/home directory to a CD image file, run the following command:

Mkisofs-r-o/tmp/home. iso/home

The above command creates a name named home in the/tmp directory. iso image file, which contains all the content of the/boot directory. The-r option indicates that long file names are supported, and-o indicates that output is supported. By default, the mkisofs command also retains the ownership attributes and permission settings of the backup file. In addition to the mkisofs command, you can also use the dd command to create a disc image:

Dd if =/dev/sda1 of =/tmp/boot. iso

In the dd command, the if parameter specifies the input file and the of parameter specifies the output file. The if parameter of the dd command must be a file rather than a directory, here, when backing up the/boot directory, the actual used parameter is/dev/sda1, that is, the disk partition corresponding to the/boot directory;

The recorder is recognized as a SCSI device in Linux. Even if the device is actually an IDE device, you can use the following command to detect the burning device before actually burning the disc, obtain the SCSI device identification number of the disc Burner for use in the tool for burning the disc;

Cdrecord-scanbus

The first three digits of the preceding command are the SCSI bus, device identifier, and LUN (logical unit number,). These three digits are required for running cdrecord burning:

The syntax format for using the cdrecord command to burn an ISO file to a CD is as follows:

Cdrecord-v-eject <speed = burning speed> <dev = recorder device identification number> <ISO file name>

-Eject indicates that a disc is displayed after being burned. For example, if the recorder device identification number is 0, 1, and 0, run the following command to burn the image file to a blank disc:

Cdrecord-v dev = 0, 0 home. iso

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.