SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot headsnet's Avatar
    Join Date
    Feb 2001
    Location
    London, UK
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to configure a UNIX/LINUX server to do a MySQL Dump for a database on an automatic schedule and then to email the dump file to me (the administrator)??

    I want to be able to have my database automatically backed up every week and emailed to me for storage purposes without any action on my part.

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is - but you'll have to write a script to do it. I'm pretty new to linux but I'm sure you could do it if you wrote a shell script to call mySQL, dump the tables, then zip them all up into a tarball. The shell script could then call a mail program and mail the tarball to you.

    Stick a call to the shell script in CRON (which allows you to set automated tasks for the system to carry out ever specified interval) and you're sorted.

    Unfortunately shell scripting is a bizzare black art which seems to be handed down from unix hacker to unix hacker by word of mouth. There's probably some good tutorials / FAQs around though.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the shell script part the mail part isn't quite working but I will try and figure it out. It may not be the best way to do it and I am no expert in shell scripting so this is the best I could do and it works. I will work on the mail part.

    #!/bin/bash

    #Set this to be the path of the tmp dir we will use
    TMP=/home/mysqlbk/tmp


    #Get todays date
    right_now=$(date +'%Y%m%d')


    mysqldump -u root dbname > $TMP/$right_now.sql

    #Change dir to tmp folder
    cd $TMP

    #Archive the stuff
    tar -cf $TMP/$right_now.tar $right_now.sql

    #Compress the archive
    gzip $right_now.tar

    #Set permissions
    chmod 700 $right_now.tar.gz

    #mail it
    mail you@yourdomain.com < $right_now.tar.gz

    #Remove the .sql file
    rm -r -f $right_now.sql
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aargh! Shell Scripter!

    Your cat has many talents

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The mail line should look like this in order to send the file as an attachment

    uuencode $right_now.tar.gz $right_now.tar.gz | mail you@yourdomain.com
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turns out my boss expects me to know it, so I have been writi8ng a few and this happened to be one of them
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •