Unix Shell - backup_home.sh; request for feedback

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2006 > backup_home.sh; request for feedback





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author backup_home.sh; request for feedback
bob the builder

2006-01-23, 6:13 pm

#!/bin/bash
# add the to crontab for a nightly backup of your homedir

EMAIL=youraddress@someserver.com
TIMESTAMP=$(date +%Y%m%d%H%M%S)
tar cjvf $TIMESTAMP.tar.bz2 ~/bin ~/.bash_history
cat $0 | tail -n1 | gpg -c --passphrase-fd 0 $TIMESTAMP.tar.bz2
echo | mutt -s "Backup - $TIMESTAMP" -a $TIMESTAMP.tar.bz2.gpg $EMAIL
rm -f $TIMESTAMP.tar.bz2 $TIMESTAMP.tar.bz2.gpg

exit 0
password

Benjamin Schieder

2006-01-23, 6:13 pm

bob the builder wrote:
> #!/bin/bash
> # add the to crontab for a nightly backup of your homedir
>
> EMAIL=youraddress@someserver.com
> TIMESTAMP=$(date +%Y%m%d%H%M%S)
> tar cjvf $TIMESTAMP.tar.bz2 ~/bin ~/.bash_history
> cat $0 | tail -n1 | gpg -c --passphrase-fd 0 $TIMESTAMP.tar.bz2


useless use of cat. use tail -n 1 $0

> echo | mutt -s "Backup - $TIMESTAMP" -a $TIMESTAMP.tar.bz2.gpg $EMAIL
> rm -f $TIMESTAMP.tar.bz2 $TIMESTAMP.tar.bz2.gpg
>
> exit 0
> password


Greetings,
Benjamin

--
Today, memory either forgets things when you don't want it to,
or remembers things long after they're better forgotten.
bob the builder

2006-01-23, 6:13 pm

thanks, I am sure that will save me at least 3 nanaoseconds.

lets find out

[root@vmware01 bin]# time ohfortheloveofgod_using_cat.sh
.....

real 0m0.009s
user 0m0.000s
sys 0m0.008s
[root@vmware01 bin]# time ohfortheloveofgod_without_cat.sh
.....

real 0m0.006s
user 0m0.000s
sys 0m0.008s
[root@vmware01 bin]#

Benjamin Schieder

2006-01-23, 6:13 pm

bob the builder wrote:
> thanks, I am sure that will save me at least 3 nanaoseconds.


not to mention a wasted PID

Greetings,
Benjamin

--
Benjamin 'blindCoder' Schieder
Registered Linux User #289529: http://counter.li.org
finger blindcoder@scavenger.homeip.net | gpg --import
--
/lusr/bin/brain: received signal: SIGIDIOT
Jeremiah DeWitt Weiner

2006-01-24, 6:23 pm

bob the builder <ewaguespack@gmail.com> wrote:
> thanks, I am sure that will save me at least 3 nanaoseconds.


A) When you're replying to a post, quote some context. Google Groups is
a crappy interface for posting to the web, so don't use it.

B) It's not about saving three nanoseconds, it's about knowing how to
use your tools. If you don't know how to use them properly, it will
come back to bite you sooner or later when there is some side effect of
which you weren't aware.
Also, even "three nanoseconds" have a way of adding up over time.
At my job, I discovered a shell script which parses a log file,
splitting it into smaller files. For each line, it opens an output
file, writes the line, and closes the output file. Simple, huh? And
what's an open() and close() take, three nanoseconds? Unfortunately,
when you have a two-million-line input file, that begins to add up...

To return to your original script:

> EMAIL=youraddress@someserver.com
> TIMESTAMP=$(date +%Y%m%d%H%M%S)
> tar cjvf $TIMESTAMP.tar.bz2 ~/bin ~/.bash_history


I thought the comment said it was to back up your home directory?
Also, what happens if the tar fails, perhaps because the partition is
full, or permissions got messed up?


> cat $0 | tail -n1 | gpg -c --passphrase-fd 0 $TIMESTAMP.tar.bz2


I like the fact that you're encrypting your backup, but you're
keeping your GPG passphrase in a plain text file? Well, it's your
system. And you're still not checking any return values. What happens
if $0 isn't there, or has zero lines?

> echo | mutt -s "Backup - $TIMESTAMP" -a $TIMESTAMP.tar.bz2.gpg $EMAIL


Useless use of echo. Could be replaced with "mutt ... < /dev/null"

> rm -f $TIMESTAMP.tar.bz2 $TIMESTAMP.tar.bz2.gpg
>
> exit 0


Seems like kind of a funny thing to assert, since it's not dependent
on whether anything else finished properly or not.

> password


I assume that's just a stray line.


--
Oh to have a lodge in some vast wilderness. Where rumors of oppression
and deceit, of unsuccessful and successful wars may never reach me
anymore.
-- William Cowper
bob the builder

2006-01-24, 6:23 pm

you are seriously retarded.

Benjamin Schieder

2006-01-24, 6:23 pm

bob the builder wrote:
> you are seriously retarded.


Okay, let me get this straight:
1) ask for help
2) get help
3) insult people for helping you

ehm, where does this lead you?

Greetings,
Benjamin

--
Benjamin 'blindCoder' Schieder
Registered Linux User #289529: http://counter.li.org
finger blindcoder@scavenger.homeip.net | gpg --import
--
/lusr/bin/brain: received signal: SIGIDIOT
bob the builder

2006-01-24, 6:23 pm

> > you are seriously retarded.
>
> Okay, let me get this straight:
> 1) ask for help
> 2) get help
> 3) insult people for helping you
>
> ehm, where does this lead you?


OK... you are right, that was not called for, I'll be specific on why
you are retarded.

>A) When you're replying to a post, quote some context. Google Groups is
>a crappy interface for posting to the web, so don't use it.


um, your not my mommy.

> Also, even "three nanoseconds" have a way of adding up over time.

....
if you are so concerned about performance, why are you not using C? or
better yet assembly?

>What happens if $0 isn't there, or has zero lines?


do you know what $0 is? clearly not, let me educate you:

$0 is the name of the current script running

>Useless use of echo. Could be replaced with "mutt ... < /dev/null"


i know its useless, but i dont care, its more readable, i am not going
to debate this.. other than saying performance at the cost of
readability in simple scripts is a silly thing.

[vbcol=seagreen]
[vbcol=seagreen]
> Seems like kind of a funny thing to assert, since it's not dependent
>on whether anything else finished properly or not.


yeah well i guess i am funny then

[vbcol=seagreen]
> I assume that's just a stray line.


$0...


So basically in a nutshell I was fishing for more meaningful feedback,
I wasn't trolling for the "Useless Use of Cat / Echo" Nazis to come out
of the woodwork and teach me the insultingly obvious.

No_One

2006-01-25, 2:58 am

On 2006-01-24, bob the builder <ewaguespack@gmail.com> wrote:
>
>
> um, your not my mommy.


It's not a question of anyone being your mommy, it's a question, as
previously explained, about people knowing what you're talking about and
what your referencing from a prior post....simple enough.

>
> ...
> if you are so concerned about performance, why are you not using C? or
> better yet assembly?


C or assembly isn't used for obvious reasons....


>
>
> i know its useless, but i dont care, its more readable, i am not going
> to debate this.. other than saying performance at the cost of
> readability in simple scripts is a silly thing.


You have trouble reading < /dev/null?


>
>
>
>
> yeah well i guess i am funny then


You asked for feedback...the above comment about the exit reference is
entirely valid....that's not the kind of feedback you want??


> So basically in a nutshell I was fishing for more meaningful feedback,
> I wasn't trolling for the "Useless Use of Cat / Echo" Nazis to come out
> of the woodwork and teach me the insultingly obvious.


You asked for feedback, you were given some valid suggestions....what the
hell else do you want....praise for brilliantly scripted scripts?

ken
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com