LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-13-2012, 06:48 AM   #1
shubhamuddu
LQ Newbie
 
Registered: Jun 2012
Posts: 24

Rep: Reputation: Disabled
Tape drive backup and Restore


Hi ...




Am using ultrium LTO4 sas IBMtape drive in RHEL 5.5 for backup.



Device name is /dev/IBMtape0
Someone has written a script for backup as monday is full backup and for rest of the days partial backup, used the below command in the script for backup.
$TAR $TAR_ARGS -cvzpf $TAPE $DIR $BACKUP_ROOT_DIR
when i issue tar -tvzf it lists files in the tape.

when i issue tar -tvzf it lists files in the tape.
but how can i know which date backup it is listing.

Please tell me how to create a directory with date in tape drive so backup should go into the created directory.
And also please tel me how to restore files from tape drive.

Thank you for all.
 
Old 06-13-2012, 08:29 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
The command
Code:
tar -tvzf path_to_tape
should list the content with the date of each file.

If you want to extract you substitute the t with x; however, that will extract everything (which you may not want). To extract one file from the archive you would use
Code:
tar xzvf archive_name file_name_in_archive
I have a compressed archive named moneydance_other.tar.gz and I want to view one file, moneydance/moneydance.xpm from it:
Code:
tar -tvzf moneydance_other.tar.gz moneydance/moneydance.xpm
-rw-r--r-- sreilly/staff  6278 2001-02-01 09:16 moneydance/moneydance.xpm
If I wanted to extract that file, I would change -tvzf to -xvzf to do so.

The above is the GNU version of tar (but most will work like this). You may want to read the manual page for tar or the info page for tar or, using Google, search for "linux tar." Here is one page that you may find useful (and full of examples) http://www.computerhope.com/unix/utar.htm.

Hope this helps some.
 
1 members found this post helpful.
Old 06-14-2012, 06:12 AM   #3
shubhamuddu
LQ Newbie
 
Registered: Jun 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Tape drive backup and restore

Hi..

Really helpfull information.

Here is the thing.
Script had the line $TAR $TAR_ARGS -cvpf $TAPE $BACKUP_ROOT_DIR(with no archive name)

As i wanted to create a compressed archive in the tape so modified it as

#name for the archive in the tape
DIR=mkdir TEST_BKP_$(date '+%d%m%Y')

$TAR $TAR_ARGS -cvzpf $TAPE $DIR $BACKUP_ROOT_DIR

Still couldn't able to find the name of the archive or directory in the tape.(only listing files)
I think archive is not being created in the tape.

please guide me how to create a archive name with current date in the tape.
(Where archive name should be mentioned in the below tar line)
$TAR $TAR_ARGS -cvpf $TAPE $BACKUP_ROOT_DIR.

Also when i extract file from tape which location file will be placed.
(I mean whether in the present working directory where issuing the command or in the original location)

Thanks...
 
Old 06-14-2012, 11:50 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
The way your shell program is written, the first argument to the tar command ($TAR) is the tape drive ($TAPE); i.e., /dev/IBMtape0. So, the tape is the tape archive (that's what tar means, an acronym of tape archive. So, what you see on the tape is a list of directory and file names that are a copy of the location (directory) and content (file).

The other way to look at that is if you used tar to create a file named, say, 2012-06-14.tar (for example) somewhere on your disk drive(s) then compress that into what's called a tarball (say, 2012-06-14.tar.gz) then copy that to the tape as one big (but compressed) tar archive. You'd do that something like this
Code:
tar cvf 2012-06-14.tar $DIR $BACKUP_ROOT_DIR
<wait a while>
gzip 2012-06-14.tar
<which compresses the archive into 2012-06-14.tar.gz>
cp 2012-06-14.tar.gz /dev/IBMtape0
You can do that in a pipeline (see below) but those are the basic steps to get a date stamped compressed archive on tape (or CD-ROM or DVD or Blu-ray disc media for that matter). The way your shell program is doing it, the archive is not compressed or date stamped.

You have to consider, though, whether you have sufficient room on the tape for more than one back up of the system root (or whatever file tree on the disk drive) directory (some tape systems do, some don't, some will write on more than one cartridge, some won't). It may be simpler to, you know, write the date on the label and be done with it.

A slick way to create the archive file name is
Code:
tar -cvf `date +%F`.tar.gz <other arguments>
If you want to add a directory name to that
Code:
tar -cvf /tmp/`date +%F`.tar <other arguments>
Those "`...` are "sideways pipes," they can also be done $(date +%F) (definitely in KornShell, pretty sure in BASH too).

Now, let's combine stuff.

You can compress on-the-fly by adding z for gzip or j for bzip2 in the tar arguments:
Code:
tar -czvf /tmp/`date +%F`.tar.gz <other arguments>
for gzip (replace the z with j for bzip2.

You might want to avoid the v (which shows you the file names) unless you're keeping a log.

So, all in one go
Code:
# Create a date stamp name for the archive
FILE_NAME=/tmp/`date +%F`.tar.gz
# Create a gzip tar archive in /tmp/yyyy-mm-dd.tar.gz
tar czf $FILE_NAME $DIR $BACKUP_ROOT_DIR
# Copy the archive file to tape
cp $FILE_NAME $TAPE
# Remove the archive file
rm $FILE_NAME
You can do the entire thing in one line but you have to use dd to do it which means that you have to know the input block size of the tape and some other stuff. Just as easy to use two line to accomplish the job.

Hope this helps some.

Last edited by tronayne; 06-14-2012 at 11:51 AM. Reason: Typo
 
1 members found this post helpful.
Old 06-14-2012, 07:45 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,415

Rep: Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785Reputation: 2785
Just a comment on post #3
Code:
# this doesn't work
DIR=mkdir TEST_BKP_$(date '+%d%m%Y')

# I think you meant
DIR=TEST_BKP_$(date '+%d%m%Y')
mkdir $DIR

Also
Code:
$TAR $TAR_ARGS -cvpf
looks odd. The syntax for tar is tar [options] file... http://linux.die.net/man/1/tar
'-cvpf' are the options.. I think you meant
Code:
TAR_ARGS=-cvpf
$TAR $TAR_ARGS $FILE_NAME...
as per Tronayne's explanation.
 
Old 06-15-2012, 12:37 AM   #6
shubhamuddu
LQ Newbie
 
Registered: Jun 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Got it...
See the script for the full backup and partial backup.
For partial backup aleso tar acrchive will be created..?
And please correct if the script is wrong anad also when i type
mt -f /dev/IBMtape0 erase it took hours and get device busy..
How to delete a tar archive,files, directories in the Tape.

# Backup logs are stored here
LOGBASE=/root/backup/log

# Backup dirs; do not prefix /
BACKUP_ROOT_DIR="u05 "

# Get todays day like Mon, Tue and so on
NOW=$(date +"%a")

# Tape device name
TAPE="/dev/IBMtape0"

# Exclude file
TAR_ARGS=""
EXCLUDE_CONF=/root/.backup.exclude.conf

# Backup Log file
LOGFIILE=$LOGBASE/$NOW.backup.log

# Path to binaries
TAR=/bin/tar
MT=/bin/mt
MKDIR=/bin/mkdir

# ------------------------------------------------------------------------
# Excluding files when using tar
# Create a file called $EXCLUDE_CONF using a text editor
# Add files matching patterns such as follows (regex allowed):
# home/vivek/iso
# home/vivek/*.cpp~
# ------------------------------------------------------------------------
[ -f $EXCLUDE_CONF ] && TAR_ARGS="-X $EXCLUDE_CONF"

#### Custom functions #####
# Make a full backup
full_backup(){
local old=$(pwd)
# Create a date stamp name for the archive
FILE_NAME=/tmp/`date +%F`.tar.gz
# Create a gzip tar archive in /tmp/yyyy-mm-dd.tar.gz
tar czf $FILE_NAME $DIR $BACKUP_ROOT_DIR
# Copy the archive file to tape
cp $FILE_NAME $TAPE
# Remove the archive file
rm $FILE_NAME
$MT -f $TAPE rewind
$MT -f $TAPE offline
cd $old
}
[ $? -eq 0 ] && status="Success!" || status="Failed!!!"
mail -s 'Backup status=$status' < mail id>
The backup job finished.

End date: $(date)
Hostname : $(hostname)
Status : $status
# Make a partial backup
partial_backup(){
local old=$(pwd)
cd /
$TAR $TAR_ARGS -cvzpf $TAPE -N "$(date -d '1 day ago')" $BACKUP_ROOT_DIR
$MT -f $TAPE rewind
$MT -f $TAPE offline
cd $old
}
[ $? -eq 0 ] && status="Success!" || status="Failed!!!"
mail -s 'Backup status' <mail id>
The backup job finished.
End date: $(date)
Hostname : $(hostname)
Status : $status

# Make sure all dirs exits
verify_backup_dirs(){
local s=0
for d in $BACKUP_ROOT_DIR
do
if [ ! -d /$d ];
then
echo "Error : /$d directory does not exits!"
s=1
fi
done
# if not; just die
[ $s -eq 1 ] && exit 1
}

#### Main logic ####

# Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE

# Verify dirs
verify_backup_dirs

# Okay let us start backup procedure
# If it is monday make a full backup;
# For Tue to Fri make a partial backup
# Weekend no backups
case $NOW in
Mon) full_backup;;
Tue|Wed|Thu|Fri) partial_backup;;
*) ;;
esac > $LOGFIILE 2>&1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OS backup to a tape drive scopiansl Linux - Server 5 09-27-2011 09:54 PM
How do i backup onto tape drive? Astol Linux - Server 2 09-13-2007 09:10 PM
Using a DDS5 tape drive to restore from a DDS3 backup tape. AndrewCAtWayofthebit Linux - Hardware 1 05-14-2006 10:15 AM
Backup to tape drive kwtan Linux - Software 1 01-11-2006 11:11 PM
Old slackware tape backup - need to restore rah Slackware 14 04-10-2003 12:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration