Home Linux Backup How to Backup and Restore CentOS Server Directories or Full Server?

How to Backup and Restore CentOS Server Directories or Full Server?

2023-04-20 | Nick Zhao

Table of contents
  • How to Backup CentOS server with TAR command?
  • How to backup CentOS server with dd command?
  • How to backup CentOS server with rsync command?
  • Backup CentOS server with Vinchin Backup & Recovery
  • Sum Up

Are you looking for a robust CentOS server backup solution? Try Vinchin Backup & Recovery!

CentOS is often used as the operating system of server because of its stability. To maintain the IT environment, it is necessary to backup data. In this post, you will know how to backup CentOS server in 4 ways.

How to Backup CentOS server with TAR command?

Linux system is often managed by commands and you can use tar command to backup the full server or certain directory because unlike Windows, Linux doesn’t restrict users from extracting or importing anything so you can put every file in the directory into the tar file as data backup.

Benefits of creating backup with tar command

● Preserves permission

● Backups the whole directory

● Provides different compression methods

● Provides incremental backup and granular restore if compression is not enabled

The command to create a full CentOS server backup:

tar cvpzf backup.tgz / --exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=backup.tgz

tar: the command to extract archive files

cvpfz: the options of tar command, to create an archive file, preserve permission, and enable gzip compression.

backup.gz: the name of the backup file

“/”: the directory to backup

exclude: excludes the useless directory

Some directories are useless so you can exclude them like “/proc”, “/lost + found”, “/sys” and the backup file backup.gz should be excluded or there will be a loop. “/mnt” should be also excluded or the partitions mounted in it will be backed up, too. Likewise, you should check whether there is a DVD or external hard drive mounted in “/media”. If so, exclude this directory, too.

It might take a long time to create the backup file. You might see a notification like “tar: Error exit delayed from previous errors”. In most situations, you can omit it. After that, backup,gz will be generated in the root directory.

Compress backup with bzip2

If you want a better compression ratio, you can use bzip2 but the speed will be slower.

tar cvpjf backup.tar.bz2 / --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys

Recover CentOS server

The recovery process is namely rewriting the directory with the backup file so you should log in to the server as a root user, copy the backup file to the root directory of the partition and then recover the server with tar command.

If you used gzip before, you should recover the server with the command:

tar xvpfz backup.tgz -C /

If you used bzip2 before, you should recover the server with the command:

tar xvpfj backup.tar.bz2 -C /

Don’t forget to recreate the directories excluded before.

mkdir proc

mkdir lost+found

mkdir mnt

mkdir sys

It is necessary to restore SELinux Type or you will be kept asking to enter the user name and password after rebooting the server.

Run the command below to restore SELinux Type:

restorecon -Rv /

restorecon: restores SELinux Type

R: also modifies the subdirectories

v: present the process in screen

How to backup CentOS server with dd command?

Since you need to backup the files in CentOS, dd command can help you clone the files.

Benefits of creating backup with dd command

● Operates the blocks

● Provides full disk backup

● Provides data compression

There is one thing you should that because it is a full disk backup, the “blank space” will be copied, too.

The command you need to clone CentOS files is:

sudo dd if=/dev/sda1 of=/dev/sdb1

if: the source directory

of: the destination directory

How to backup CentOS server with rsync command?

Rsync is a powerful tool to let you quickly sync data between servers via LAN/WAN. Its Rsync algorithm syncs file by transferring only the different parts of the file so that the speed is fast. Although the command is simple, you need to configure the source server and backup serve with complicated procedures so the procedures will not be presented in this post.

The command you need to backup CentOS server is like:

rsync -avz --password-file=/root/passwd rsyncAdmin@192.168.1.121::common /home/backup2/ >/home/backup/rsync.log 2>&1

Backup CentOS server with Vinchin Backup & Recovery

Backing up server with commands might be not good for later management so you can try an integrated backup solution.

Vinchin Backup & Recovery is a professional backup solution for CentOS 8.3/8.2/8.1/8.0/7/6 and also the virtual CentOS server on VMware vSphere, Hyper-V, XenServer, Red Hat Virtualization, Oracle Linux KVM, etc.

There will be a user-friendly web console to help you easily backup the server with strategies like creating a schedule to backup the server automatically, using incremental backup to increase backup speed and reduce backup size, enabling data encryption to improve data security, etc.

If you want to backup a physical server, just install an agent to add the server to Vinchin backup system > select the server as backup source (there is file backup option for selecting directories)> select backup destination > select backup strategies > confirm the job

Vinchin Backup CentOS Server

If you want to backup a virtual server, just add its host to add all the VMs on it agentlessly > select the virtual server as backup source > select backup destination > select backup strategies > confirm the job

Vinchin Virtual Server Backup

With this professional solution, you can increase the efficiency of your backup and recovery plan. Vinchin Backup & Recovery has been selected by thousands of companies and you can also start to use this powerful system with a 60-day full-featured free trial. Just click the button to get the installation package.

Sum Up

CentOS is a popular operating system for server. To protect data and business continuity, you can backup CentOS server with commands like tar, dd, and rsync.

If you would like to build a highly-efficient backup system, you can choose Vinchin Backup & Recovery. Don’t miss the free trial.

Share on:

Categories: Linux Backup