LinuxQuestions.org
Visit Jeremy's Blog.
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 07-29-2021, 08:00 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
A gpg --batch question


The end of the month is approaching - time for my monthly off site data backup. I tar and gzip my important data files by directory and upload them to my ProtonDrive storage facility. I also upload a copy to my storage facility at mega.nz. As I am not sure I really trust mega I wrap the files in pgp before uploading them. I have entered the passphrase into the memory variable PASS in my backup script and after producing the .tar.gz files I execute
Code:
find /data/stage/ -name "*.tar.gz" -exec gpg --batch --passphrase "$PASS" -c {} \;
This works great EXCEPT that it puts each ,gpg file in the same directory as the .tar.gz file from which it was created. This requires me to manually separate the files into two directory trees prior to uploading.

I am looking for a way to write the .pgp files to a different directory location during the gpg process rather than moving them later. I find nothing in the man page for gpg which addresses the destination directory. Does anyone have a suggestion?

TIA,

Ken
 
Old 07-29-2021, 01:28 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,738

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
I find this in the gpg man page:
Code:
 --output file
-o file
Write output to file.
I presume that file could be a full pathname to the output file…
 
1 members found this post helpful.
Old 07-29-2021, 02:25 PM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks scasey,

The man page is rather overwhelming. I missed that option. This will be interesting. I have used the "find ... -exec some command {} \;" method to deal with a bunch of files in numerous directories for a long time. I have never tried using the found file expression {} for anything but telling the command what file to operate on. I will have to do some sed operation on the path and name of the input file to generate the name of the output file. I will see what I can do and post back with my success (or not).

Ken

Update: I am cooking with gas

I could not stuff the whole thing into a single "find ... exec {}" command so here is what I came up with
Code:
PASS=testpasswordfornow

for sourcefile in $(find /quitelarge/upload/proton/ -name *.gz)
do
  destfile=$(echo $sourcefile | sed 's;/quitelarge/upload/proton;/quitelarge/upload/mega;')
  gpg --batch --passphrase "$PASS" -o $destfile.gpg -c $sourcefile
done
If I may explain...

I will be changing my main script to write the .tar.gz files to the /quitelarge/upload/proton/ directory tree. This is on a secondary PCIe SSD. The data originates in the /data/ tree on my primary PCIe SSD. tar should run rather FAST (and it is only a couple of GB of data total) The files to be uploaded to ProtonDrive do not need to be encrypted. Once this is complete I will run the code shown above. This will place the encrypted files in the same locations in the /quitelarge/upload/mega/ tree. These I will upload to mega.nz. I have also prepared code to create the necessary directory structure from scratch so I can delete the whole /update/ tree once I have completed the monthly backup and then recreate it from the script next month. A few more tweaks and enhancements and I will be ready to go.

Thanks again scasey! You have made my day.

p.s. A couple of comments about the sed command. A routine find and replace with sed is usually shown as something like
Code:
sed '/changethis/tothat/'
When changing paths which contain / characters - rather a pain. I found a thread over on stackoverflow which pointed out that the / / / in the sed command is an arbitrary delimiter. Using a ; or + or some other character works just as well and there is no need to try and escape the / characters in that paths. That was also a great tip.

Last edited by taylorkh; 07-29-2021 at 07:42 PM.
 
  


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
gpg / gpg-agent -- Can't connect to /root/.gnupg/S.gpg-agent jrtayloriv Linux - Security 9 06-03-2019 10:06 AM
[SOLVED] gpg: WARNING: unsafe permissions on configuration file `/home/b/.gnupg/options' gpg: widda Mandriva 9 07-30-2018 07:49 AM
[SOLVED] how to write a batch file in linux?and what are batch(.bat) file benefits? karthilin Linux - Newbie 8 10-15-2012 02:10 PM
GPG: Bad session key gpg between gpg on linux and gpg gui on windows XP konqi Linux - Software 1 07-21-2009 09:37 AM
gpg in batch mode - help cricos Linux - Newbie 1 01-21-2006 08:14 PM

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

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