#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,670
    Rep Power
    171

    How to get mysql database backup with crontab in Ubuntu


    Hi;

    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:
    Code:
    root@behnam:/var/www/vhosts/website.com/scripts# vim database_back_up
    Once in vim, write mysql dump script
    Code:
    #!bin/bash
    mysqldump -u root -ppasssword_here  "database_name_here"  > /var/www/vhosts/website.com/database_backup/backup.sql
    Change the file permission to executable
    Code:
    root@behnam:/var/www/vhosts/website.com/scripts# chmod 755 database_back_up
    Create a folder that stores the backup file
    Code:
    root@behnam:/var/www/vhosts/website.com# mkdir database_backup
    Add the crontab script to system (What to call this??!!)
    Code:
    crontab -e
    Let it run every minute
    Code:
      * * * * * /var/www/vhosts/website.com/scripts/database_back_up
    This is working fine. Is there anything I need to improve or do any other ways? Thank you.



    ---------
    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
    Code:
    root@behnam:/var/www/vhosts/website.com# mail it@yahoo.com
    Cc: itw@yahoo.com.au
    Subject: hi
    This is the message
    cannot send message: Process exited with a non-zero status
  2. #2
  3. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,670
    Rep Power
    171
    Anyone?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,450
    Rep Power
    1751
    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:
    #!bin/bash
    should be
    #!/bin/bash

    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    58
    Rep Power
    1
    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.

IMN logo majestic logo threadwatch logo seochat tools logo