LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-22-2005, 08:52 AM   #1
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Rep: Reputation: 15
Question shell scripting - help needed


hi

i'm writing a shell script which backs up data held in a mysql db, and ftp uploads it to a server. this works perfectly so far.

i plan to set this up as a cron job so it runs daily. however, i don't need to keep all the previous files containing exported data - i only need to keep, say, that last week or fortnights worth of files.

filename are in the format:

backup-yyyy-mm-dd.sql

if anyone has any suggestions that would be great

cheers
jon
 
Old 08-22-2005, 09:32 AM   #2
visaris
Member
 
Registered: Dec 2004
Distribution: gentoo
Posts: 190

Rep: Reputation: 30
Code:
mv foo.bar foo-backup-`date +%m-%d-%y`.bar
Something like that.

EDIT:
Ah, I misread your post, sorry.
 
Old 08-22-2005, 09:44 AM   #3
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
no worries

at the moment i've come up with something like this:

echo "Removing backup files older than 7 days..."
find /var/backup -name "backup-*.sql" -mtime +7 -exec rm -v '{}' \;

if anyone could suggest anything better that would be good
 
Old 08-23-2005, 05:39 AM   #4
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
also, is there any way of detecting whether the ftp login and upload was successful, so I can output the appropriate message. The ftp code in my script is as follows:

ftp -in << END-OF-SESSION
open server
user username password
bin
hash
prompt
put backup-$date.sql
bye
END-OF-SESSION

cheers
 
Old 08-23-2005, 06:25 AM   #5
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
I'm no expert, but maybe do something like ls backup-$date.sql just before bye, and then use an if statement to check if ls provides any output. Would be nice for you to share it once you've completed it though
 
Old 08-23-2005, 07:21 AM   #6
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
ok i'll give that a go

sure, i'll post the finished script here once finished
 
Old 08-23-2005, 07:40 AM   #7
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by tomj88
...but maybe do something like ls backup-$date.sql just before bye, and then use an if statement to check if ls provides any output....
problem is that between the END-OF-SESSION labels everything is treated as a ftp input. i can ls to get the output (or nothing if the file hasn't been uploaded) but then i dont know how i would go about checking this, because i am still in the ftp session
 
Old 08-23-2005, 07:44 AM   #8
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
hmm... could you use ssh? I suppose that could start to over complicate things though...
 
Old 08-23-2005, 07:47 AM   #9
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
oh cool there this ftp command

mls remote-files local-file
will write the result of ls remote-files to the local-file


Last edited by jonhewer; 08-23-2005 at 07:48 AM.
 
Old 08-23-2005, 07:48 AM   #10
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by tomj88
hmm... could you use ssh? I suppose that could start to over complicate things though...
no ssh available to me
 
Old 08-23-2005, 07:50 AM   #11
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
OK, but it looks like that mls might work I did have a perl based mysql backup program but that was bloated... If you want I could try and find that but as I said it was bloated, it would backup to tar.gz files, would email you if you wanted to, could ftp, and you could enable/disable all the options if I remember

edit: found it :P http://worldcommunity.com/opensource...ql_backup.html there if you want to look at it for any kind of reference. I also seem to remember it doing something that it shouldn't have done

Last edited by tomj88; 08-23-2005 at 07:52 AM.
 
Old 08-23-2005, 07:57 AM   #12
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
hey

i'll have a go using mls first see if that works nicely or not.

at the end of the day my code works perfectly, it just lacks some error handling - its only a small script to set up as a cron job so it'll be fine, but if i can get mls working to keep a log of uploaded files that would be handy!

will let you know how i get on.
 
Old 08-23-2005, 08:00 AM   #13
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
cool, I'm having a look at that perl script, it's very well commented but has a fair few options. If your script works then I would advise using it because if it breaks, you know how to fix it . Hope mls works...
 
Old 08-23-2005, 08:04 AM   #14
jonhewer
Member
 
Registered: Apr 2005
Location: London, UK
Distribution: Debian Lenny, Debian Etch, Ubuntu Hardy
Posts: 71

Original Poster
Rep: Reputation: 15
plus i have no experience of perl so wouldn't be able to modify your script to suit my needs

if this script i'm writing doesn't work as i need it, i may end up writing a simple python script
 
Old 08-23-2005, 08:11 AM   #15
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
Neither do I and it's broke straight away haha... I got a couple of tutorials bookmarked on shell scripting so I'm gonna have a go at that now see if I can help you some more .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
bash scripting --- some help needed rajsharma Linux - Software 1 09-09-2005 02:49 AM
Scripting help needed. stonelee Linux - Software 2 09-29-2003 09:47 AM
Shell scripting and background processes - help needed. trafalgar Programming 3 06-08-2003 09:15 AM


All times are GMT -5. The time now is 08:43 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration