Thanks masterbator, something simple twice better

It can be improved backuping files too.

---------- Post added at 07:30 PM ---------- Previous post was at 04:31 PM ----------

Well... i modified the code provided by masterbator to adjust to my needs and correct some issues on my CentOS 5 x64 machine, fixes:

- Tar shows a warning for use absolute paths (the files are compressed Ok anyway, but i not love see warning messages so i decied to fix them).

- Changed ".tgz" extension of compressed files to ".tar.gz", both are equivalent, correct and working extensions but i always used ".tar.gz" and not give problems unless you go to a very very very old OS that not allows more than one point and more than three letters into a extension (MS-DOS for example).

- Changed "-" with "_", since can cause issues have "-" char into filenames.

- Ftp client on my CentOS 5 x64 (using same code as masterbator) result in upload files corrupted to my remote server, then i changed ftp to ncftp (installed by default on my CentOS 5 x64). I?m using into remote server vsftpd as ftp server/daemon.

- I use /tmp folder as temporary folder to create backups and delete them, seems a safer location to play with command "rm -rf".

- Line "rm -rf /your/path/*" is a little hardcore for me, i used prefix namefile, wildcard "*" and file extension, less hardcore.

- Added support to backup files of my public_html folder.

- Added support to upload the compressed and uncompressed database backup (i?m paranoic, but with a safe backup in my hands ).

The code (remember to edit script with your paths and user/pass, the blue text):

Code: 
#!/bin/bash
### Dump mysql database and compress it ###
echo Starting Database Backup
mysqldump -uYour_db_User -pYour_db_password -hlocalhost Your_db > /tmp/sql_backup_`date +%d%m%y`.sql
cd /tmp
tar -zcf sql_zipped_backup_`date +%d%m%y`.tar.gz sql_backup_*.sql
echo Database Backup Completed

### Compress files ###
echo Starting Files Backup
cd /
tar -zcf /tmp/filesbackup_`date +%d%m%y`.tar.gz home/www/web.com/public_html
echo Files Backup Completed

### Upload to remote ftp ###
cd /tmp
HOST='100.200.200.105'
USER='ftp_user'
PASSWD='ftp_pass'
ncftp -u"$USER" -p"$PASSWD" $HOST<<EOF
put sql_zipped_backup_*.tar.gz
put filesbackup_*.tar.gz
put sql_backup_*.sql
quit
EOF

### Delete backups ###
echo Start Cleaning Backup Files
cd /tmp
rm -rf sql_zipped_backup_*.tar.gz
rm -rf sql_backup_*.sql
rm -rf filesbackup_*.tar.gz
echo Cleaning Backup Files Completed

exit 0
Enjoy.