Backup and restore the Linux system – Introduction
Backup and restore the Linux system is hard for some users but we make linux easy for you. So, here it is
In information technology, making a copy of the file can be used to restore original data when data is lost is known as a backup or the backing up process.
Backups serve two different purposes.
The primary objective is to restore lost data, whether due to corruption or data erasure. Computer users frequently face data loss. Internet users have lost important data in 67% of cases.
By using a user-defined data retention policy, which is frequently established inside a backup tool to determine how long copies of data must be retained, The second purpose of backup is to restore historical data.
Here are a few simple methods for backup and restore the Linux system
-
Tar
Multiple files and directories are compressed and archived using tar, which stands for tape archive, and is used to create a tarball for convenient storage distribution. It uses tar, gzip, and bzip to make backups.
For Linux Server Backup
Construct a tar backup.
# tar -cvf backup_name.tar /home/user
Create a tar.gz backup.
# tar -cvfz backup_name.tar.gz /home/user
Leave the files out.
# tar –exclude file.txt –exclude file.sh -cvfz backup_name.tar.gz
Obtain data from a backup.
# tar -xvfz backup_name.tar.gz /backup/directory/file.txt
Create a new backup directory, exclude the last backup you made, then gzip archive every file on the server. A maintenance mode on the server should not be present, so check.
sudo tar –cvpzf backup_name.tar.gz –exclude=/home/server/backup.tar.gz –one-file-system
Linux Server Recovery
Restore the backup tar.gz file.
# tar -xvpf /media/your_harddisk/backup.tar.gz
-
Using Cpio
A file archiver program called Cpio, or copy in/out, allows users to build and extract archives or copy data to another location.
Parameters
- O: Reads from the standard input.
- I: Files are removed from the standard input.
- C: Reading and writing ASCII character header data.
- D: as necessary, creates directories
- U: Unrestricted copying; an outdated file won’t take the place of a new one
For Backup
Back up the files.
#ls file * /cpio -acvf >/root/backup.cpio
Look at the backup material.
#cpio -it </root/backup.cpio
#cpio -it -I /root/backup .cpio
For Recovery
Restore the backup files.
#cpio -icuvd </root/backup.cpio
-
DD (Disk to Disk)
Used to copy a partition’s backup to another, the source partition should be sent to the “if” operator here, and the destination partition should be passed to the “of” operator.
For Backup
Make a backup.
#dd if=source_partition of=destination_partition
Without making a backup file, replicate the partition with the current partition.
dd if=existing_source_partition of=destination_partition
For Recovery
Onto a different bare disc, restore the backup partition.
#dd if=destination_partition of=another_empty_partition
-
Using SCP and Timeshift
SCP (Secure Copy) transfers data between Unix/Linux systems on the same machine, between local and distant machines, or between several remote servers.
Linux Server Backup
Preparation
Possess the necessary rights to copy files on the destination machine.
Have a public key that has been authorized or an account on the target computer.
Have write permission on the target computer and read permission on the source computer.
Copy files from the local computer to the remote server.
#scp filename root@serverxxx.example.com:/root
from a remote server, copy files to a local server.
#scp root@serverxxx.example.com:/root/backup*
Replicate a directory.
#scp –r directory root@serverxxx.example.com: /root
Utilise arcfour or blowfish encryption to boost performance.
#scp -c blowfish filename root@serverxxx.example.com.com:
Put the port number in.
#scp -p xxxx backup_file root@serverxxx.example.com:/tmp
For Recovery
On various Linux distributions, there is a system restoration utility called Timeshift that enables point-in-time recovery.
- In the terminal, install Timeshift.
On Ubuntu and derivatives:
sudo add-apt-repository -y ppa:teejee2008/timeshift
sudo apt-get update
sudo apt-get install timeshift
On Fedora, CentOS, and RHEL:
sudo dnf install timeshift
Manjaro and Arch Linux:
yay -S timeshift
- Search for Timeshift in the Applications menu before launching it. Press Authenticate after entering your credentials.
Customize the Setup Wizard’s settings.
Select either Rsync or Btrfs as the snapshot type, then click Next.
Click Next after choosing a place for the Timeshift pictures.
Choose a snapshot frequency depending on how frequently you alter the system components.
Click Next after selecting the snapshot levels.
Select whether to backup your home folder to a snapshot and then click Next.
To finish, click.
When the system is operating, choose the desired snapshot and click Restore in the main window.
-
Using Rsync and Cronopete
Users often use the Linux-based rsync utility to transfer and synchronize files and directories locally, from a remote shell with other hosts, or with a remote rsync daemon.
Linux Server Backup
Use the ‘fdisk -l’ command to find the drive letter on the backup media.
Run the given commands after opening your terminal.
$ sudo rsync -aAXv / –exclude={“/dev/*”,”/proc/*”,”/sys/*”,”/tmp/*”,”/run/*”,”/mnt/*”,”/media/*”,”/lost+found”} /target_folder
Except for the /dev, /proc, /sys, /tmp, /run, /mnt, /media, and /lost+found folders, the whole root directory is backed up and saved in the target folder.
Back up mail folders and a home directory with huge MS Word files:
rsync -aiz . bkhost:backup/user_name/
Linux Server Recovery
Time Machine’s Linux equivalent, Cronopete, is a Mac backup application. All user files on a separate hard drive can be copied and restored, but not the operating system as a whole.
Run the following command into the terminal after installing Cronopete:
$ cronopete
On the welcome page, click Configure right away.
Connect the USB or external HDD, then select Change disc.
Select your USB disc by clicking the Select button. For additional backup discs, repeat the procedure.
To format the discs for backups, click Format disc.
By default, the utility immediately starts backing up the whole $HOME directory. The Options section allows you to set the backup items and the time gap between backups.
Right-click the Cronopete icon in the menu and choose Recover files to recover the data. Click Restore files in the top left after selecting the source files or folders from the backup USB.
-
Using Bera
Bera is a backup solution that makes it simple to back up all of your key files, directories, and server configurations. As a result, you can effortlessly move or restore them to a different server, ensuring seamless data migration and recovery processes. This user-friendly backup tool streamlines the entire backup and restoration workflow, enabling you to safeguard your critical data with ease. This utility can move a sophisticated server in 10m and do full backup and recovery. It uses SSH to encrypt communication and can exclude domains, files, and directories.
For Backup
Preparation:
Ubuntu server
Rsync
SSH
Both the source and the target computers have root access.
- To configure the server, install the SO, configure the network, install packages, etc.
- Utilising Bera, download service settings, files, directories, and more.
- Set permissions on the following files before uploading them to the server:
chmod +x bera-backup.sh
chmod +x bera-restore.sh
Each script’s configuration file must include examples such as _bera_restore_config_example and _bera_backup_config_example.
A Linux server backup in the specified folder:
./bera-backup.sh PATH_TO_CONFIG_FILE
-
Linux Server Recovery
Download the server backup, then do the restore:
./bera-restore.sh PATH_TO_CONFIG_FILE
Final Words
The most crucial responsibility is backup and restore the Linux system, which you are required to perform daily.
Poor backup preparation has led to the demise of several businesses.
Just copying is the simplest approach to make a backup of your first. However, copying and restoring may take too long and be inconvenient if there are too many files to back up. The world would be a better place if a program could combine several files into a single file; thankfully, ‘tar’ is used to build archive files.
Links
You can learn about linux more deeply by clicking the link below
https://linuxiron.com/what-is-linux-a-whole-introduction/
Links
Learn about the linux commands by clicking the links below
https://linuxiron.com/echo-command-in-linux/
https://linuxiron.com/how-to-use-nice-renice-commands-in-linux/
https://linuxiron.com/how-to-use-kill-commands-in-linux/
https://linuxiron.com/a-beginners-guide-to-htop-for-process-management/
https://linuxiron.com/15-useful-yum-commands-in-linux/
https://linuxiron.com/how-to-use-the-top-command-in-linux/
https://linuxiron.com/17-ps-command-to-monitor-linux-process-with-examples-linuxiron/
https://linuxiron.com/12-cat-commands-in-linux-with-examples/
https://linuxiron.com/archiving-and-compressing-files-and-directories-in-linux/
https://linuxiron.com/how-to-run-the-du-command-in-linux/
Utilizing backup utilities like tar, cpio, ufsdump, dump, and restore in Linux, you may backup and restore files. These instructions are not necessarily useful for small machines. However, you should use a dedicated backup and restore location for large backups. These consist of Amanda, Symatic NetBackup, or EMC Networker.
cpio. This will show a list of the files and folders that were backup-included. Using Linux’s cpio command, you can back up your data in the manner described below. By extracting the contents from the backup archive with the cpio command’s -i option, you can later restore these data.
The rsync command line software is the most widely used tool on Linux systems for many reasons. It allows you to create a continuous file containing the entire directory tree of local and remote servers. Even better, you can perform backups with a shell script and cron jobs.
Without requiring any specific knowledge of the file system’s underlying structure, the restore command restores the files on a file system archive. The restore command produces and uses a file called restore symtable when you restore the file system archives. The current directory is where this file is produced.
All user data, which is often composed of static files that are easy to restore, is typically stored in the /home directory. Therefore, utilizing the backup home directory with Linux is an effective technique to back up user data.
The process of backing up the operating system, files, and other crucial or practical information for the system is known as system backup. Additionally, it essentially makes sure that a system’s state or operating condition, as well as user data, are saved.