WordPress Developer & Linux Administrator

cPanel shell script to pkgacct each user on a server

This script creates an extra backup of users on server with cPanel’s built-in packaging system. These are restorable backups which are basically a snapshot of any given cPanel account. When you restore, they will be perfect copies of the account as it was at the time of backup.

Due to limited space issues we all face at one time or another, this script will rsync each cPanel account backup to a remote server after creation, then removed.

#!/bin/bash
#
#  Date: Aug 7th 2014
#  Author: Will Ashworth (williamashworth.com || linuxscripts.org)
#
#  cPanel bash script to 'pkgacct' each user on a server
#
#  Copyright (C) 2015 Will Ashworth
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details. http://www.gnu.org/licenses/

IFS="$"
EMAILADDRESS="someone@emailaddress"
EMAILMESSAGE="emailmessage.txt"

/bin/mail -s "Server backup started" "$EMAILADDRESS" < $EMAILMESSAGE

cd /var/cpanel/users

find * | while read CPUSER; do
    echo "Now processing ${CPUSER} ..."
    /scripts/pkgacct ${CPUSER}
    rsync --remove-sent-files /home/*.tar.gz root@remoteserver.com:/home/backups/      
done

/bin/mail -s "Server backup finished" "$EMAILADDRESS" < $EMAILMESSAGE
Categories: Bash, cPanelTags: , , ,

Comments

Your email address will not be published. Required fields are marked *