backup & recovery

Backup and Recovery

Full Backup
Full backup is a method of backup where all the files and folders selected for the backup will be backed up.  When subsequent backups are run, the entire list of files and will be backed up again. The advantage of this backup is restores are fast and easy as the complete list of files are stored each time. The disadvantage is that each backup run is time consuming as the entire list of files is copied again.  Also, full backups take up a lot more storage space when compared to incremental or differential backups.

Incremental backup
Incremental backup is a backup of all changes made since the last backup. With incremental backups, one full backup is done first and subsequent backup runs are just the changes made since the last backup. The result is a much faster backup then a full backup for each backup run. Storage space used is much less than a full backup and less then with differential backups. Restores are slower than with a full backup and a differential backup.

Differential backup
Differential backup is a backup of all changes made since the last full backup. With differential backups, one full backup is done first and subsequent backup runs are the changes made since the last full backup. The result is a much faster backup then a full backup for each backup run. Storage space used is much less than a full backup but more then with Incremental backups. Restores are slower than with a full backup but usually faster then with Incremental backups.

Mirror Backup
Mirror backups are as the name suggests a mirror of the source being backed up. With mirror backups, when a file in the source is deleted, that file is eventually also deleted in the mirror backup. Because of this, mirror backups should be used with caution as a file that is deleted by accident or through a virus may also cause the mirror backups to be deleted as well.

##############################################################################
Here we need two machines for good understanding
1)machine1(172.16.28.130)
2)machine2(172.16.28.131)
###############################################################################
[root@machine1 ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64

$ rsync options source destination

[root@machine1 ~]# mkdir dir1
[root@machine1 ~]# touch dir1/files{1..100}
[root@machine1 ~]# ls -lh dir1/
[root@machine1 ~]# rsync -r dir1/ dir2
[root@machine1 ~]# ls dir2/

-v : verbose
-r : copies data recursively (but don’t preserve timestamps and permission while transferring data
-a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
-z : compress file data
-h : human-readable, output numbers in a human-readable format

#######################################################
[root@machine1 sample]# rsync -azvh dir1/ root@172.16.28.131:/root/dir3
########################################################
[root@machine2 ~]# ls dir3/
[root@machine2 ~]# mkdir sample
[root@machine2 ~]# touch sample/samplefiles{1..50}
#######################################################
[root@machine1 ~]# rsync -azvh  root@172.16.28.131:/root/sample .
#######################################################################
Rsync Over SSH

With rsync, we can use SSH (Secure Shell) for data transfer, using SSH protocol while transferring our data you can be ensured that your data is being transferred in a secured connection with encryption so that nobody can read your data while it is being transferred over the wire on the internet.

Also when we use rsync we need to provide the user/root password to accomplish that particular task, so using SSH option will send your logins in an encrypted manner so that your password will be safe.

Copy a File from a Remote Server to a Local Server with SSH

To specify a protocol with rsync you need to give “-e” option with protocol name you want to use. Here in this example, We will be using “ssh” with “-e” option and perform data transfer.

#################################################################################
[root@machine1 ~]# rsync -avzhe  ssh sample1  root@172.16.28.131:/root/
[root@machine2 ~]# ls sample1/
#################################################################################
Show Progress While Transferring Data with rsync
[root@machine1 ~]# rsync -avzhe  ssh sample1 –progress  root@172.16.28.131:/root/
#################################################################################
Use of –include and –exclude Options
[root@machine1 ~]#rsync -avze ssh –include ‘R*’ –exclude ‘*’ root@172.16.28.131:/var/lib/rpm/ /root/rpm
#################################################################################
Set the Max Size of Files to be Transferred
[root@machine1 ~]#rsync -avzhe ssh –max-size=’200k’ /var/lib/rpm/ root@172.16.28.131:/root//tmprpm
#################################################################################
Automatically Delete source Files after successful Transfer
[root@machine1 ~]#rsync –remove-source-files -zvh backup.tar /tmp/backups/
#################################################################################
Set Bandwidth Limit and Transfer File
[root@machine1 ~]#rsync –bwlimit=100 -avzhe ssh  /var/lib/rpm/  root@172.16.28.131:/root//tmprpm/
#################################################################################

Backup: 
Backup is used to prevent the data lost.
Copy data to alternative media
Only Adiministrator can backup the data
Back up media:
Cd ,dvd, Brd, pen drive , hard disk ,zip drive , tape drive etc.
The type of data and backup devices depends on the administrator’s on the company policies.
We have 3 types of Backups
1.Full Backup or Monthly Backup
2.Incremental Backup or Daily Backup
3.Differential Backup or Daily Backup
Full Backup: 
Here total backup of the file system is taken . It doesn’t consider any modification date and time. If we apply this backup all the files are taken in to backup media. Disadvantages of this backup is it doesn’t consider the modification date and time of files and directories.Hence space of the backup device will be wasted.
Incremental Backup: 
It includes all files that were changed since the last full backup. Incremental Backup depends upon the modification date & time.
Differential Backup: 
It doesn’t depends upon the modification date & time.
Commands for backup
1.Tar Backup
2.Cpio Backup
3.dd Backup(disk to disk) and
4.dump Backup
5.Remote Backup
Using Tar Backup
#tar {option} {destination} {source}{/source}{/destination}{/option}
Options:-
-c ——— create
-v ——— verbose
-f ———- file
-t ———- table of content
-x ——— extract
-z ——— Zip
To take backup example:
#mkdir Linux
#cd Linux
#touch 1 2 3 4 5
#mkdir /dev/st0
#tar -cvf /dev/st0/b1.tar Linux
To view table of contents
#tar -tvf /dev/st0/b1.tar
To remove data
#rm –rf Linux
To recovery or restore the data
#tar –xvf /dev/st0/b1.tar
To extract Backup data to the perticular folder
#tar –xvf /dev/st0/b1.tar -C /root
How to take Zip Backup with tar
#tar -cvzf /dev/st0/c1.tar
How to restore 
#tar -zxvf /dev/st0/c1.tar
CPIO:Copy Input / Output.
#cpio {source} | cpio {option} {controller} {destination}
Options:
-o —– out
-i —– in
-c —– create
-t ——- table of backup content
-v ——– verbose
-f ——- file
How to take the CPIO Backup:
It is having two methods.
i) In Relative Method
ii) Absolute Method
This backup we can take storage medias and CD/DVD’s.
I am taking the backup in my pc so first creat backup directory in your PC.
#mkdir /cpio
#cd /cpio
1)How to Take the CPIO Backup in In Relative Method:
first create the Files which you want to take the backup.
#touch a{1..10}
To take the backup:
#ls * | cpio -ocvf >/dev/st0/relative.cpio
To see the Backup whether it is created or not.
#cd /dev/st0
#ls
To See the Backup Content:
#cpio -itvf
To remove the old files
#rm -rf *
To extract or restore the Backup:
#cpio -icvf
2) how to take the Backup in Absolute Method:
first create some files in your directory
ex:
#mkdir /cpio
#cd /cpio
#touch b{1..10}
#ls (to see the creating files)
Now take the backup using find command:
#find /cpio | cpio -ocvf >/dev/sto/absolute.cpio
See the backup content:
#cpio -itvf >/dev/st0/absolute.cpio
Remove the old files along with directory 
#cd
#rm -rf /cpio
#ls (here there is no files)
To extract or restore the backup now:
#cpio -icvf >/dev/st0/absolute.cpio
#ls (here you can see the restoring or backup files).
DD (disk to disk)
It is used to take backup one hard disk to another harddisk .
#dd if ={source file} of = {destination file}
Dump
#dump -0uf /dev/st0/dump1 /dev/hda6
To recovery 
#restore -rvf /dev/st0/dump1
Dump Backup
Using the Dump Backup we can take 3 types of backup Full, Differential & Incremental Backup
1.Full Backup 2. Incremental Backup 3. Differential Backup.
With this command we don’t need to unmount the Partition to take the backup.
How take the Dump Backup
#dump -0uf /dev/st0/dump1 /dev/hda6 (here 0-indicate Full Backup)
1-9 (here replace of Zero)Indicates Incremental / Differential Backup
How to restore the Backup
#restore -rvf /dev/st0/dump1 (r- Recursive, v- Verbose, f- file)
To check the Dump Updates
#cat /etc/dumpupdates
Remote Backup
1. How to take the Backup with rsync 
rsync -avg {source} -e ssh {destination Ip}:{path}
Ex #rsync -avg a* -e ssh 192.168.0.1:/mnt
How to restore the backup
rsync -avg -e sh {destination Ip}:{path} {source path}
Ex: #rsync -avg -e ssh 192.168.0.1:/mnt/a* /mnt
2. How to take the Backup with scp (scp – Secure Copy)
#scp -r {source} ssh {destiation ip}:{path} {source}
How to restore
#scp -r ssh {destination Ip}:{path} {source path}
====================================================================

Example 1. Backup Entire Harddisk

To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command as shown below. In this dd command example, the UNIX device name of the source hard disk is /dev/hda, and device name of the target hard disk is /dev/hdb.

# dd if=/dev/sda of=/dev/sdb
“if” represents inputfile, and “of” represents output file. So the exact copy of /dev/sda will be available in /dev/sdb.
If there are any errors, the above command will fail. If you give the parameter “conv=noerror” then it will continue to copy if there are read errors.
Input file and output file should be mentioned very carefully, if you mention source device in the target and vice versa, you might loss all your data.
In the copy of hard drive to hard drive using dd command given below, sync option allows you to copy everything using synchronized I/O.

# dd if=/dev/sda of=/dev/sdb conv=noerror,sync

———————————————————
Example 2. Create an Image of a Hard Disk

Instead of taking a backup of the hard disk, you can create an image file of the hard disk and save it in other storage devices.There are many advantages to backing up your data to a disk image, one being the ease of use. This method is typically faster than other types of backups, enabling you to quickly restore data following an unexpected catastrophe.

# dd if=/dev/hda of=~/hdadisk.img
———————————————————
Example 3. Restore using Hard Disk Image

To restore a hard disk with the image file of an another hard disk, use the following dd command example.

# dd if=hdadisk.img of=/dev/hdb
The image file hdadisk.img file, is the image of a /dev/hda, so the above command will restore the image of /dev/hda to /dev/hdb.
———————————————————
Example 4. Creating a Floppy Image

Using dd command, you can create a copy of the floppy image very quickly. In input file, give the floppy device location, and in the output file, give the name of your floppy image file as shown below.

# dd if=/dev/fd0 of=myfloppy.img
———————————————————-
Example 5. Backup a Partition

You can use the device name of a partition in the input file, and in the output either you can specify your target path or image file as shown in the dd command example below.

# dd if=/dev/hda1 of=~/partition1.img
———————————————————-
Example 6. CDROM Backup

dd command allows you to create an iso file from a source file. So we can insert the CD and enter dd command to create an iso file of a CD content.

# dd if=/dev/cdrom of=tgsservice.iso bs=2048
dd command reads one block of input and process it and writes it into an output file. You can specify the block size for input and output file. In the above dd command example, the parameter “bs” specifies the block size for the both the input and output file. So dd uses 2048bytes as a block size in the above command.
——————————————————–

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s