backup_home.sh; request for feedback
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > backup_home.sh; request for feedback




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    backup_home.sh; request for feedback  
bob the builder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 11: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






[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
Benjamin Schieder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 11: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.





[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
bob the builder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 11: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]#






[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
Benjamin Schieder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-06 11: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





[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
Jeremiah DeWitt Weiner


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 11: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





[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
bob the builder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 11:23 PM

you are seriously retarded.






[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
Benjamin Schieder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 11: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





[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
bob the builder


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 11: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 dependen
t
>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.






[ Post a follow-up to this message ]



    Re: backup_home.sh; request for feedback  
No_One


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-25-06 07: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:39 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register