• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Bash Expert Needed

argedion

The TechnoFrog
If there is a Bash expert willing to help me figure out an issue I'm having with a bash file.

The issue I want to Save my Nandroids over to the Harddisk however I am not going to know the names of the folders with exception to BCDES the rest of the name is date and time of nandroid obviously I need to get those into a variable and then 7zip them over to the hard drive. Anyone have any Ideas of how I can get this to work?

So basically it will look like
/media/SDCARD/nandroid/HNUMBER/BCDES-20120405-2234
/media/SDCARD/nandroid/HNUMBER/BCDES-20120403=1744

need to grab those in an array variable i assume something like
$NandStore(x)

then a simple loop to 7zip them over to the hard drive.

TIA
 
I'm working on a script for ya, I'd say it's nearly done, I want to have it working before I send it over (to save face mostly), but could you not just grab the whole nandroid folder?

also, I don't have 7zip installed, so I'll be using tar, but I'm sure you can swap that part out (along with the other parts that'll obviously need to be changed)

Just to clear it up, you're gonna run this from the computer right?
 
Okay, here we go, I *think* this does what you want.
just an fyi, I'm using tar because i don't have 7zip.... it is set to tar and gzip the file in one go. So, that's nice.

Also, it currently saves the file to /tmp/backup (which you could easily change), but when extracted, it recreates the full path of the original file, so you end up with something like this:
/tmp/backup/tmp/sdcard/FILES

Also, I was only copying files from /tmp/sdcard/H-{1,2,3,4}
Each one of those directories had a few txt files in it to see if it was working. Those all copied fine for me.

code:
Code:
#!/bin/bash
#Okay, sd_path, for you this will be something like /mnt/ANDROID/path/to/nandroids/HNUMBER/
sd_path='/tmp/sdcard/'
ls $sd_path > /tmp/sdpath
var=$(cat /tmp/sdpath)
for line in $var
do
    tar czfv /tmp/backup/${line}.tar.gz $sd_path${line}
done
I think that will do what you want. And I'm *sure* there are much better ways to do this than I've done, but I'm quite the noob at this. I just find it kinda fun.
 
First Thanks a bunch for the help :D

Ok This is working however its putting all the files in one zip and it repeats for every folder

example
/HNUMB/BCDES-20120404-544
/HNUMB/BCDES-20120405-1720

Both of those will go in
BCDES-20120404-544
then it saves both in
BCDES-20120405-1720

I'm going to try taking out the loop and see if it does the whole folder just once if so that's close enough for me to get the rest of the bash working.

I also agree that writing bash is fun :D
 
yeah I removed the loop and it only makes 1 zip of all the files so really i could probably just have it zip the /HNUMBER folder and remove all the extra code. which is fine I never keep more than 3 nands on at a time anyways.
 
weird, I'll try to describe what's going on on my end.

Files to be copied are located it /tmp/sdcard/HC-{1,2,3,4}
Within these directories are three files (to simulate the *.img files).

When I run it, it backs up each directory independently of the others into four .tar.gz files. Oddly, when I extract these files, the path is as follows:

/tmp/backup/ # where all the .tar.gz files go
/tmp/backup/tmp/sdcard/HC-1/ # three txt files
/tmp/backup/tmp (2)/sdcard/HC-2/ # three txt files

The layout isn't what I pictured (throwing each one in ../tmp/sdcard/....), but other than that, it isn't coping multiple directories into each tar file....

what is the line you're using with 7zip (just for curiosity's sake)
 
weird, I'll try to describe what's going on on my end.

Files to be copied are located it /tmp/sdcard/HC-{1,2,3,4}
Within these directories are three files (to simulate the *.img files).

When I run it, it backs up each directory independently of the others into four .tar.gz files. Oddly, when I extract these files, the path is as follows:

/tmp/backup/ # where all the .tar.gz files go
/tmp/backup/tmp/sdcard/HC-1/ # three txt files
/tmp/backup/tmp (2)/sdcard/HC-2/ # three txt files

The layout isn't what I pictured (throwing each one in ../tmp/sdcard/....), but other than that, it isn't coping multiple directories into each tar file....

what is the line you're using with 7zip (just for curiosity's sake)
trying to remember the exacts but I think it was close to something like this:
ls $sd_path > /tmp/sdpath
var=$(cat /tmp/sdpath)
for line in $var
do
tar czfv /tmp/backup/${line}.tar.gz $sd_path${line}
7z a $sd_path${line}.7z /tmp/sdpath/${line}
done

the only reason I didn't use tar is not supported in windows without 7zip. tar also keeps permissions (which is very handy in Linux) however in Windows its totally overlooked. anyways originally i just wanted to store the current folders over to the hard drive in zip format so as to easily go between them in windows and linux if needed. it's not catastrophic the way it is. just have a couple of nands in one zip instead of 1 per zip. I'm still working on the bash there are like 7 parts of it backing up, updating, and compressing. Oh yeah I forgot about removing stuff that is no longer needed as well. I'm getting ready to try and error proof it.
 
Hmm... I'll have to see about installing 7zip and fooling around with that for a while.... Well, it's not perfect, but it looks like it's heading in the right direction...

;D
 
Back
Top Bottom