cPanel Script to Dump Data and RYSNC



cPanel Script to Migrate Data In One Shot

cPanel Script to Migrate Data In One Shot

What Does This Script Do :

"cPanel Migration Script" This script is used to take the Input when you Initiate the Script and Prompts for the Directory to provide and to store the cPanel backup files under the same. Once the backup for the accounts has been done which are mentioned in the file name which is "/root/rohit/24.txt".This File contains the Usernames (cPanel accounts) which needs to be moved from the Source Server to the Target Server.



Once the Backup is done then it uses the command known as "sshpass" to rsync the data from the source server to the target server. In "sshpass" we need to provide the destination server password as an argument to that command, so that it will simultaneously move the accounts without asking for the Password.

Note : SSHPASS can be downloaded from the below mentioned link which is -

http://www.nextstep4it.com/categories/unix-command/sshpass/

However, More Information regarding the Working of the Script is mentioned below -


========================================================================

#Starting of the Script

#!/bin/bash

set -x
AUTHOR="ROHIT PATEL"
FILE=/root/rohit/24.txt
MAIL="rp@rohitpatel.in"
SUBJECT="Migration Status"
Success="Migration Is Success."
Failed="Migration Failed."
Target_IP="75.114.50.34"
Source_IP="89.114.50.15"
NOW=$(date +"%d-%m-%Y")
Time=$(date)

read -p "Enter the Directory Name To Create and Store Backup Files Under It - " BAK

if [ ! -d $BAK ] &&  mkdir -p $BAK
then
echo "Backup Directory Created, which Is "$BAK"."
else
echo "Please Provide Directory Name To Generate Backup To :: $BAK"
exit 1;
fi

ans=$?

if [ $ans !=  0 ]
then
echo "Backup Failed To Start."
else
for i in `cat $FILE`; do sudo /scripts/pkgacct $i $BAK; done
fi

rstat=$?
if [ $rstat -eq 0 ]
then
echo "Backup done for the accounts mentioned in $FILE and the backup files are present under the $Source_IP:$BAK Folder."
else
echo "Backup Failed For the Accounts."
fi

retval=$?
if [ $retval == 0 ]
then
echo "Started with the RSYNC of the data from Source Server : $Source_IP to the Target Server :  $Target_IP `sshpass -p "qwedsa@123" rsync -avHe ssh --progress $BAK root@115.114.50.154:/root/rohit/`"
fi

rp=$?
if test $rp == 0
then
echo $Success On :: Date = $NOW and Time is = $Time | mail -s "$SUBJECT" "$MAIL" && echo "Mail Sent Successfully On :: $NOW and $Time."
else
echo $Failed On :: Date = $NOW and Time is = $Time | mail -s "$SUBJECT" "$MAIL" && echo "Mail Sending Failed On :: $NOW and $Time."
fi

echo -e "\n ..This Script Was Made By "Rohit Patel".. \n"


#END of The Script
========================================================================

NOTE : The above Shell Script will do the following things step wise step -

1, Ask for the Directory to dump the cPanel backup file to the same and if it doesn't exists it will create the same. (Ex. : /rohit/).

Note: This will not work if no Argument is provided is the form of Directory Address when it Prompts for the same and also provide such Directory which doesn't exists and then it will create the same and will proceed further else it will not and exit.

2, Then Takes the input from the File name which is "FILE=/root/rohit/24.txt", this file contains the cPanel Usernames to be dumped.

3, Once the backup for the mentioned accounts done then it will start with the RSYNC process from the Source Server to the Target Server.

4, Once RSYNC is done for the Accounts, then it will send a mail to the concerned Administrator regarding the Migration Status (One needs to edit as per there usage the mail id, source server and target server IP, File Path), whether the Migration was Success or Failure along with the Date and Time on which the Migration was Done.



                               "KEEP CALM AND STAY AWAKE"
  


FEED


Share








SUPPORT


View Rohit Patel's profile on LinkedIn









VISIT COUNTER !!



One Response so far.