Six applications and skills of Linux system backup optimization

When switching to Linux , you may notice that your version comes with a default backup utility. However, it is possible that the tool is not set up to backup all important parts of your system. Also, using the default tool may cause it to generate some larger backup data less efficiently than expected. This article will introduce you to some alternative methods that can use existing storage space to backup your Linux system .

Make sure your backups are just right

The default tool for the Ubuntu desktop: dejá-dup is only set up to back up your home directory by default, so it leaves out some important parts when you need to restore your system to an orderly working state. Let's imagine that your system consists of the following three parts:

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

Then, you can easily set up the default tool to support all the content of the above three parts. But this is only possible if you have a lot of storage space, or it may involve a lot of data being transferred over the Internet (if you are using network backup). Here are some apps and tips that can help you reduce the storage space you need and make sure you still have proper backups in the event of a system crash.

1. Clone the partition to take a snapshot of the Home directory

Some data is stored in the /home/[username] directory of your user account. These include your personal configuration. They are usually files starting with a "dot" (such as /home/[username]/.local) or directories, and music, pictures, and other types of files and folders (for example, the default documents path or downloads folder). These are the areas where you may need to pay special attention when backing up your data, and when dealing with "out of the box" tools.

One big reason you want to put the /home directory on a separate partition is so that you can operate it independently from the main part of the system. Also, if you do this, you can back up your home directory by cloning the entire partition. It also enables precise disk-level recovery when you need it.

As I mentioned in a past article, one of the options is dd, which does a full clone of a disk or partition (meaning that all partitions are backed up to the same size). Of course, you can also consider using Clonezilla. While it is backing up the overall structure of the disk/partition, it can omit unused disk space, so that your backup is only the partition size occupied by the actual data.

2. Use the file synchronization tool to store the snapshot of the Home directory on multiple machines

A file synchronization tool is a good choice for you to manage your personal files, especially when you use multiple devices. You can think of too many names for such tools, including simple file copying tools such as rsync; online services such as Dropbox; and local/peer-to-peer tools such as Resilio Sync, etc. Some of these will provide you with tracking and history services, although these minute-by-minute changes can be "picky" and a waste of storage space.

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

3. Use archiving tools to keep historical snapshots of system data

In addition to your home directory, you may want to add the following to your backup list:

  • /etc, which contains various configurations, such as /etc/apt/lists descriptively lists the newly installed program resources on your system.
  • /var, which contains supplementary data used by various applications. Examples of this include various logs (such as /var/log/dpkg, which records package transactions on .deb-based systems) and caches (such as /var/cache/dpkg, which keeps copies of all installed packages), and /var/lib/dpkg (database used to store packages).

Standard "archive-style" backup tools can also handle these system directories. They usually check the files in the source directory to see if a recent backup of the file exists, and if not, create and update it. They can keep multiple copies (such as daily or weekly), and these copies are usually compressed to save disk space. There are many such tools, including the programs dejá-dup and backintime, among others.

However, you may need to be root to set up and run such backup jobs, or use admin privileges to use the tool's built-in features.

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

By using these applications (backintime is used as an example below), you can simply add the directories you need to a new or existing backup job:

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

By properly filtering these directory backups, you can compare the disk space savings of this with a typical "full system" backup and see the effect. You can browse the links below for tips on which /var subdirectories you might need and which you don't. ( backup - What directories do I need to back up? - Unix & Linux Stack Exchange )

4. Use etckeeper to keep records of configuration changes

Let's talk about the /etc directory specifically. The tool etckeeper uses source-level control to help you back up important configurations in your system. If you want to install it in Ubuntu, you need

sudo apt-get install etckeeper

During the install, it will create a backup (actually a git repository) and put all the files under /etc into it.

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

After this, you can use any git client to view the historical version of your system configuration. What's more, the software is also set up with a cron job that puts your configuration changes into it daily. Also, given that most configuration files are created in plain text, and since git (and other source control systems) store changes on a line-by-line basis, for multiple version stashes, Its capacity can still be kept relatively small.

5. Use aptik to backup various configurations and packages

The aptik program integrates a large number of backup/restore tools on its friendly GUI interface:

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

Its "Installed Software" feature will by default back up all packages you have explicitly installed. The image below is a very short list of examples:

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

You might be wondering: why is it so short? It's because by the time you need to use the backup, you obviously have a base system installed, so it doesn't need those base system packages. And if you need to install these dozens of listed packages, its package manager will automatically take care of the installation of all associated dependent packages for you. It can be seen that your "full software backup" will only consume tens of megabytes of storage space. Smart enough?

6. Use the package list to back up your packages

If you are familiar with command line operation, you may do better than aptik. In case you can restore your system later, you can try the following command . Note that this command is not used to back up soft packages, but to record a list of packages. That is, the following command will export the list of installed packages to a text file:

sudo dpkg --get-selections > my-packages.txt

In addition to giving you a human-readable statistic of system packages (as shown above), the following command also allows you to batch reinstall these packages:

sudo dpkg - set-selections < my-packages.txt

Six Applications and Techniques of Linux System Backup Optimization Six Applications and Techniques of Linux System Backup Optimization

sudo apt-get - u dselect-upgrade

Note that you still have to manually handle programs that you have installed yourself (they are likely stored in /usr/local and/or /opt). Other than that, the only difference between your old and freshly restored system is whether or not the various software needs to be manually updated to the latest versions. And these only take up a few kilobytes of disk space.

Remember: please don't stick to one of the above applications, you can combine multiple applications to ensure that when the worst happens, you can still quickly perform backup and recovery.

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/131753223