How To Backup All cPanel Accounts via SSH
Posted by Pete | Posted in SSH/Bash | Posted on 12-08-2009-05-2008
0
In this tutorial I will show you how to use the script pkacct to backup all cPanel accounts using a loop and then put the backups onto a remote server using RSync.
So first lets create the directory in which the backups will be stored.
Step 1
mkdir /manualbackups;
That will create a folder called manualbackups in /
Step 2
Now we have to setup the RSync.
ssh-keygen -t rsa -N '';
scp ~/.ssh/id_rsa.pub USERNAME@HOSTNAME:;
ssh USERNAME@HOSTNAME mergekeys
This will create a key which will allow the server to auto login. Simple replace USERNAME and HOSTNAME with the username and hostname of the remote server.
Step 3
Now to actually make it create the account backups and move them run the following.
nano manualbackups.sh
and paste the following code into it by right clicking.
#!/bin/sh
cd /var/cpanel/users
for CUSTOMER in `ls -1A --color=no`
do
/scripts/pkgacct $CUSTOMER /manualbackups/
done;
rsync -avz -e ssh /manualbackups/ USERNAME@HOSTNAME:DIRECTORY
Replace USERNAME and HOSTNAME with the remote server username and hostname and replace DIRECTORY with the directory which the backups will be stored on the remote server e.g backups/
Now press Ctrl + X then Y and now press enter.
Thats the script done but we need to be able to run it so we need to set the permissions of the file using.
chmod u+x manualbackups.sh
And we are complete. If you want to run it all you have to do is type ./manualbackups.sh
So thats it. If you want any futher help or like this tutorial please leave a comment.
EDIT: All commands are run on the local server. So the server that has the cPanel accounts on.


