📘Create Backup of Reseller Account via SSH

This guide explains how to back up all cPanel accounts under a specific Reseller using SSH on a cPanel server. It includes options for customizing backup destinations and preventing backup overwrite.


1. Basic One-Liner to Backup All Accounts Under a Reseller

Run the following command, replacing RESELLERUSERNAME with your reseller’s actual username and /backup with your desired backup directory:

for i in $(whmapi1 listaccts searchtype=owner search=RESELLERUSERNAME want=user | grep user: | awk '{print $2}') ; do /scripts/pkgacct $i /backup ; done

2. Create a Date-Named Folder for Backups (Recommended)

To avoid overwriting previous backups, use a dated folder:

currdate=$(date +%Y-%m-%d)
mkdir -p /backup/"$currdate"
for i in $(whmapi1 listaccts searchtype=owner search=RESELLERUSERNAME want=user | grep user: | awk '{print $2}') ; do /scripts/pkgacct $i /backup/"$currdate" ; done
  • Replace /backup/ with your desired backup path.
  • This creates a backup directory like: /backup/2025-07-09/

3. Change Backup Directory

If you want to back up to a custom path, change /backup/ to something like:

/backup/reseller_backups/

Or use:

/home/username/backups/

Make sure the path exists and has enough disk space.


4. Correct Permissions After Backup (Optional)

If needed, fix ownership and permissions of the backup directory (especially if you are restoring or moving data):

chown -R username:username /home/username/customers/dedicated/server.domain.com
chmod -R 644 /home/username/customers/dedicated/server.domain.com

Replace:

  • username:username with the correct user and group
  • Path /home/username/customers/dedicated/server.domain.com with your actual backup or data path

Tips

  • Run as root over SSH.
  • Monitor disk space with df -h before starting large backups.
  • Consider automating with cron for regular backups.

Here is an enhanced version of the guide with email notifications and optional rsync to a remote server after backup:


Create Backup of Reseller Account via SSH (with Email Notification + Remote Sync)


1. Create the Script

Create a script file:

nano /root/reseller_backup.sh

Paste the following:

#!/bin/bash

# Configurable Variables
RESELLER="RESELLERUSERNAME"
BACKUPDIR="/backup"
EMAIL="[email protected]"
REMOTEUSER="root"
REMOTEHOST="remote.server.com"
REMOTEPORT="22"
REMOTEPATH="/remote/backup/path"
USE_RSYNC_REMOTE=true

# Create dated folder
currdate=$(date +%Y-%m-%d)
mkdir -p "$BACKUPDIR/$currdate"

# Backup each account
for i in $(whmapi1 listaccts searchtype=owner search=$RESELLER want=user | grep user: | awk '{print $2}'); do
    /scripts/pkgacct $i "$BACKUPDIR/$currdate"
done

# Send email notification
mail -s "Reseller Backup Completed: $RESELLER ($currdate)" $EMAIL <<EOF
Backup for all accounts under $RESELLER completed on $currdate.
Stored in: $BACKUPDIR/$currdate

Total backups: $(ls "$BACKUPDIR/$currdate" | wc -l)

Regards,
cPanel Backup Script
EOF

# Optionally sync to remote server
if [ "$USE_RSYNC_REMOTE" = true ]; then
    rsync -avz -e "ssh -p $REMOTEPORT" "$BACKUPDIR/$currdate/" "$REMOTEUSER@$REMOTEHOST:$REMOTEPATH/$currdate/"
fi

Make it executable:

chmod +x /root/reseller_backup.sh

2. Update the Following Values in the Script

  • RESELLER="RESELLERUSERNAME" → replace with your reseller username
  • EMAIL="[email protected]" → to get notified after completion
  • Remote sync settings:
    • REMOTEUSER, REMOTEHOST, REMOTEPATH, REMOTEPORT

3. Schedule it via Cron (Optional)

Edit root’s crontab:

crontab -e

Add this to run every day at 2 AM:

0 2 * * * /root/reseller_backup.sh

Requirements

  • Ensure mailx or mail is installed for email: yum install mailx -y
  • Ensure SSH key or passwordless access is set up for remote rsync (or modify rsync to use sshpass if necessary).
Scroll to Top