Backup & Restore
 How to do Backup & Restore in Linux
In information technology, a backup or the process of backing up is making copies of data which may be used to restore the original after a data loss event.

Backup have two distinct purposes.

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

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 backup of the data every day.

Many companies have gone out of the market because of poor backup planning.

The easiest way to backup your first is just copying. But if you have too many files to backup, copying and restoring may take too long time and it is not convenient. If there is a tool that can put many fiels 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 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

At TekSlate, we offer resources that help you in learning various IT courses. 
We avail both written material and demo video tutorials. 

To gain in-depth knowledge and be on par with  practical experience, then explore Linux Training Online.

Step 1:  create some random blank files:

#touch file 1 file 2 file 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 fies:

#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 different location

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

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 iinput from the “find” command

----->The basic structure is

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

Optons:                             -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 secured shell (ssh) to transfer the data between the remote hosts.

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

Copies files with in the same machine
Copies files from local machine to remote machine
Copies files from remote machine to 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 remote host to local server:

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

Current directory

----->Copying a directory:

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

----->Improving 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