Performing incremental backups for reseller accounts ensures data security and efficient storage management. Follow the steps below to automate the backup process.
Step 1: Identify Usernames Under Reseller Account (On Shared/Source Server)
1️⃣ Create a backup script:
vi /home/resellerUsername/backup.sh
2️⃣ Add the following command to extract usernames under the reseller account:
cat /etc/trueuserowners | grep resellerUsername | awk -F: ‘{print $1}’ > /home/resellerUsername/resellerUsername.txt
3️⃣ Save the file and set executable permissions:
chmod 755 /home/resellerUsername/backup.sh
4️⃣ Schedule a daily cron job in cPanel of the reseller account:
0 0 * * * sh /home/resellerUsername/backup.sh
Step 2: Configure Backup Server
1️⃣ Create a backup script:
vi /home/backupUsername/backup.sh
2️⃣ Add the following rsync commands to fetch data from the source server:
✔ Sync Reseller Account List
/usr/bin/rsync -vrplogDtH -e “ssh -p SSH-PORT” root@Source_Server_Hostname:/home/resellerUsername/resellerUsername.txt /home/backupUsername/
✔ Sync User Data
for i in cat /home/backupUsername/resellerUsername.txt; do
/usr/bin/rsync -vrplogDtH -e “ssh -p SSH-PORT” root@Source_Server_Hostname:/home/$i /home/backupUsername/weekly-data;
done
✔ Sync MySQL Databases
for i in cat /home/backupUsername/resellerUsername.txt; do
/usr/bin/rsync -vrplogDtH -e “ssh -p SSH-PORT” root@Source_Server_Hostname:/var/lib/mysql/$i* /home/backupUsername/weekly-mysql/;
done
✔ Update File Ownership for FTP Access
chown backupUsername:backupUsername /home/backupUsername/weekly-data/ -R
chown backupUsername:backupUsername /home/backupUsername/weekly-mysql/ -R
Step 3: Schedule Automatic Backup on Backup Server
1️⃣ Save the file and set executable permissions:
chmod 755 /home/backupUsername/backup.sh
2️⃣ Add a cron job to execute the backup script daily:
vi /var/spool/cron/root
3️⃣ Add the following line to schedule the script to run at midnight daily:
0 0 * * * /bin/bash /home/backupUsername/backup.sh