Presentation is loading. Please wait.

Presentation is loading. Please wait.

BACKUPS Whenever a crash occurs we run a backup program. The backup device can be magnetic or a cartridge tape, a floppy diskette or even a disk file.

Similar presentations


Presentation on theme: "BACKUPS Whenever a crash occurs we run a backup program. The backup device can be magnetic or a cartridge tape, a floppy diskette or even a disk file."— Presentation transcript:

1 BACKUPS Whenever a crash occurs we run a backup program. The backup device can be magnetic or a cartridge tape, a floppy diskette or even a disk file. Small systems especially workstations, may not have the tape facility, so the floppy drive will be used here to illustrate the features of both commands. UNIX offers two commands – cpio and tar. Both combine a group of files into a single file ( called an archive), with suitable headers preceding the contents of each file. Each command has definite advantages over the other, and the formats they use to record data are not compatible with each other.

2 Copy input-output – the cpio Command cpio (copy input output) copies files to and from a backup device. cpio (copy input output) copies files to and from a backup device. It uses standard input to take the list of filenames. It uses standard input to take the list of filenames. It then copies them with their contents and headers to a stream which can be redirected to a file or device. This means that cpio can be used with redirection and piping. It then copies them with their contents and headers to a stream which can be redirected to a file or device. This means that cpio can be used with redirection and piping. cpio uses two key options, -o (output) and i (input) two commands should not be placed at a time. cpio uses two key options, -o (output) and i (input) two commands should not be placed at a time.

3 Packing up files(-o) Since cpio uses only standard input, you can use ls to generate a list of filenames to serve as its input. The –o key option creates the archive on the standard output, which you need to redirect to a device file. Since cpio uses only standard input, you can use ls to generate a list of filenames to serve as its input. The –o key option creates the archive on the standard output, which you need to redirect to a device file. $ ls | cpio –ov > /dev/rdsk/foq18dt $ ls | cpio –ov > /dev/rdsk/foq18dt Array.pl Array.pl Calendar Calendar Convert.sh Convert.sh The –v verbose option displays each file name on the terminal when its being copied. The –v verbose option displays each file name on the terminal when its being copied. cpio needs as input a list of files, and if this list is available in a file, redirection can be used too. cpio needs as input a list of files, and if this list is available in a file, redirection can be used too. $cpio –o >/dev/rdsk/foq18dt /dev/rdsk/foq18dt < flist.

4 Incremental Backups: find can also produce a file list, so any files that satisfy its selection criteria can also be backed up. find can also produce a file list, so any files that satisfy its selection criteria can also be backed up. You will frequently need to use find and cpio in combination to backup selected files. You will frequently need to use find and cpio in combination to backup selected files. Find the files those that have been modified in the last two days. Find the files those that have been modified in the last two days. Shell command Shell command find. –mtime -2 –print | Cpio –ovB > /dev/rdsk/foq18dt find. –mtime -2 –print | Cpio –ovB > /dev/rdsk/foq18dt Since the path list of find is dot, the files are backed up with their relative path names. Since the path list of find is dot, the files are backed up with their relative path names. However if it is /, find will use absolute pathnames However if it is /, find will use absolute pathnames -B sets block size to 5120. for higher sizes –c option is used. -B sets block size to 5120. for higher sizes –c option is used. [Find. –mtime -2 –print | cpio –ovc 51200 > /dev/rdsk/foq18dt] [Find. –mtime -2 –print | cpio –ovc 51200 > /dev/rdsk/foq18dt]

5 Multivolume backups When the created archive in the backup device is larger than the capacity of the device, cpio prompts for inserting a new diskette into the drive. When the created archive in the backup device is larger than the capacity of the device, cpio prompts for inserting a new diskette into the drive. Find. –mtime -2 –print | cpio –ocB > /dev/rdsk/foq18dt Find. –mtime -2 –print | cpio –ocB > /dev/rdsk/foq18dt Output: Output: Reached the end of the medium on output. Reached the end of the medium on output. If you want to go on, type device/filename when ready If you want to go on, type device/filename when ready /dev/fd0 /dev/fd0 3672 blocks 3672 blocks Enter the device when cpio pauses to take input. In this way, an archive can be split into several extents(volumes). Enter the device when cpio pauses to take input. In this way, an archive can be split into several extents(volumes).

6 Restoring Files A complete archive or selected files can be restored with the –i key option A complete archive or selected files can be restored with the –i key option To restore files, use redirection to take input from the device. To restore files, use redirection to take input from the device. $cpio –iv < /dev/rdsk/foq18dt $cpio –iv < /dev/rdsk/foq18dt Array.pl Array.pl Calendar Calendar a.sql a.sql When restoring subdirectories, cpio assumes that the subdirectory structures are also maintained on the hard disk; it cant create them in case they are not. When restoring subdirectories, cpio assumes that the subdirectory structures are also maintained on the hard disk; it cant create them in case they are not. However the –d (directory) option overrides that. However the –d (directory) option overrides that. cpio also accepts a quoted wild card pattern, so multiple files fitting the pattern can be restored. Restoring only the shell scripts becomes quite easy. cpio also accepts a quoted wild card pattern, so multiple files fitting the pattern can be restored. Restoring only the shell scripts becomes quite easy. $Cpio –iv “*.sh” < /dev/rdsk/foq18dt $Cpio –iv “*.sh” < /dev/rdsk/foq18dt

7 Handling modification times Use the –m option to tell cpio that the modification time has to be retained. Use the –m option to tell cpio that the modification time has to be retained. cpio compares the modification time of a file on the media with the one on disk (if any). If the disk file is newer than the copy, or of the same age, then it wont be restored. cpio compares the modification time of a file on the media with the one on disk (if any). If the disk file is newer than the copy, or of the same age, then it wont be restored. cpio then echoes the message. cpio then echoes the message. “current newer” “current newer” This is useful built in protection feature that safeguards the latest version of a file. However these can be overridden with the – u(unconditional) option. This is useful built in protection feature that safeguards the latest version of a file. However these can be overridden with the – u(unconditional) option.

8 Displaying the archive The –t option displays the contents of the device without restoring the files. This option must be combined with the –i key option. The –t option displays the contents of the device without restoring the files. This option must be combined with the –i key option. $cpio –itv “*.sh” < /dev/rdsk/foq18dt $cpio –itv “*.sh” < /dev/rdsk/foq18dt Other options Other options -d creates directories as and when needed -d creates directories as and when needed -c writes header information in ASCII form for portability -c writes header information in ASCII form for portability -r renames the file in interactive manner -r renames the file in interactive manner -f exp copies all files except those in expression -f exp copies all files except those in expression Copy all files except those in expression Copy all files except those in expression $Cpio –ivf “*.c” < /dev/rdsk/foq18dt $Cpio –ivf “*.c” < /dev/rdsk/foq18dt

9 The “tape” archive Program – the tar Command tar is a versatile command with certain exclusive features not found in cpio. tar is a versatile command with certain exclusive features not found in cpio. It doesn’t use standard input to obtain its file list. Tar accepts file and directory names as arguments. It doesn’t use standard input to obtain its file list. Tar accepts file and directory names as arguments. It copies one or more entire directory trees, i.e. it operates recursively by default. It copies one or more entire directory trees, i.e. it operates recursively by default. It can append to an archive without overwriting the entire archive. It can append to an archive without overwriting the entire archive. The common key options are. The common key options are. -c -----copy -c -----copy -x-----extract -x-----extract -t-----table of contents -t-----table of contents -f-----additionally used for specifying device name -f-----additionally used for specifying device name

10 Backing up files (-c) tar accepts directory and file names directly on command line. The –c option is used to copy files to the backup device. The –v verbose option shows the progress of the backup. tar accepts directory and file names directly on command line. The –c option is used to copy files to the backup device. The –v verbose option shows the progress of the backup. $tar –cvf /dev/rdsk/foq18dt/home/sales/sql/*.sql $tar –cvf /dev/rdsk/foq18dt/home/sales/sql/*.sql a/home/sales/sql/a.sql 1 tape block a/home/sales/sql/a.sql 1 tape block The ‘a’ before each pathname indicates that the file is appended. The ‘a’ before each pathname indicates that the file is appended. The command backs up all sql scripts with absolute pathnames. The command backs up all sql scripts with absolute pathnames. They can only be restored in the same directory. They can only be restored in the same directory.

11 The advantage of tar lies in that it can copy an entire directory tree with all its subdirectories The advantage of tar lies in that it can copy an entire directory tree with all its subdirectories 18 tell to execute the program faster (i.e. 18*2*512 bytes) 18 tell to execute the program faster (i.e. 18*2*512 bytes) $tar –cvfb /dev/rdsk/foq18dt 18* $tar –cvfb /dev/rdsk/foq18dt 18* The above command doesn’t backs up the hidden files. The above command doesn’t backs up the hidden files. $tar –cvfb /dev/rdsk/foq18dt 18. $tar –cvfb /dev/rdsk/foq18dt 18. The above command backs up the hidden files. The above command backs up the hidden files. The files here are backed up with their relative pathnames, assuming they all fit in one diskette. The files here are backed up with their relative pathnames, assuming they all fit in one diskette. If they don’t, tar in system V can accommodate them as much as much as possible and then quit the program without warning. If they don’t, tar in system V can accommodate them as much as much as possible and then quit the program without warning.

12 Multivolume Backups For multivolume backups tar in solaris uses –k option followed by the volume size in kilobytes. For multivolume backups tar in solaris uses –k option followed by the volume size in kilobytes. $tar –cvfkb /dev/rdsk/foq18dt 1440 18 index $tar –cvfkb /dev/rdsk/foq18dt 1440 18 index Output: Output: Volume ends at 1439, blocking factor=18 Volume ends at 1439, blocking factor=18 Tar: large file index needs 2 extents Tar: large file index needs 2 extents Tar: Current device seek position =ok Tar: Current device seek position =ok +++ a index 1439 [extent #1 of ] +++ a index 1439 [extent #1 of ] Tar: please insert new volume, then press RETURN Tar: please insert new volume, then press RETURN Tar estimates that two 1440kb diskettes will be required.

13 Restoring Files Files are restored with the –x(extract) key option. Files are restored with the –x(extract) key option. When no file or directory name is specified, it restores all files from the backup device. When no file or directory name is specified, it restores all files from the backup device. The following command restores the files just blocked up. The following command restores the files just blocked up. #tar –xvfb /dev/rdsk/foq18dt #tar –xvfb /dev/rdsk/foq18dt Output: Output: /home/sales/sql/a.sql 169 bytes, 1 tape blocks /home/sales/sql/a.sql 169 bytes, 1 tape blocks /home/sales/sql/b.sql 456 bytes, 1 tape blocks /home/sales/sql/b.sql 456 bytes, 1 tape blocks /home/sales/sql/c.sql 4855 bytes, 1 tape blocks /home/sales/sql/c.sql 4855 bytes, 1 tape blocks

14 Selective Extraction Selective Extraction It is possible by providing one or more directory or filenames. It is possible by providing one or more directory or filenames. #tar –xvF /dev/rdsk/foq18dt /home/sales/SQL/a.sql #tar –xvF /dev/rdsk/foq18dt /home/sales/SQL/a.sql Unlike cpio, when files are extracted, the modification time of the files also remain unchanged. This can be overridden by the –m option to reflect the system time at the time of extraction. Unlike cpio, when files are extracted, the modification time of the files also remain unchanged. This can be overridden by the –m option to reflect the system time at the time of extraction. Key options: Key options: Option significance Option significance -ccreates a new archive. -ccreates a new archive. -xextracts files from archive. -xextracts files from archive. -t List contents of archive. -t List contents of archive. -r Appends file at the end of the archive. -r Appends file at the end of the archive. -u Like r, but only if files are newer than archive -u Like r, but only if files are newer than archive

15 Non key options Non key options -f device uses pathname device. -f device uses pathname device. -v verbose option lists files in long format. -v verbose option lists files in long format. -w confirms from user about action to be taken. -w confirms from user about action to be taken. -b n uses blocking factor n, when n is restricted to 20 -b n uses blocking factor n, when n is restricted to 20 -mchanges modification time of file to time of extraction. -mchanges modification time of file to time of extraction. -I file_nameTakes file name from file(solaris only) -I file_nameTakes file name from file(solaris only) -T file_nameTakes file name from file(Linux only) -T file_nameTakes file name from file(Linux only) -X file_nameExcludes filenames in file -X file_nameExcludes filenames in file -K numMultivolume backup sets size of volume to num kilo bytes. -K numMultivolume backup sets size of volume to num kilo bytes. -MMultivolume backup Linux only. -MMultivolume backup Linux only. -Zcompress/uncompress with gzip(linux only) -Zcompress/uncompress with gzip(linux only)

16 Displaying the archive Like in cpio, the –t key displays the contents of the device in a long format similar to the listing. Like in cpio, the –t key displays the contents of the device in a long format similar to the listing. #tar –tvf /dev/rdsk/foq18dt #tar –tvf /dev/rdsk/foq18dt Output: Output: rwxr_xrwx 203/50472jan 4 09:355 1991./dentry.sh rwxr_xrwx 203/50472jan 4 09:355 1991./dentry.sh rwxr_xrwx 203/50472jan 4 09:355 1991./dentr.sh rwxr_xrwx 203/50472jan 4 09:355 1991./dentr.sh If you want to extract the file func.sh from the diskette. If you want to extract the file func.sh from the diskette. #tar –tvf /dev/rdsk/foq18dt func.sh #tar –tvf /dev/rdsk/foq18dt func.sh Tar:func.sh: not found in archive Tar:func.sh: not found in archive Tar failed to find the file because it existed there as./func.sh and not func.sh put the./ before the file name and get it. Tar failed to find the file because it existed there as./func.sh and not func.sh put the./ before the file name and get it. #tar –tvf /dev/rdsk/foq18dt./func.sh #tar –tvf /dev/rdsk/foq18dt./func.sh

17 Other options: Other options: The –r option is used to append a file to an archive. The unusual outcome of this is that an archive can contain several versions of the same file. The –r option is used to append a file to an archive. The unusual outcome of this is that an archive can contain several versions of the same file. The –u option also adds a file to an archive but only if the file is not already there or is being replaced with a newer version. You cant use the –c option when using either –r or –u. The –u option also adds a file to an archive but only if the file is not already there or is being replaced with a newer version. You cant use the –c option when using either –r or –u. The –w option permits interactive copying and restoration. It prints the name of the file and prompts for the action to be taken(yes or no). The –w option permits interactive copying and restoration. It prints the name of the file and prompts for the action to be taken(yes or no).


Download ppt "BACKUPS Whenever a crash occurs we run a backup program. The backup device can be magnetic or a cartridge tape, a floppy diskette or even a disk file."

Similar presentations


Ads by Google