Loading...
Basic Linux

Backup and Restore

  • 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 backup is to recover 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 everyday.
  • Many companies have planning.
  • The easiest way to backup your first is just copying. But if your 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 files into one file, the world will be better. Fortunately, ‘tar’ is used to create archive files.

Compressing 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 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: (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 file, for easy storage distribution.
Syntax:

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

Create some random blank files:

#touch   file1    file2      file3    another_file

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.

Let’s recreate the archive using the gunzip compression:

#tar   -cvzf    sample.tar.   file1    file2    file3     another_file

View the current directory to see the two current archive files:

#ls

To see all the contents within the build file:

#tar    -tvf     sample.tar

Now extract this build file verbosely:

#tar    -xvf    sample.tar

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 input from the “find” command.
The basic structure is

: find       -name     file  |   cpio   [options]   [controller]   <Dest>

Options:
-o -> out
-i -> In

Controllers:
O (or) > -out
I (or) < -in

To take the backup files

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

To see the backup content:

#cpio     -it   <  /root/backup . cpio

o -> Read 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’.

To take the backup:

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

To recovery:

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

spc: (Secure Copy)

  • scp is used to copy data from one unix or linux system to another Unix or Linux server.
  • scp used Secured Shell (ssh) to transfer the data between the remote hosts.
  • The features of scp are:
    • Copies file with the same machine.
    • Copies file from local machine to remote machine.
    • Copies files from remote machine to local machine
    • Copies files between two different remote servers.

Syntax:

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 local host to remote server:

#scp    filename     root@192.168.1.2 : /root

Copy files from remote host to local server:

#scp    root@ 192.168.1.2 : /root/backup*    .

Copying a directory:

#scp     -r      directory     root@192.168.1.2 : /root

Improving performance of scp command:
Using blowfish or arcfour encryption will improve the performance of the scp command.

#scp    -c    blowfish    filename    root@ 192.168.1.2 : .

Specifying the port number:

#scp   -p   6001    backup_file   root@ 192.168.1.2 : /tmp

Leave a Reply

Your email address will not be published. Required fields are marked *