Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 31st, 2002, 12:33 PM
MRK's Avatar
MRK MRK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 191 MRK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 8
Backup Solution needed

Ok, i have a small site that i run that has a lot of data on it that changes every week. I would like to do two things. I'm not sure how to go about doing this, but i have a general idea. Its just makeing it happen that i dont get.

There would be two differnt things i would do.

First would be a weekley proccess that runs every week. This process would do three things.
1. It would dump all the data in a mysql db into an sql file.
2. It would then tar or zip that into a file that had the date in the file name. IE: backup_20023012.tar or something like that. Just something so that i know when it was made.
3. It would then email this file to me. (would be a differnt email server. (remote)

The second thing it would is a monthly procedure. These are the steps it would take.
1. It would tar or zip all of the files in /var/www/html (or whatever directory i choose) into a file that included that date. IE: montly_20021230.zip, etc..
2. It would then email that file to my email address.


If this were windows, i would write a batch file and then put that in the task scheduler to be run when ever i say. I know that in linux i'll use the cron deamon. and i know that the cron.weekley, and the cron.monthly are the ones i would use. But i'm not sure how to make it do this. I'm also not sure about how i would go about creating a file that would do this. Would a shell script be used? I dont know c or c++ or any other linux bassed programming lanugage yet.

I would appriciate any help or advice you can give very much. I need to get a backup solution running on my system as soon as possible. Right now, i do these tasks by hand. I just thought i would automate this proccess. Thanks again!!

-Mr.K

Reply With Quote
  #2  
Old December 31st, 2002, 01:59 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Re: Backup Solution needed

Well, shell scripting is a lot like batch scripting, only it has a lot of extra nice stuff to work with if you want. So, if you just want to run a list of commands that you already know - just throw them in a file (put "#!/bin/sh" at the top to notify that it's a shell script), put that wherever you want, and write a cron job that will call that whenever.

But, if you want to do some more advanced stuff (this stuff you listed doesn't need any of the shell niceties that are there), then I know plenty and can help you out if you want
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #3  
Old December 31st, 2002, 02:50 PM
MRK's Avatar
MRK MRK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 191 MRK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 8
Ok, that sounds pretty easy. I have all the commands i want to do exept the email part. How would i send the file in an email? (as far as doing it from the command line) Thanks for your help!!

-Mr.K

Reply With Quote
  #4  
Old December 31st, 2002, 06:43 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Quote:
Originally posted by MRK
Ok, that sounds pretty easy. I have all the commands i want to do exept the email part. How would i send the file in an email? (as far as doing it from the command line) Thanks for your help!!

-Mr.K

Assuming you have some sort of MTA (Mail transport agent, my favorite is postfix) installed, the command is simply mail. I'm not entirely too clear on the syntax, but it's something like:

echo "This is my message" | mail -s "Your subject here" foo@recipient.com

So, mail reads (I think, check the man page on this), text and attachments from stdin, and then you simply do mail and the recipients address to send to that person, with an optional subject or some other header or two or six.

So, in short, mail is what you want, but I'll let you toy around with it to see if you can get it working first

Reply With Quote
  #5  
Old January 5th, 2003, 06:32 PM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 sec
Reputation Power: 11
You can't create an email attachment without wheeling out Perl or something to create all the MIME boundary junk that's required to do attachments. MIME::Lite is your friend here.

The mysqldump file can be emailed to you as text, as that's what it is. But for the binary .tar.gz we need to take a different approach. One approach would be to have the file uuencoded then emailed to you, and then you can uudecode it down your end. Basically, uuencode will take a binary file and output a text representation of it, which can be sent in a plain text email.

So, do something like this (for your mysql dump example):

Code:
mysqldump -u username -pmypassword | mail -s 'mysqldump' you@you.com

and for the site backup:
Code:
tar zcvf /tmp/backup.tar.gz /var/www/html
uuencode /tmp/backup.tar.gz /dev/null | mail -s 'uuencoded backup of /var/www/html' you@you.com
rm -f /tmp/backup.tar.gz


To automate all this, stuff the above commands in a file called backup.sh or something like that, copy it to your home directory (/home/you) then change your crontab (using crontab -e) to add this line:

Code:
30 06 * * * sh /home/you/backup.sh > /dev/null


Every day at 6:30 am the backups will land in your mailbox. You can decode the .tar.gz back to that using uudecode.


Hope this helps.


Alex
__________________
Alex
(http://www.alex-greg.com)

Reply With Quote
  #6  
Old May 24th, 2003, 04:04 PM
tomcat5239 tomcat5239 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 tomcat5239 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can anyone give me an idea of how to modify this script to FTP the files to a remote server instead of e-mailing them to an address? It would make backups much simpler for me. Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Backup Solution needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway