Understanding backup and Restore in AIX
Important Points:
a. rootvg backup can be taken thru mksysb command. Most people refer it as mksysb backup.
b. This type of backup on a tape is bootable. Hence its been widely used to restore the system incase of system crash.
c. Mksysb backup contains 4 images
i. BOS Boot Image - Kernel Device Drivers
ii. mkinsttape image - ./image.data, ./tapeblksz, ./bosinst.data and few other commands
iii. dummy .toc - Nothing but a dummy table of contents file
iv. rootvg data - This is where the actual data resides
Files used by mksysb:
/image.data :
Contains information about the image installed during the BOS installation process. This includes the sizes, names, mount points of LVs and file systems in the rootvg [Actually nothing but the rootvg structure]. It can be created using mkszfile command.
/var/adm/ras/bosinst.data :
It allows you to customize the OS installtion. Modified mostly to use the mksysb image to install new servers.
Few Commands :
To generate just /image.data :
# mkszfile
To create /image.data and generate a system backup on the tape :
# mksysb -i /dev/rmt0
To generate a system backup on the tape but to exclude /home directory and to create /image.data :
# echo /home > /etc/exclude.rootvg
# mksysb -ei /dev/rmt0
To list the contents of a mksysb image :
# lsmksysb -f /backup/system1.mksysb
To restore a specific file from mskysb image :
a. Rewind the tape :
# tctl -f /dev/rmt0 rewind
b. Move the tape forward to the end of 3rd image :
# tctl -f /dev/rmt0.1 fsf 3
c. Restore the specific file:
# restore -xqvf /dev/rmt0.1 /home/himanshu/him_file
Non-rootvg Backup :
Few Points:
a. Volume groups other than rootvg can be backup'ed using savevg command.
b. You can exclude certain files by creating /etc/exclude.vgname.
c. VG data files are kept under, /tmp/vgdata/vg-name/vg-name.data.
Few Commands :
To backup a datavg to the tape drive :
# savevg -if /dev/rmt0 datavg
To backup a datavg to the tape drive and exclude certain files :
# savevg -ief /dev/rmt0 datavg
To restore the datavg image from the tape onto the disks specified in /tmp/vgdata/datavg/datavg.data file :
# restvg -f /dev/rmt0
To create the data file (/tmp/vgdata/oravg/oravg.data) for oravg :
# mkvgdata oravg
File System Backup :
File systems can be backup'ed using many ways.Few commands used for this are backup, cpio, dsm [TSM Client].
To back up all the files and subdirectories in the /home directory using full path names :
# find /home -print l backup -if /dev/rmt0
To back up all the files and subdirectories in the /home directory using relative path names :
# cd /home
# find . -print l backup -if /dev/rmt0
I have used "l" for the pipe symbol as it was not displaying properly in blog.
To backup a list of files:
# cat bakfile
/home/himanshu/him_file.txt
/home/himanshu/file2.txt
/home/himanshu/file3.txt
# backup -iqvf /dev/rmt0
I-node Base Backup:
Here is the syntax for the backup command in case of inode based backup
Syntax:
# backup [-u] [-level] [-f device] filesystem
u -> Updates the /etc/dumpdates file
-level -> Values available from 0 to 9 where 0 is the full backup and 1-9 for backup the changes since the previous level.
To back up the /home file system by i-node :
# backup -0 -uf /dev/rmt0 /home
i-node based backup has the advantage of making incremental and differential backups. Here we use the numeric flags (0 to 9) to make the difference in the way it back ups. It actually updates the date/time/mode of last backup in /etc/dumpdates when you use the 'u' flag.
Here are the different numeric flags used and their meanings,
0 - Full Backup
1 - Back ups the files created/modified from the date/time of 0th backup
2 - Back ups the files created/modified from the date/time of 1th backup
3 - Back ups the files created/modified from the date/time of 2th backup
4 - Back ups the files created/modified from the date/time of 3th backup
5 - Back ups the files created/modified from the date/time of 4th backup
6 - Back ups the files created/modified from the date/time of 5th backup
7- Back ups the files created/modified from the date/time of 6th backup
8 - Back ups the files created/modified from the date/time of 7th backup
9 - Back ups the files created/modified from the date/time of 8th backup
Backup folder and its sub directories
find ./HS -print | backup -if /oracle/backup/HS/him_test
Restore file at a present directory
restore -xqvf /oracle/backup/HS/him_test
To View files in the backup
restore -Tvf /oracle/backup/HS/him_test
Few Examples for i-node based backup :
Scenario 1 - Full and Incremental Backup :
If you want to have full backup of /home on sunday night and incremental backup on other nights, then follow the below procedure.
Sunday Night - Full Backup :
# backup -0 -uf /dev/rmt0 /home
Monday Night - Incremental Backup :
# backup -1 -uf /dev/rmt0 /home
Tuesday Night - Incremental Backup
# backup -2 -uf /dev/rmt0 /home
Wednesday Night - Incremental Backup :
# backup -3 -uf /dev/rmt0 /home
Thursday Night - Incremental Backup :
# backup -4 -uf /dev/rmt0 /home
Friday Night - Incremental Backup
# backup -5 -uf /dev/rmt0 /home
Saturday Night - Incremental Backup :
# backup -6 -uf /dev/rmt0 /home
Advantages of Incremental Backup:
a. It takes lesser time to restore the specific data.For example, if you lose a file that was created on thursday morning, then you need only the wednesday night tape to restore the specific file.
b. This method consumes less tapes for backup. Hence its cost effective compared to differential backup.
Disadvantages of Incremental Backup:
a. You need more number of tapes (from sunday-full to last night-incre) to restore the entire file system.
Scenario 2 - Full and Differential Backup :
If you want to have full backup of /home on sunday night and differential backup on other nights, then follow the below procedure.
Sunday Night - Full Backup :
# backup -0 -uf /dev/rmt0 /home
Monday Night - Differential Backup :
# backup -1 -uf /dev/rmt0 /home
Tuesday Night - Differential Backup :
# backup -1 -uf /dev/rmt0 /home
Wednesday Night - Differential Backup :
# backup -1 -uf /dev/rmt0 /home
Thursday Night - Differential Backup :
# backup -1 -uf /dev/rmt0 /home
Friday Night - Differential Backup :
# backup -1 -uf /dev/rmt0 /home
Saturday Night - Differential Backup :
# backup -1 -uf /dev/rmt0 /home
Advantages of Differential Backup:
a. It takes less tapes (from sunday-full and last night-incre) to restore the entire file system.Hence it is easy for the backup operator to restore the data.
Disadvantages of Differential Backup:
a. It consumes more tapes for backup. (since we are going to backup the same old files again and again for the whole week).Hence cost is more in this type of backup.
To list the contents of backup on the tape :
# restore -Tvf /dev/rmt0
To restore individual files from backup created by 'backup -i' command :
# restore -xvf /dev/rmt0 /home/himanshu/him_file
To restore the entire file system :
# restore -rvf /dev/rmt0
Other Unix Backup Commands:
TAR:
tar is the only command (i think so) in UNIX which doesnot require a dash(-) infront of a flag.
To create a tar image in /tmp for a directory :
# tar cvf /tmp/oradata.tar /opt/oradata
To view the contents of a tar image :
# tar tvf /tmp/oradata.tar
To restore the tar image :
# tar xvf /tmp/oradata.tar
CPIO :
cpio reads and writes from stdin and stdout.
To backup the current directory to a /tmp/file.cpio file :
# find . -print cpio -ov > /tmp/file.cpio
To view the table of contents of the cpio archived tape :
# cpio -itvcC1 < /dev/rmt0
To restore data from the cpio archive file :
# cpio -idv < /tmp/file.cpio
To restore a selective file from cpio archived tape :
# cpio -imv /home/roger/.profile < /dev/rmt0
To restore selectively only the *.c and *.cpp file :
# cpio -i "*.c" "*.cpp" < /dev/rmt0
DD Command :
'dd' command copies (also converts) from an input device to an output device. This command will not span multiple tapes.
To copy a file and converting all the chars to upper case :
# dd if=/tmp/unixfile.txt of=/tmp/dosfile.txt conv=ucase
Tcopy Command :
Copies from one tape device to another.
To list the contents of a tape media :
# tcopy /dev/rmt0
To copy all the data from one tape to another tape device :
# tcopy /dev/rmt0 /dev/rmt1
tctl Command :
tctl has been widely used to control tape drives.
To rewind a tape device :
# tctl -f /dev/rm0 rewind
To fast forward to the beginning of 2nd tape mark :
# tctl -f /dev/rmt0.1 fsf
To do retension :
# tctl -f /dev/rmt0 retension
Retension is nothing but moving the tape to beginning, end and again to the beginning. You have to do this, if you encounter multiple read errors during the restoration operation.
To display the status of atape device :
# tctl -f /dev/rmt0 status
To eject a tape device :
# tctl -f /dev/rmt0 offline
TSM Client :
Few Points:
a. It requires a connection to TSM server and also a registeration in the TSM server.
b. You can take the 'backup' and 'archive' based on the TSM server configuration.
c. Archive can be taken for 90 days, 180 days, ... based on the management class.
d. Backup can have different versions. Last backup is the new and current version and oldest backup is the old version for every file that is backed up.
e. Most of the small sized companies keep 3 versions of backup, that means can have 3 backup version for each file.
To Backup a file :
# dsm backup /tmp/him_file
To archive a file :
# dsm archive /tmp/him_file
To list all the backed up filesystems :
# dsm query filespace
To verify the backup of a file :
# dsmc query backup /tmp/him_file
To verify the inactive version of a backup of a file :
# dsmc query backup -inactive /tmp/him_file
To verify the archive of a file :
# dsmc query archive /tmp/him_file
To backup VIO Server :
To take the OS backup in a CD ROM :
# backupios –cd /dev/cd1 -cdformat
To take the OS backup in a DVD-RAM :
# backupios –cd /dev/cd1 -udf
To take the OS backup in a tape drive :
# backupios –tape /dev/rmt0
To verify the backup available in a tape :
# backupios –tape /dev/rmt0 -verify
To generate vio backup (tar file) in a file :
# backupios –file /opt/him_file
To generate vio backup (mksysb image) in a file :
# backupios –file /opt/him_file -mksysb
Note: To restore a backup image on vio server, you have to use "installios" command in HMC. installios is a menu driven command (tool) which will ask for machine name, vio server(lpar) name, profile name for restoring the mksysb image.
Post a Comment
Post a Comment