Skip to main content

Automatic cPanel backup with SQL dumps and without homedirs

Comments

5 comments

  • Jcats
    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. #!/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
    0
  • dandadude
    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
    0
  • cPanelMichael
    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:
    0
  • Jcats
    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!

    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.
    0
  • dandadude
    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
    0

Please sign in to leave a comment.