The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Automating Full backups

Discussion in 'General Discussion' started by freeranger, Sep 3, 2003.

  1. freeranger

    freeranger Member

    Joined:
    Aug 11, 2003
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    The full backup in Cpanel seems to back up the databases and website, which is great. Is there any way to automate this, via a cron job?
    I want to be able to back up my client's sites with minimal effort.

    thanks.

    cPanel.net Support Ticket Number:
     
  2. ciphervendor

    ciphervendor Well-Known Member

    Joined:
    Aug 26, 2002
    Messages:
    1,052
    Likes Received:
    0
    Trophy Points:
    36
    Setup the cpanel backup option in WHM.

    cPanel.net Support Ticket Number:
     
  3. freeranger

    freeranger Member

    Joined:
    Aug 11, 2003
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I don't seem to have such an option - maybe it's not available to resellers?

    thanks.

    cPanel.net Support Ticket Number:
     
  4. ciphervendor

    ciphervendor Well-Known Member

    Joined:
    Aug 26, 2002
    Messages:
    1,052
    Likes Received:
    0
    Trophy Points:
    36
    aahh sorry I interpreted cpanel backups as in system backups...not individual client backups.

    You can do this fairly easily with a bash script being called via cron. Here's something that should work for you. Create a directory called backup in the root of your clients home directory, then create a file named backup.sh with the following contents:
    Code:
    #!/bin/sh
    
    username=USERNAME
    date=`/bin/date +%m-%d-%Y`
    
    mysqldump -u$username_DATABASE-USERNAME  -pDATABASE-PASSWORD $username_DATABASE-NAME > /home/$username/backup/$username_DATABASE-NAME-$date.sql
    tar -zcPf /home/$username/backup/$username_DATABASE-NAME-db-$date.tar.gz /home/$username/backup/$username_DATABASE-NAME-$date.sql
    rm -f /home/$username/backup/$username_DATABASE-NAME-$date.sql
    
    rm -f /home/$username/backup/backup-*.tar.gz
    tar -zcPf /tmp/$username-backup-$date.tar.gz /home/$username
    rm -f /home/$username/backup/$username_*-$date.tar.gz
    mv /tmp/$username-backup-$date.tar.gz /home/$username/backup/backup-$date.tar.gz
    Be sure to replace everything in UPPERCASE. You can copy & paste the first few lines if your client has more than one database to backup. You should then cron the above script with something like:
    Code:
    0 4 * * * /bin/sh /home/USERNAME/backup/backup.sh > /dev/null
    Edit: A small note, make sure that the backup.sh script has permissions of 700.
     
    #4 ciphervendor, Sep 3, 2003
    Last edited: Sep 3, 2003
  5. freeranger

    freeranger Member

    Joined:
    Aug 11, 2003
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1


    Actually, what I _really_ want to be able to do is for _me_ to be able to back up _all_ my client websites & databases, but as I am on a shared box, I don't see that as being possible :(

    That's great man, thanks a lot.
    I am a windoze man, not a *nix one, so this shell scripting is all new to me.
    Can you recommend a good book on the subject?

    Also, can I be really cheeky and ask how I would go about deleting backups over a certain age (eg more tha 2 days old) to stop filling up the user's web space - or even how to ftp the backup out to another box & delete it afterwards?

    many thanks for your help

    cPanel.net Support Ticket Number:
     
  6. ciphervendor

    ciphervendor Well-Known Member

    Joined:
    Aug 26, 2002
    Messages:
    1,052
    Likes Received:
    0
    Trophy Points:
    36
    You could ask your host to add you to either the user or group permissions of each of your clients; you can then use a bash script to backup all of your users' data into your home directory. Alternatively, you can ask your host to script something for you and have them execute the backup as root so you don't have to deal with UID/GID issues. Another way to do it is to get your own box. They've become so incredibly cheap, it would be almost worth it to get one if you have more than 25 paying hosting customers.

    As for shell scripting, you can learn a lot from "Sams Teach Yourself Shell Programming in 24 Hours" 24 hours of course is not going to happen, but this book is a good base and you can probably find it for download on the net somewhere.

    http://www.google.com/search?source...+Teach+Yourself+Shell+Programming+in+24+Hours

    7th link down.

    The script I hacked together and pasted in my other post removes the previous day's backups before completing a new backup.

    cPanel.net Support Ticket Number:
     
  7. freeranger

    freeranger Member

    Joined:
    Aug 11, 2003
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the info cipher, I'll check out that book.

    Ummmm......what other post r u referring to?

    cheers.

    cPanel.net Support Ticket Number:
     
  8. ciphervendor

    ciphervendor Well-Known Member

    Joined:
    Aug 26, 2002
    Messages:
    1,052
    Likes Received:
    0
    Trophy Points:
    36
    Look up 4 or so posts. I was referring to the script I initially created and pasted into this thread.

    cPanel.net Support Ticket Number:
     
  9. freeranger

    freeranger Member

    Joined:
    Aug 11, 2003
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Ahhhhh.... I saw the script alright, but didn't spot the bit that removed the previous day's backup - I was looking in the database dump bit, but not the home directory dump bit....

    cheers d00d, that's been a _great_ help

    cPanel.net Support Ticket Number:
     
Loading...

Share This Page