LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-14-2008, 10:27 AM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 810

Rep: Reputation: 39
Encrypting and Subsequently Tarring the contents of a directory


Hi there --

I am involved with the writing of a script that is designed to first encrypt, then tar, and subsequently copy to tape. There are normally a series of subdirectories under the parent directory. The idea here is to individually encrypt and then tar the directories under the parent without having to make a separate copy of each encrypted file.

Listed below is the script that is being developed to accomplish this task:

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;}

# Run the tar, openssl, and tar command again to copy the encrypted file
# to the tape drive. Once the file is copied over, delete the original and
# the encrypted files from the directory. Repeat this process for for all
# files within the directory.
$cmd= "(cd $path; tar -czvf $FILENAME|openssl des3 -salt3 -k $PASSWORD |tar -cvf $FILENAME.des3 $DEVICENAME

# Once the initial tar, encryption, and copying of the encrypted file are comple
ted,
# go back to the directory and remove the tar and encrypted files. After that,
# repeat the procedure for the subsequent files in the directory.
# rm -rf $FILENAME
# rm -rf $FILENAME.des3

# Confirm the backup completed successfully, and send a notification to
# the system administrators.
What would the correct syntax be in order for the script to accomplish what is desired? Thanks.
 
Old 11-14-2008, 03:06 PM   #2
rjwilmsi
Member
 
Registered: Mar 2005
Location: UK
Distribution: opensuse 12.2 x86_64
Posts: 563

Rep: Reputation: 38
Personally I would achieve this using 7-zip which can automatically create an archive of an entire directory and all subdirectories, and include encryption of the archive created.
 
  


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
ftp directory and contents Josephus Ross Programming 1 04-10-2007 08:56 AM
list contents of directory without listing contents baddah Linux - Newbie 2 06-12-2006 04:02 AM
Directory contents in / wordlife Linux - General 2 12-11-2005 02:30 AM
mv the contents of one directory to the parent directory warkrime Linux - Newbie 4 07-14-2003 07:03 PM
Get directory contents vank Programming 6 10-19-2002 10:13 AM

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

All times are GMT -5. The time now is 08:25 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