Backup and Restore in Linux

Ratings:
(4.5)
Views:4124
Banner-Img
  • Share this blog:

How to do Backup and Restore in Linux

  • In information technology, a backup or the process of backing up is making copies of data that may be used to restore the original after a data loss event.
  • Backups have two distinct purposes.

1. The primary purpose is to recover data after its loss, be it by data deletion or corruption. Data loss is a very common experience for computer users. 67% of internet users have suffered serious data loss.

2. The secondary purpose of backups is to recover data from an earlier time, according to a user-defined data retention policy, typically configured within a backup application for how long copies of data are required.

  • Backup is the most important job of a system administrator as a system admin it is your duty to take a backup of the data every day.
  • Many companies have gone out of the market because of poor backup planning.
  • The easiest way to back up your first is just copying. But if you have too many files to backup, copying and restoring may take a too long time and it is not convenient. If there is a tool that can put many files into one file, the world will be better, fortunately, ‘tar’ is used to create archive files.  

Compression and Archiving

  • As you will learn when you become a system administrator, backups are the number one priority.
  • If something should crash or become corrupt and you can’t restore it because you aren’t keeping up with your backups or you just don’t keep any, you may be looking for a new job. Although we don’t address backup programs here, this is a good lead into archiving and compression.

 

 Tar

Tar means tape archiving

  • It is used for compressing and archiving files and directories
  • A more common use for tar is to simply combine a few files into a single file, for easy storage distribution.  

Syn:       tar          [options]             [FILE]

Options:          

  • c    -----> creates a new archive
  • v    -----> provides verbose output
  • f    ----->  specifies the archive file to use
  • t    ----->  lists the files in an archive
  • x   ----->  Extract the backup
  • z   ----->  Zipping
Inclined to build a profession as Linux Developer? Then here is the blog post on, explore Linux Training

Step 1:  Create some random blank files:

#touch file 1 file 2 files 3 another _file

Step 2: create a simple archive containing these files:

#tar –cvf              sample.tar file1  file2 file3 another –file

When an archive is created, you can also apply compression to reduce the amount of space the archive files takes up. Although multiple types of compression are supported with the use of tar we look only at gunzip (.gz) and bzip2 (bz2) here.

Step 3:  Let’s re-create the archive using the gunzip compression:

#tar        -cvzf sample.tar.gz           file1 file2 file3 another-file

Step 4: view the current directory to see the two current archive files:

#ls

Step 5: To see all the contents within the build file:

#tar –tvf sample.tar

Step 6: Now extract this build file verbosely:

#tar        -xvf sample.tar

Step 7:  To extract files on a different location

#tar – xvf sample.tar  -c  /root/desktop

 

Read these latest Linux Interview Questions that help you grab high-paying jobs

 

Cpio

cpio is a tool for creating and extracting archives or copying files from one place to another.

----->It handles a number of cpio formats as well as reading and writing tar files.

----->Cpio like tar but can read input from the “find” command

----->The basic structure is

:find –name        file/cpio [options]  [contraoller]  <dest>

Options:                             -o (out)                               Controllers:         O (or)  > -out

-i (in)                                                                  I   (or) > -in

Step 1: To take the backup files

#ls  file *  /cpio  -acvf  >/root/backup.cpio

Step 2: To see the backup content:

#cpio                    -it </root/backup.cpio

#cpio                    -it           -I /root/backup .cpio

Step 3: To restore the backup file:

#cpio  -icuvd  </root/backup.cpio

O      ----->           Reads the standard input

i        ----->           Extract files from the standard input

c      ----->           Read or write header information in ASCII character

d      ----->           Creates directories as needed

u       ----->           Copy unconditionally (older file will not replace a new file)

 

DD (Disk to Disk)

Used to take the backup of one partition to another, here source partition should be given to “if” destination partition should be passed to “of”

Step 1: To take the backup:

#dd        if=/dev/hda6      of= /dev/hda7

Step 2: To recovery:

#dd        if = /dev/hda7    of=/dev/hda6

 

SCP (Secure copy)

----->SCP is used to copy data from one Unix or Linux system to another Unix or Linux server.

----->SCP uses a secured shell (ssh) to transfer the data between the remote hosts.

----->The features of SCP are:

  • Copies files within the same machine
  • Copies files from the local machine to the remote machine
  • Copies files from the remote machine to the local machine
  • Copies files between two different remote servers.

Syn: SCP              [options]             [user from_Host: source_file]      {user to _host: Destination_file]

Options:              

-r   ----->         Recursively

-q   ----->        Progress bar not displayed

-v    ----->        Verbose mode

-p   ----->        copy files using the specified port number.

----->Copy file from local host to remote server:

#scp       filename              root@server254.example.com:/root

----->Copy files from the remote host to the local server:

#scp       root@server254.example.com:/root/backkup*    

• Current directory

----->Copying a directory:

#SCP –r directory root@server254.example.com: /root

----->Improving the performance of SCP command:

Using Blowfish or Arcfour encryption will improve the performance of the SCP command

#SCP   -c  blowfish filename  root@server254.example.com.com:      

----->Specifying the port number:

#SCP   -p  6001   backup-file          root@server254.example.com:/tmp

 

For an in-depth understanding of Linux click on

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.