Unix/Linux System Automation Management: Data Backup and Synchronization

  
                  

Data is the most important part of a Unix/Linux system, but backing up and synchronizing data is the most overlooked task. With regular data backup and synchronization, data loss can be minimized in the event of a disk failure. When the user accidentally causes data corruption or loss, it can be quickly recovered.


Data backup is different from the entire system backup, classifying different data according to priority, and backing up important files according to user needs.


This makes data independent of the operating system, reducing backup costs and time.


Different operating systems may use different data backup methods. This article describes common Unix/Linux utilities (tar and cpio), standard AIX utilities (mksysb and backup), and remote Backup tool rsync.


Determining Backup Strategies


In a business environment, you must first determine which files need to be backed up and how long it takes to back up. If you back up too many files, the cost of the backup system will be too large, resulting in unnecessary expenses. If you do not back up enough data, it may lead to the loss of important data, but it will bring more losses.


Of course, backing up the entire system is straightforward, but often such backups are wasteful and meaningless. Starting from reducing the cost of the backup system, only when some data is important enough to be shared, is it necessary to have a backup.


Basic data is generally divided into the following categories:


•User data: all user data and user directories, and private files.

•System Information: System users, groups, passwords, host lists, etc.

•Applications: Services launched on the system, such as web applications, apache, etc.

•Application configuration files and data: for different applications, different configuration parameters and important data files.

•Database: In fact, the database can provide backup and synchronization functions for all data in the database.

Simple data backup refers to backing up all data at once, and then backing up the changes made since the last backup. The first backup is a "full backup" and the latter backup is an "incremental backup." Usually suitable for personal or small websites. For organizations or large websites, “multi-level backup” is required. Set the full backup to level 0, and the levels of incremental backups are 1, 2, 3, and so on. At each incremental backup level, you can back up changes since the last backup of the peer or previous level.


For example, if we have 10 disks, if we use a simple backup for daily backup, we can recover the data within two weeks.


If you use multi-level backup, for example:


Tape 1-2, monthly backup, first Friday of each month

Tape 3-6 Weekly backup, weekly Friday (excluding the first week)

Tape 7-10, daily backup, weekly Monday to Thursday, you can extend the backup history to two months.


Utilities and Commands


tar Commands


The tar command is a more versatile Unix/Linux archive command. Tar packages one or more files and directories into a single file and maintains the original file size, owner, permissions, file type, and its location in the file system hierarchy. Tar is an acronym for tape archive and is the easiest data backup utility to use.


Table 1. Common parameters of the tar command:

To create an archive file of /CriticalData, use:


# tar -czvf Backup.tar.gz /CriticalData/


To restore this directory, use:


# tar -xzvf backup.tar.gz /CriticalData/


tar performs well in extracting files and smaller directories. If you want to restore filesystems and volume groups, we prefer cpio or a more specific Linux/Unix data backup utility.


cpio Command


cpio is a versatile Unix/Linux archive command similar to tar. It is generally used to back up and restore files and directory structures.


Table 2. Common parameters for the cpio command:

Archive the /CriticalDate directory and all its files and subdirectories using:

< BR># find /CriticalData/-depth

Copyright © Windows knowledge All Rights Reserved