Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Automatic cPanel backup with SQL dumps and without homedirs

Discussion in 'Data Protection' started by dandadude, Apr 2, 2018.

Tags:
  1. dandadude

    dandadude Active Member

    Joined:
    Apr 14, 2011
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    56
    Hi!

    I have a problem that probably many of you face.

    I want to use the automatic backup feature of cPanel, but my users have lots of data that are being backed up by virtual image backup software anyway from which I can make file based restores (so it makes no sense to create another backup of all that data...).
    So actualy I don't need their homedir contents, but I would very much need their MySQL and PostgreSQL dump files, because that's something that is worth creating, since backing up the dir-files is not the same.

    I know that pkgacct has the --skiphomedir option, but I do not plane to create my own little script that either works or not in the future. I would like to stick with cPanel's builting method, but surely there must be a good solution for the same future as "--skiphomedir".

    I also do not like the idea of creating my own SQL dumps for this purpose, because I have already done this in the past, and it is not as reliable as cPanel's solution. Also cPanel notifies me of errors through e-mail etc.

    Oh yeah, I found a method, I put "*" in /etc/cpbackup-exclude.conf, but the problem is that when I do this, the users loose their ability to create full backups from their control panel, because their homedir will be skipped at that point too, causing them to have a false secure feeling...

    Is there a built-in solution for this? Or what would you recommend?

    Thanks,
    Daniel
     
  2. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    700
    Likes Received:
    112
    Trophy Points:
    168
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    Daniel,

    If you don't want to do your own script, then I'd say look at Jetbackups, this has a lot of added functionality that will do what you want, otherwise I created a script similar for r1soft backups a while back, it might not be super pretty but it works, it will alert you if the number of backups taken do not match the number of cPanel accounts.

    Code:
    #!/bin/bash
    
    # Justin - BigScoots
    # Used for r1soft servers
    # Creates a cPanel backup minus the home directory
    # Requires mutt ( yum -y install mutt )
    
    cpusercount=$(whmapi1 listaccts |grep user: |awk '{print $2}'|wc -l)
    bkdir=/backup/r1soft
    
    mkdir -p "$bkdir"
    rm -f "$bkdir"/*.tar.gz
    echo > "$bkdir"/backup.txt
    
    for user in $(whmapi1 listaccts |grep user: |awk '{print $2}')
    do
        nice -n 19 ionice -c3 /scripts/pkgacct --skiphomedir "$user" "$bkdir" >> "$bkdir"/backup.txt
        cpbkcomplete=$(grep -c "pkgacct completed" "$bkdir"/backup.txt)
    done
    
    if [ "$cpusercount" == "$cpbkcomplete" ]
    then
            echo "This backup completed successfully" | mutt -a "$bkdir/backup.txt" -s "$HOSTNAME Backup successful:  $cpbkcomplete accounts backed up out of  $cpusercount accounts." -- your@email.com
    else
            echo "This backups failed, please check attached txt." | mutt -a "$bkdir/backup.txt" -s "$HOSTNAME Backup failed:  $cpbkcomplete accounts backed up out of  $cpusercount accounts." -- your@email.com
    fi
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. dandadude

    dandadude Active Member

    Joined:
    Apr 14, 2011
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    56
    Hi Jcats!

    Thanks for the tip about Jetbackup and absolutely thanks for sharing your great script!

    I guess your answer also tells me that I should not be searching for a built-in solution from cPanel for this task :) Maybe I can put it in a feature request, because it is really something others would also use...

    Your script seems very nice. The only thing that I am thinking of is wether "This backup completed successfully" string is written also when there are minor warnings or errors or this only happens if it is 100% warning and error free? I recall getting sometimes backup reports containing some minor problems, but I don't know if this string makes me damn sure that everything went OK!

    Thank you very much!

    Regards,
    Daniel
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,660
    Likes Received:
    1,787
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hi Daniel,

    The backup exclusion feature is currently the best approach if you want to use native cPanel & WHM functionality:

    How to Exclude Files From Backups - cPanel Knowledge Base - cPanel Documentation

    However, as you mentioned, this also applies to the Download a Full Website Backup feature in cPanel >> Home >> Files >> Backup. I recommend creating a feature request for the ability to exclude files globally for WHM backups without excluding them for backups generated through cPanel:

    Submit A Feature Request

    Note that our feature request website is currently undergoing maintenance.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    700
    Likes Received:
    112
    Trophy Points:
    168
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    No it definitely will not let you know if there were any errors, it will only alert if the number of backups taken do not match the total number of cPanel accounts on the server. Its in no way a smart script at all, you could add some error detection in there by grepping for keywords/strings though.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. dandadude

    dandadude Active Member

    Joined:
    Apr 14, 2011
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    56
    Hi Michael, Justin!

    Thanks for the replys!

    I guess that I will need to make a feature request when the site goes online again.
    This is really something that should be needed by others too, because the image-based backups are more then usual now and everything can be restored easily from that except the database-backups (at least it leaves you with much less options and more headaches in certain situations, using dumps is much better in my opinion).

    Until then, I might use Justin's script (thanks very much), but because there is no exact specification for error handling (I have to experiment with it for months) probably I will be better off disabling backup manager for the users to not mislead them and use "*" in /etc/cpbackup-exclude.conf . Of course that is not a good solution either...
    Or maybe Jetbackup... :)

    Ah well, let's hope cPanel puts --skiphomedir option in the next release :)

    Thank you,
    Daniel
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice