Visit Our UNIX and Linux User Community


Backing Up and Emailing Home Directory and SQL Databases


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Backing Up and Emailing Home Directory and SQL Databases
# 1  
Old 07-30-2009
Backing Up and Emailing Home Directory and SQL Databases

Hello,

I run a web hosting company, and I'm wondering how I can use cPanel's Cron Jobs so that a copy of my entire home directory and a copy all of my MySQL databases can be compressed and emailed to me. I know nothing about Linux, Unix, or whatever that thing with the penguin is called. Smilie

Anthony
# 2  
Old 07-30-2009
Now here is a question, where did you install cPanel? Smilie
It has to be Linux/Unix. The thing with Penguin.. Smilie That's Tux, de-facto Linux mascot


Here is a simple MySQL dump script, it'll rotate weekly:
Code:
#!/bin/bash
export week_day=`date +%u`
mkdir -p /some_path/mysql_backup/$week_day
for i in `echo "show tables" | mysql -u username -ppassword database|grep -v Tables_in_`;
do
  echo $i; mysqldump --add-drop-table --allow-keywords -q -a -c -u username -ppassword database $i > backup/$week_day/$i.sql
  rm -f backup/$week_day/$i.sql.gz
  gzip backup/$week_day/$i.sql
done

To set cron:
Code:
30 0 * * * /path_to_script/mysql_backup_script >/dev/null 2>&1

This will run your backup script at 12:30 AM, everyday.
As for mailing, I have a script somewhere, I'll have to dig it up.

-Nitin
# 3  
Old 07-30-2009
I am a hosting reseller account, so it was automatically installed for me.

I did some Linux research online, and I found out how to compress the contents of my public_html directory. Now I just need to figure out how to send that file to my email and then delete the file off of the server.

Here's the command I used for compressing my public_html directory

Code:
date=`date -I` ; tar -zcf backup_$date.tgz ./public_html

Also, how does that SQL thing work, and how do I change the script to fit my needs?

Last edited by millipedeman; 07-30-2009 at 04:37 PM..
# 4  
Old 07-30-2009
Try this for mailing:

Code:
 uuencode backup.tar.gz | mailx -s "My backup" my@email.org

HTH,
Nitin
# 5  
Old 07-30-2009
Didn't get an email with this command
Code:
date=`date -I` ;  uuencode backup_$date.tar.gz | mailx -s "Your Daily Site Backup" *******@gmail.com



---------- Post updated at 03:09 PM ---------- Previous update was at 01:59 PM ----------

I finally got it with mutt and then I used the RM command to remove the file. I tested it and it works. Now I need to try out the MySQL backup.
# 6  
Old 07-30-2009
Run the uuencode, see if you get any thing like this:

Code:
/usr/bin/uuencode
Try `uuencode --help' for more information.

Next try mailx the same way. You use 'mail' instead of mailx. I think. I'll have to test. If you get 'command not found' error, then either it's not installed or it's /usr/bin is not in your path. Do
Code:
echo $PATH

-Nitin
# 7  
Old 07-30-2009
It worked with mutt, and I was able to finish the job by using the rm command to remove the file once it was sent to me via email. Now, how do you do the MySQL backup?
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #719
Difficulty: Medium
Alan Minsky wrote the book Artificial Neural Networks, attacking the work of Frank Rosenblatt, which became the foundational work in the analysis of artificial intelligence applications in machine learning.
True or False?

9 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. UNIX for Dummies Questions & Answers

Emailing results of a pl sql procedure from UNIX shell script

Hello All, I am writing the below unix script to email the result of a small pl sql procedure: #!/bin/bash ORACLE_HOME=/opt/oracle/orcts/product/9.2.0; export ORACLE_HOME SQLPLUS=$ORACLE_HOME/bin/sqlplus sqlplus -s user/pass@Db_instance<<EOF set echo off set feedback off set pages 0... (9 Replies)
Discussion started by: Bunty bedi
9 Replies

3. Shell Programming and Scripting

Help on Backing up all the files in the subdirectories under a parent directory

Hi, I am not too familiar with Unix scripting but I have to write code to find all the files under all the sub directories under a parent directory of unix location and move them to the corresponding Windows location. For eg: I have \home\sreenu\Files\ Under neath this I have multiple sub... (3 Replies)
Discussion started by: raj.sreenu
3 Replies

4. Shell Programming and Scripting

Need help in backing up of databases.

Hi Everyone, I am new to DBA stuff. I wonder if anyone can help me. Task is that, I have 10 databases and need to take backups of all the databases using data pump in Unix/Linux, compress them using gzip and use cron to schedule the job twice a day. Appreciate if anyone can help me in... (1 Reply)
Discussion started by: sreepriya0987
1 Replies

5. Shell Programming and Scripting

Export SQL results to .TXT file for emailing

Hi everyone, I am new to unix and bash and in need of some help. I am writing a script that will execute a SQL query. The script runs and the SQl query runs, but I cannot figure out how to save the results as a file that can be emailed to a user. Here is my scripts thus far: #!/bin/sh SID=$1... (2 Replies)
Discussion started by: alpinescott
2 Replies

6. Solaris

Restricting SFTP user to a defined directory and home directory

Hi, I've created solaris user which has both FTP and SFTP Access. Using the "ftpaccess" configuration file options "guest-root" and "restricted-uid", i can restrict the user to a specific directory. But I'm unable to restrict the user when the user is logged in using SFTP. The aim is to... (1 Reply)
Discussion started by: sftpuser
1 Replies

7. UNIX for Dummies Questions & Answers

home directory

Hi what is the difference between the directory named /home and the user's home directory? can anyone plz reply? really confuse about it!!!!!!!! thank you (1 Reply)
Discussion started by: nokia3100
1 Replies

8. Solaris

Can usfdump be used for backing up 1 directory?

I know I can use ufsdump to backup a full device, but can I use it to just backup specified directories within the device? If so , how? (The man pages do not mention how to do that). If ufsdump can not do it, what are my choices? Thank you! (5 Replies)
Discussion started by: FredSmith
5 Replies

9. HP-UX

Accessing databases using sql*plus on HP box

When I try to connect to databse from HP box using the following command sqlplus <username>@<databasename> I get this error message: ksh: <database name> : not found I can connect to the database outside the UNIX box using sqlplus though. Looks like the problem is the way HP Unix is... (4 Replies)
Discussion started by: dtonse
4 Replies

Featured Tech Videos