Fedora Linux Support Community & Resources Center
  #1  
Old 5th April 2012, 01:36 AM
Argedion's Avatar
Argedion Offline
Registered User
 
Join Date: Dec 2009
Location: I Live in the USA - Georgia
Posts: 90
linuxfirefox
7zip question for a bash script.

I need to save a few folders from my phone's sdcard over to my harddrive. I have a bash already but want to make it a bit more usable for my needs. One of this issues I'm having with this is a proper command for 7zip in compressing a folder contents and then saving the compressed folder content on to the hard drive. Problem is I don't know the physical name of the folder I wish to save.

Example

I have directory /SDCARD/ConstantNameFolder/BDCES-*-*/*.*

so the first part of the directory I know the name however the last part that starts with BDCES is always changing depending on the date and time it was created so a normal look would be (BDCES-20120404-2021) I want to do this in a bash file because Its really easier to let the file run and copy everything over to the appropriate place on the Hard drive than it is for me to drag and drop. This way I can backup the contents of the card and do other things I need to do.

I've tried doing commands like this
7z -r /media/Storage/Phone/Nandroid/12345/BDCES-*-*/BDCES-*-*.7z /SDCARD/Nandroid/12345/
I get Error Incorrect Command Line

TIA

Argedion
__________________
Command Line Flunkie and a GUI Junkie
Currently using F17
androidforum.com for all android needs (Htc Evo 4G)
Reply With Quote
  #2  
Old 5th April 2012, 02:02 AM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,300
linuxfirefox
Re: 7zip question for a bash script.

See "man 7z" command.
You nee a function letter (like 'a' for add) as the first argument.

Ther eare warnings about using '-r', but I don't know the meaning.
The arg after the '-r' is an archive name and you may not want the '*' wildcard chars there
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #3  
Old 5th April 2012, 02:54 AM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 30
Posts: 1,695
linuxfirefox
Re: 7zip question for a bash script.

Ditto what stevea said.

Also, unless you have a good reason to use 7z, I'd recommend using Linux-native tools. If you need 7z's LZMA2 compression, the xz command does that:
Code:
tar cf - $dir | xz -9e > $backup.tar.xz
You can extract it with the graphical tool of your choice, or run:
Code:
tar xf $backup.tar.xz
If you do want to use 7z, I think the proper command is "7z a $backup.7z $sourcedir" ('a' for add, no '-r' needed – see the warning stevea mentioned).

---------- Post added at 02:54 AM ---------- Previous post was at 02:42 AM ----------

Quote:
Originally Posted by Argedion View Post
I have directory /SDCARD/ConstantNameFolder/BDCES-*-*/*.*
If I understand correctly, "*.*" is supposed to match all files inside the BDCES-* directory? That's a DOS-ism, and not how it works in Linux: "*" matches all (non-hidden) files, but in this case you're better off working with the directory name directly.

Quote:
I've tried doing commands like this
7z -r /media/Storage/Phone/Nandroid/12345/BDCES-*-*/BDCES-*-*.7z /SDCARD/Nandroid/12345/
I get Error Incorrect Command Line
The *'s in the .7z file name won't do anything here, as the 7z files haven't been created.

I'm not sure I quite understand what you want to do, but here's my suggestion (NOT TESTED!):
Code:
# Set these variables as you need.
source_dir="/media/Phone"
backup_dir="/media/Storage/Phone Backups"

pushd "$source_dir"
for dir in BDCES-*
do
    tar cf - "$dir" | xz -9e > "$backup_dir/$dir.tar.xz"
    # 7z a "$backup_dir/$dir.7z" "$dir"
done
popd
Reply With Quote
  #4  
Old 5th April 2012, 03:07 AM
Argedion's Avatar
Argedion Offline
Registered User
 
Join Date: Dec 2009
Location: I Live in the USA - Georgia
Posts: 90
linuxfirefox
Re: 7zip question for a bash script.

Quote:
Originally Posted by stevea View Post
See "man 7z" command.
You nee a function letter (like 'a' for add) as the first argument.

Ther eare warnings about using '-r', but I don't know the meaning.
The arg after the '-r' is an archive name and you may not want the '*' wildcard chars there
yeah i forgot the a also found out that i need to seperate the a from the 7z so instead of 7za i needed to use 7z a. So that part of my problem is solved now i need to figure out how to get the name and then save it to the harddrive with out affecting the other files that are also in the saved directory

I need to get a list of the child directory's then maybe save them as an array name or something

7z a /media/Storage/Phone/Nandroid/12345/BDCES-*-*/BDCES-$Date-(Numb).7z /SDCARD/Nandroid/12345/

any suggestions on how i can work that? I would like to do a variable so
instead of BDCES-*-*.zip maybe
NandFile(x)=BDCES-*-*
NandCompres =BDCES-date-(x).zip

---------- Post added at 10:07 PM ---------- Previous post was at 10:01 PM ----------

Quote:
Originally Posted by Gareth Jones View Post
Ditto what stevea said.

Also, unless you have a good reason to use 7z, I'd recommend using Linux-native tools. If you need 7z's LZMA2 compression, the xz command does that:
Code:
tar cf - $dir | xz -9e > $backup.tar.xz
You can extract it with the graphical tool of your choice, or run:
Code:
tar xf $backup.tar.xz
If you do want to use 7z, I think the proper command is "7z a $backup.7z $sourcedir" ('a' for add, no '-r' needed – see the warning stevea mentioned).

---------- Post added at 02:54 AM ---------- Previous post was at 02:42 AM ----------



If I understand correctly, "*.*" is supposed to match all files inside the BDCES-* directory? That's a DOS-ism, and not how it works in Linux: "*" matches all (non-hidden) files, but in this case you're better off working with the directory name directly.



The *'s in the .7z file name won't do anything here, as the 7z files haven't been created.

I'm not sure I quite understand what you want to do, but here's my suggestion (NOT TESTED!):
Code:
# Set these variables as you need.
source_dir="/media/Phone"
backup_dir="/media/Storage/Phone Backups"

pushd "$source_dir"
for dir in BDCES-*
do
    tar cf - "$dir" | xz -9e > "$backup_dir/$dir.tar.xz"
    # 7z a "$backup_dir/$dir.7z" "$dir"
done
popd
The main reason for doing it in 7zip is for when I'm in computer land hell I think they call it Windows. I find that 7zip is easier to use between the two OS'S
__________________
Command Line Flunkie and a GUI Junkie
Currently using F17
androidforum.com for all android needs (Htc Evo 4G)
Reply With Quote
  #5  
Old 5th April 2012, 03:13 AM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 30
Posts: 1,695
linuxfirefox
Re: 7zip question for a bash script.

Quote:
Originally Posted by Argedion View Post
[...] then save it to the harddrive with out affecting the other files that are also in the saved directory
[...]
The main reason for doing it in 7zip is for when I'm in computer land hell I think they call it Windows. I find that 7zip is easier to use between the two OS'S
In light of these two points, I'll amend my suggestion slightly:
Code:
# Set these variables as you need.
source_dir="/media/Phone"
backup_dir="/media/Storage/Phone Backups"

pushd "$source_dir"
for dir in BDCES-*
do
    # Assume that if a backup already exists,
    # it doesn't need recreating or updating.
    backup="$backup_dir/$dir.7z"
    [[ -f "$backup" ]] || 7z a "$backup" "$dir"
done
popd
Reply With Quote
  #6  
Old 5th April 2012, 09:54 AM
Argedion's Avatar
Argedion Offline
Registered User
 
Join Date: Dec 2009
Location: I Live in the USA - Georgia
Posts: 90
linuxfirefox
Re: 7zip question for a bash script.

Thank you kind sirs. When I return home from work I will try this out and report back how it all went for me.
__________________
Command Line Flunkie and a GUI Junkie
Currently using F17
androidforum.com for all android needs (Htc Evo 4G)
Reply With Quote
  #7  
Old 6th April 2012, 12:05 AM
Argedion's Avatar
Argedion Offline
Registered User
 
Join Date: Dec 2009
Location: I Live in the USA - Georgia
Posts: 90
linuxfirefox
Re: 7zip question for a bash script.

ok none of that seemed to work all i got zipped was the folder names and nothing in them it took all of two seconds to make. I've tried some variations but no luck with that either. So still working on this problem.
__________________
Command Line Flunkie and a GUI Junkie
Currently using F17
androidforum.com for all android needs (Htc Evo 4G)
Reply With Quote
  #8  
Old 10th April 2012, 05:28 PM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Leamington Spa, UK
Age: 30
Posts: 1,695
linuxfirefox
Re: 7zip question for a bash script.

I ran "7z a dir.7z dir" on a test dir, and it does archive the contents of the directory too.

Try changing the line to "echo 7z a ..." – this will print the commands that the script would run to the terminal instead of actually running them. Check that the commands shown have the intended arguments.
Reply With Quote
Reply

Tags
7zip, bash, question, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script question nat0925 Using Fedora 5 31st October 2010 07:09 PM
rpm question with regards to bash script schotty Using Fedora 5 26th March 2010 07:55 AM
bash script backup if else question crainey69 Linux Chat 1 20th January 2009 03:32 AM
bash script/zenity question daviddoria Using Fedora 4 20th October 2008 07:15 PM
Bash Script Question SkyFlyer Using Fedora 0 28th August 2007 11:07 PM


Current GMT-time: 06:45 (Monday, 20-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat