LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-23-2008, 09:09 AM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
Problem with tar piping through openssl to tape


Hi there --

A colleague and I wrote a perl script that is designed to change to a specific directory, and once there proceed to tar a directory, encrypt the newly created tar file, and then tar to tape media the encrypted tar file. Once that was done, the script would go back to the source directory, remove the tar and encrypted tar files, and repeat the process on all additional directories in the same location.

The command syntax that is used to accomplish this is the following:

Code:
#!/usr/local/bin/perl

# The purpose of this script is to run a tar backup on
# every file wihtin a specific directory. Each file in
# the directory will be tarred, and then encrypted.

# Once that is done, the encrypted file will then be
# copied to tape. After that, the encrypted and original
# tar files will then be deleted from the directory.

# This process will be repeated for every file within
# the directory.

# Uncomment the line below to debug the script.
# set -x

# Prompt the user for the directory in question:
print "Please enter the full path of the directory: \n";
$path = <STDIN>; 
chomp $path;
print "You have entered the following path: $path \n";

# Confirm the directory that was entered is the correct one.
print "Is $path the correct directory? [y/n] \n";
$confirm = <STDIN>; 
chomp $confirm;

# NOTE: The chomp command was inserted immediately after $confirm to ensure
# there was no end-of-line character (\n) that would intefere with script
# operations. 

if ($confirm ne "y") 
	{exit;}

# Prompt the user for the full pathname of the destination tape drive
# echo "Please enter the full devicefile name of the tape drive: "
# read devicefile
print "Please enter the full path of the device file: \n";
$device = <STDIN>;
chomp $device;
print "You have entered the following device file: $device \n";

# Confirm the device file that was entered is the correct one.
print "Is $device the correct device file? [y/n] \n";
$confirm = <STDIN>;
chomp $confirm;

# NOTE: The chomp command was inserted immediately after $confirm to ensure
# there was no end-of-line character (\n) that would intefere with script
# operations.

if ($confirm ne "y")
	{exit;}

# Remind the user there should already be a tape in the destination drive
# or else the script will fail.
print "Verify there is a tape in the destination drive before proceeding \n";
print "Shall we proceed? [y/n] \n";
$confirm = <STDIN>;
chomp $confirm;

# NOTE: The chomp command was inserted immediately after $confirm to ensure
# there was no end-of-line character (\n) that would intefere with script
# operations.

if ($confirm ne "y")
	{exit;}

# Prompt the user for the password that will be assigned to encrypted
# files that will be created and backed up to tape
print "Please enter the password that will be assigned to all of the \n";
print "encrypted files that will be backed up to tape. \n";
print "\n";
print "***************************************************************\n";
print "WARNING: BE SURE TO KEEP A GOOD AND SECURE RECORD OF THE PASSWORD\n";
print "THAT IS ASSOCIATED WITH THIS BACKUP. LOSING THIS RECORD WILL RESULT\n";
print "IN THE BACKED UP FILES NO LONGER BEING RETRIEVABLE.\n";
print "***************************************************************\n";
$password = <STDIN>;
chomp $password;
print "You have entered the following password: $password \n";
print "Shall we proceed? [y/n] \n";
$confirm = <STDIN>;
chomp $confirm;

if ($confirm ne "y")
	{exit;}

opendir(DIR, $path) or die "Can't open $path \n"; 
# The previous line determines if the path in question is accessible.
# If the path is not accessible, the script immediately exits.

my @list = sort readdir(DIR);
# This will provide a list of the contents of the directory in question,
# and store it in the @list array.

$first=1;
# The $first line tells the script whether the tar archive is being initially
# created, or appended to. This is necessary in order for the tar backup to
# append the directories to the archive rather than overwrite them. 
for (@list){
	chomp;
	next if $_ eq ".";
	next if $_ eq "..";
# The item in the @list array is stored in the $_ variable. This variable
# is used for the directories that are listed below the parent. All will
# be handled on an individual basis.
# The two next lines tell the script to not attempt to encrypt the directory
# entries "." and "..". These two are not real files, they are simply place
# holders that should not be backed up.

# The command syntax shown below will have the script change to the appropriate
# directory, and once there run the tar command and pipe it through openssl to
# create an encrypted tar file, .des3, that will be ready for copying to the
# tape drive.
$cmd= "(cd $path; tar -cvf - $_|openssl des3 -salt -k $password > $_.des3)";
print `$cmd`;
if ($first){
$cmd= "(cd $path; tar -cvf $device $_.des3)";
} else{
$cmd= "(cd $path; tar -rvf $device $_.des3)";
}
$RC=$?;
print `$cmd`;
$cmd= "(cd $path; rm $_.des3)";
print `$cmd`;
$first=0;
}

During a testing of the script, indications were the above process completed successfully. There was write activity on the tape drive, and no errors appeared on-screen. After the session was completed, the tape media was rewound, and the tar -tvf command was ran to list the contents of the tape. The output indicated that the first directory was backed up successfully, but there was no indication of any additional directories being backed up to tape. The mt -f <DEVICE> fsf 1 command was used to go to the end of the archive, and the tar -tvf command was reran to see if there were additional archives to the initial one on the tape, but there was no indication of any.

One thought that came to mind was to remove, or initially comment out, from the script the tar -rvf command, and rerun the script along with the follow-up tvf command. Would this approach work, or is there something else that needs to be done? Thanks.
 
Old 11-23-2008, 10:56 AM   #2
irishbitte
Senior Member
 
Registered: Oct 2007
Location: Brighton, UK
Distribution: Ubuntu Hardy, Ubuntu Jaunty, Eeebuntu, Debian, SME-Server
Posts: 1,213
Blog Entries: 1

Rep: Reputation: 88
To be honest, I think you are doing this backwards. I would encrypt directory that I want to archive, then tar the encrypted result, and archive it to tape? Just a thought.
 
Old 11-23-2008, 11:06 AM   #3
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Hi there --

Thanks for the reply. The only problem with that approach is that there is not enough space available to do that. As it is, there are typically seventy-three subdirectories under the source directory that need to be tarred, encrypted, and then the encrypted tar files tarred to the tape media. That coupled with the relative lack of disk space necessitates this approach.
 
  


Reply



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
Problem: tar Backup to Remote Tape Drive HaroldWho Linux - Software 8 07-30-2008 12:05 PM
Piping tar bzcat to add a file to a tar.bz2 archive DaveQB Linux - Software 0 06-02-2008 08:28 PM
Problem with dd and tar to tape hastur Linux - Software 0 10-22-2004 07:38 AM
Help restoring from tape and tar...... TheDirtyPenguin Linux - Software 1 02-17-2004 07:42 AM
HELP, corrupted tar tape Paul_assheton Linux - General 1 01-20-2004 10:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:40 AM.

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