|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
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 ![]() |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
Quote:
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 ![]() |
|
#5
|
||||
|
||||
|
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) |
|
#6
|
|||
|
|||
|
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
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > Backup Solution needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|