Bash script to take cPanel backup in batches


Sep 30, 2017
cPanel Access Level
Reseller Owner

I'm trying to resolve the below scenario by writing bash script.

On my managed linux server I have about 30 accounts and there is not enough space to generate full 30 accounts backup in one go and transfer it via SFTP to my Backup Synology Server. What I'm thinking of doing is breaking the backup into batches and transfer it over accordingly to prevent server choking:

  1. Generate 5 accounts cPanel Backup
  2. Transfer the backup generated to Synology backup server via SFTP
  3. Delete the backups on source server.
  4. Repeat the process until all accounts are transferred in batches.
a. I have create 5 list of accounts into each array and named it cPList1 cPList2 ....and so on:
cPList1(account1 account2 account3)
cPList2(account4 account 5 account6)
b. Then I have created another array list that contains all cPLists
e.g. mainList(cPList1 cPList2)

The logic that I'm trying to use is:

#Outer Loop to process mainList array elements
for i in "${mainList[@]}"
#Inner Loop to to process cPList array elements
for j in "${i[@]}" **<<--I need help with this part, I was expecting the j variable to be accounts1, acocunts2 ...and so because it is supposed to be the elements of i variable. However, when I echo both i and j they hold same values i'e cPList1, cPList2 ....

SFTP 5 accounts backup to Synology
delete transferred files

Any input will be appreciated.


Staff member
Apr 11, 2011
Hello @beewee,

I've moved this thread to our Developers forum so it is more visible to our customers that develop scripts for cPanel & WHM.

While we don't offer direct support for custom coding, I did want to note that one alternative to how you are developing the script is to make use of the following WHM API 1 function:

WHM API 1 Functions - backup_skip_users_all - Developer Documentation - cPanel Documentation

This, combined with a forced backup generation (/usr/local/cpanel/bin/backup --force), would let you enable to enable backups for specific users prior to starting the backup generation.

Thank you.