SecondCopy is the main program in this application. It will save, verify, and restore files using a SCSI tape drive. SecondCopy can copy files from any floppy, hard disk, or ram disk on the network. The files and information like dates and permissions are written sequentially to a tape. When a set of files has been written, the contents of the tape can be compared with the files on the hard disks to prove the tape is correct and readable.
SecondCopy presents a command line interface, which allows it to be used inside a shell script for unattended execution. It does not require a windowing system to operate and can be executed from a floppy diskette. It does require a SCSI device driver.
SecondCopy is a 32-bit program for use with Linux version 2.0.30 and later.
SecondCopy was written with a command line user interface. The software reads the command line from left to right. Two command line options are required: the device name for the tape drive and a SecondCopy command. Several commands may be entered on a command line and they will be executed in left to right order.
To display the available commands, type:
$ secondcopy ?<Enter>
$ secondcopy ?
secondcopy version 0.12 07 February 1999
Copyright (C) 1992-1999 Brown Computer Company. All rights reserved.
This program will save and restore files using Tandberg tape drives,
and Linux 2.0.30.
use secondcopy dev_name "command args" +
or secondcopy ?
where:
dev_name is an entry in /dev, such as /dev/st0;
command is one of the commands listed below; and
args are white space delimited tokens.
[] indicate an option. | indicates an exclusive choice.
+ indicates one required instance with optional repetitions.
"" should enclose commands which use additional arguments.
commands usage explanation
-----------------------------------------------------------------------------
verbose "verbose [yes] | no" adjust stdout
continue "continue [yes] | no | ask" continue after recoverable error
errors "errors file_name" produce an error log
tty "tty device_name" choose an interactive device
links "links [yes] | max_links | no" observe, set, or disregard links
compress "compress [yes] | no | query" enable or disable compression
init "init volume_name" initialize a tape
save "save [-clear | incremental]" copy files to tape
verify "verify [-prefix | new_directory]" compare the files on a tape
name name read the volume_name on a tape
list list list the files on the tape
patterns "patterns max_patterns" increase default limits
restore "restore [-prefix | new_directory]" copy files to disk
help help prints this message
? ? prints this message
$
|
Each of these commands is discussed below as a series of exercises for you to follow. The commands you should type are in bold print and the responses you will see on your screen are in a box outline. Even if you intend to use the backup.s. file instead of setting up your own backup routine, you should learn how to save, verify, and restore files from the keyboard: backup.s may be unavailable due to a hard disk crash.
Choose a tape cartridge that can be erased. Place it in the tape drive and close the door. Check that a SCSI device driver is running by listing the contents of the "/dev" directory and identify a name like "/dev/st0". Try the three examples below. The screen output for the first example shows everything works. The second shows a failure when the tape cartridge is not installed. The third shows a failure when an incorrect device name is chosen.
$ secondcopy /dev/st0 "init Your_Volume_Name" <Enter>
$ secondcopy /dev/st0 "init Your_Volume_Name" secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. volume name Your_volume_name sequence # 1 $ $ secondcopy /dev/st0 "init No_Tape_Installed" secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. tape load failed 1, cartridge not detected $ $ secondcopy /dev/st12 "init Wrong_Device_Name" secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. driver_open ( /dev/st12 , 0 , 0 ) failed, No such file or directory $ |
You do not need superuser privileges but you do need to type the double quote characters to protect the space character that separates the token "init" from "Your_Name_Here" from the shell. If the tape drive and the SCSI controller card have been installed correctly, and if the device driver is running, the tape will be rewound. The SecondCopy program will initialize the tape by writing a header on the first block of the tape. If you forget to insert the tape, or specify an incorrect or non-existent device, SecondCopy will respond with an error message.
If you wish symbolic links to be saved as links rather than as full copies of the files to which they point, you must indicate this at initialize time, using the "links" option.
The volume name is an ascii string of 39, or fewer, characters. It is used to identify the contents of a tape cartridge through software. The name identifies a series of tapes and a sequence number identifies tapes within a series. When a backup session fills the first tape, SecondCopy automatically writes the volume name and the correct sequence number to the second tape.
To see the volume name you just wrote to the cartridge, type:
$ secondcopy /dev/st0 name <Enter>
$ secondcopy /dev/st0 name secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. volume name Your_volume_name, sequence # 1, os Linux 2.0.30, version 0.12, links no, compression none, date Thu May 13 12:40:12 1999 $ |
$ echo hello >junk1 <Enter>
$ cat >junk2 <Enter>
this is a test file <Enter>
^d <Enter>
$ echo hello >junk1 $ cat >junk2 this is a test file $ |
The ^d, or control d, symbol is made by pressing the 'Ctrl' and 'D' keys at the same time. In this interactive example, the keystroke is interpreted by the shell as the end of your typed input for the current program, cat. The ^d symbol is not used in batch files or shell scripts.
To save the files you just created, type:
$ secondcopy /dev/st0 save <Enter>
junk1 <Enter>
junk2 <Enter>
^d <Enter>
$ secondcopy /dev/st0 save secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. junk1 junk1 saved junk2 junk2 saved $ |
The tape will rewind. Type the name of the file you want to save and terminate the string with the Enter key. If the file is not in the current working directory, use a full path designation. The SecondCopy program will echo the file name and copy the file to the tape. You may enter several file names, but enter only one per line. When you are finished type ^d.
Now try the list command. Type:
$ secondcopy /dev/st0 list <Enter>
$ secondcopy /dev/st0 list secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. junk1 junk2 $ |
If you want to see a more verbose report, type:
$ secondcopy /dev/st0 verbose list <Enter>
or
$ secondcopy /dev/st0 "verbose yes" list <Enter>
$ secondcopy /dev/st0 verbose list secondcopy version 0.12 07 February 1999 Copyright (C) 1992-1999 Brown Computer Company. All rights reserved. volume name Your_Volume_Name, sequence # 1, os Linux 2.0.30, version 0.12, links no, compression none, date Thu May 13 12:40:12 1999 t-u--g--o- ln Owner Group Size Date Filename -rw-rw-r-- 1 0 0 4 Aug 29 12:54:37 97 junk1 -rw-rw-r-- 1 0 0 4 Aug 29 12:54:47 97 junk2 8 bytes in 2 files. 2 seconds $ |
Please note the use of double quotes around the two tokens verbose and yes. The double quotes were used before in the init example. This is a shell convention which prevents strings which have embedded spaces from being split. Double quotes override the default action of breaking a command line at every space or tab character. Double quotes work in batch files and at the keyboard.
SecondCopy reads its list of files to be saved from stdin. Stdin can be a static file or the output of another program. The most convenient mechanism for selecting files to save is piping the output of the find program into the input of SecondCopy. The '|' symbol is used between two programs on a command line to indicate to the shell that the output of the program on the left should be redirected to the input of the program on the right.
The find program, like ps, echo, and cat, is a utility that is part of a normal Linux installation. If it is not installed on your system, it can be found on the operating system distribution CD. Type:
# find source_directory | secondcopy /dev/st0 "init XYZ" save <Enter>
The find program will execute, generating a list of all the files found under the indicated directory. This includes all of the subdirectories as well. Please refer to the manual entry for the find program to learn about its use.
The output of the find program will be sent as input to SecondCopy. SecondCopy processes its command line from left to right and so it will initialize the tape first and then save the files found by the find program.
If the tape already had data on it, the initialization would have lost it forever. If you want to simply append to the end of the tape, leave off the init command. SecondCopy will skip to the end of the recorded area of the tape before writing new files.
In some cases you may not wish to back up all of the files in a directory. This can be done in several ways. First, one can redirect the output of the find program to a file and then edit that file. When the edits are complete use the file as stdin for SecondCopy. Another way is to use the pattern matching arguments for the find program. As noted above, a manual entry for the find program is available. You will find the explanations there.
One example of the need to limit the list of files which are backed up occurs when one backs up the "/" directory. The subdirectory called "proc" is used by Linux to manage currently running processes. You can tell the find program to skip this directory (or any files) by using pattern matching options, and by using the find program command line options "-type f" or "-type d" with "! -name".
# find / -type d ! -name /proc | secondcopy /dev/st0 save <Enter>
Incremental backups are available with SecondCopy. An incremental backup
allows you to save only those files which have been modified since the
last full backup and selectively restore them at a later time. To make
an incremental backup type:
# find / -type d ! -name /proc -newer some_file
| secondcopy /dev/st0 "save incremental" <Enter>
The find program will only report those files which are newer than the
date of the last backup. SecondCopy will store the files on the tape but a
prefix will be appended to each filename. The prefix will be of the
form
if the files' path is relative to the root, and
if the files' path is absolute. The date component is constructed
from the system clock. You can selectively restore these files by
including this prefix in the patterns used by the restore command.
If there are too many files for one tape, SecondCopy notifies you that
the tape is full, and asks you to enter the volume name of the tape
or "quit". If you enter the volume name, it then asks for the sequence
number of the next tape.
The volume name prompt may have a file name following it. Do not let
this confuse you. The current file name is printed on the screen unless
stdout has been redirected elsewhere. If you are performing a backup
without an init command, and if the current tape cartridge fills up
in the middle of a file, and if both stdout and stderr are directed
to the screen, the volume name prompt will be displayed next to the
current file name.
SecondCopy must prompt you for the tape's name and sequence number
because it did not read that information from the tape. It did not
read that information from the tape because you indicated your
desire for an append operation by omitting an init command. You can
prevent this mixing of message streams by using "tty device_name"
command line option.
It is possible to avoid entering the volume name by using the command
line option "name". However, few users do this because of the extra
time required. The name command directs SecondCopy to rewind to the
beginning of the tape and, in the case of a save operation, forward
to the end of the recorded area. This could take hours on the 26
gigabyte tapes.
See the section entitled
backup.s
for an example of a full save
command, illustrating the proper order of the save options.
Files are restored using SecondCopy's restore command. To restore a
file you just saved, erase junk1 and type:
$ secondcopy /dev/st0 restore <Enter>
Where did you type a pattern? In this example the pattern was junk1.
It looks like a filename because it didn't have any wildcards in it
but it is interpreted by SecondCopy as a pattern. SecondCopy reads junk1
from stdin and rewinds the tape. As it encounters each file on the
tape, SecondCopy compares the file name on the tape with the specified
pattern. If the name and the pattern match, the file is restored. The
name of the restored file is the path and name found on the tape
unless you used a new path in the restore command.
Please note that the use of stdin has changed from the save operation.
In save, stdin was interpreted as a list of files to operate on. In
restore, stdin is treated as a list of patterns. This change is
necessary because the memory required by all the file names on the
tape is often greater than the memory installed in the computer.
The number of available patterns is limited. In the most recent
version of SecondCopy the default value is fifty. The patterns command
can be used to increase that number to 4096.
Patterns offer convenience over completely resolved file names. First,
you may not know the names of the files on the tape and it would take
additional time to list the contents. Second, the patterns reduce the
number of keystrokes one has to type. For example, if you want to
restore the entire volume, type:
# echo "*" | secondcopy /dev/st0 restore <Enter>
A pattern is a string of characters chosen from the set of legal
filename characters and the special characters: '*', '?', '[', ']',
'\', and '!'. The pattern is compared against all filenames on the tape
and if the match condition is true, the file will be restored. '*' will
match any run of characters. '?' will match any single character. The
'[' and ']' characters are used to enclose a list of characters, any of
which will fulfill a match. The '!', when used as the first character
of a bracket expression, indicates that all filenames not matching the
bracket expression will be accepted as a match. '!', when used as the
first character of a pattern will cause all filenames matching the
pattern to be skipped.
Pattern matching always seems to bump into an in-band signalling
problem. In this case the '[' and ']' characters are in the set of
legal filename characters and the set of special characters. To cause
the pattern matching engine to treat '[' and ']', or any other special
character, literally, the '\' character is used. When '\' precedes a
special character, even another '\', the special character will be
demoted back to a regular character.
The progress of the restore operation is reported on stdout. One
line is written for each file restored. The line will contain the
filename, as found on the tape followed by the word "restored" or the
phrase "not restored", depending on the outcome. If the file could not
be restored, a message will be sent to stderr. If an error log is in
use, a timestamped error message will be sent to the log. Nothing
will be reported for files that were skipped.
This process will continue until the end of the recorded area of the
tape is reached. If the physical end of the tape is reached and a file
is only partially read, SecondCopy will prompt you to insert the next
tape. It will indicate the sequence number and the volume and check
that you have inserted the correct tape before it proceeds.
If the verbose option is used, SecondCopy will report the number of
files restored and the number of times each pattern was matched. If
your patterns were too restrictive, this report may help you adjust
them.
The restore command has two options that allow you to restore a file
to a different path. The first, "-prefix", will strip the root '/' from the
path found on the tape. To restore the files to a new directory while
preserving other components in the path, just change
SecondCopy's current working directory.
$ echo /copyright.notice | secondcopy /dev/st0 "restore -prefix"<Enter>
will look for /copyright.notice on the tape and restore it to
copyright.notice in the current working directory.
The second way to change the destination is to completely override the
original path. The "new_directory" option strips all of the original path
components and replaces them with your command line choice.
$ secondcopy /dev/st0 "restore /tmp" <Enter>
will look for /boot/image/hard.2 on the tape and copy it to
/tmp/hard.2. The directory tree of the old path is discarded and
replaced with the new directory. Don't use a '/' as the final character
of the new_directory option: one will be added for you.
The verify command is similar to restore. The tape is rewound and
each file is read. If the filename matches one of the patterns, the
contents on the tape is compared with that on the hard disk. If they
match, the filename and the word "verified" are printed on stdout. If
the comparison fails, the filename and the phrase "not verified" are
printed on stdout and a more detailed error message is sent to stderr.
Both the contents of the file and the file's directory information
are compared.
Like the restore command, verify interprets stdin as a list of
patterns. To verify all the files on a tape, use '*' as the pattern.
Otherwise, select an appropriately limiting pattern. To compare the
contents of the files that were saved previously, type:
$ echo "junk*" | secondcopy /dev/st0 verify <Enter>
In this example, the double quotes are used to prevent
the shell from expanding the pattern junk* before it is passed to
SecondCopy. In the /copyright.notice example above, double quotes were
not needed because the pattern did not contain replaceable
characters.
To increase the speed of the process, the file contents are compared
after the directory information. If any portion of the directory
information has changed, the comparison of the contents will not take
place. In addition, the comparison of the contents will stop at the
first mismatch.
This chapter explains how to use SecondCopy by giving many command line
examples. Most of the time, SecondCopy will be called from a shell script
instead of being executed from a command line. We have prepared a
general purpose shell script that will hide most of the complexity of
the command line interface. Refer to the chapter on
backup.s.
24-sep-98incr/
24-sep-98inc/
Restoring Files
junk1 <Enter>
^d
$ secondcopy /dev/st0 restore
secondcopy version 0.12 07 February 1999
Copyright (C) 1992-1999 Brown Computer Company. All rights reserved.
junk1
junk1 restored
$
The tape will rewind, the volume name, sequence
number, and date of initialization will be
displayed. As the tape is read, the name of each
saved file is compared with the pattern you typed
through stdin. If the name and the pattern match,
an attempt will be made to open the file, as
named on the tape. If the open is successful, the
contents on the tape will be written to the file.
The original directory information, such as the
owner and the permissions, will be set and the
file will be closed.
/boot/image/hard.2 <Enter>
^d Verifying Files
![]()
![]()
![]()
![]()