October 25th, 2013, 11:38 PM
How to get mysql database backup with crontab in Ubuntu
I have been learning how to get back up from my databases. Just want to quickly check if I am doing everything right or not.
1 - Create a backup script:
Once in vim, write mysql dump script
root@behnam:/var/www/vhosts/website.com/scripts# vim database_back_up
Change the file permission to executable
mysqldump -u root -ppasssword_here "database_name_here" > /var/www/vhosts/website.com/database_backup/backup.sql
Create a folder that stores the backup file
root@behnam:/var/www/vhosts/website.com/scripts# chmod 755 database_back_up
Add the crontab script to system (What to call this??!!)
root@behnam:/var/www/vhosts/website.com# mkdir database_backup
Let it run every minute
This is working fine. Is there anything I need to improve or do any other ways? Thank you.
* * * * * /var/www/vhosts/website.com/scripts/database_back_up
Also what is the easiest way to send emails with Ubuntu. I saw several examples on line but none of them were successful. For example
root@behnam:/var/www/vhosts/website.com# mail email@example.com
This is the message
November 8th, 2013, 01:44 AM
November 8th, 2013, 05:00 AM
Could have sworn I'd replied to this!
My comments be along the line of not having the script or backup location within the directory structure of your web server. Also, do you really want the backup taken every minute?
The script itself is missing a leading / in the shebang line:
I'me a bit surpised that the mysqldump command is being found as scripts run from cron gat a very basic environment set up - including PATH.
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
November 16th, 2013, 08:32 PM
You can't just send email from Ubuntu without making it a mail server. I'm not allowed to post links yet, but you should search for postfix Ubuntu.