Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Bash script to take cPanel backup in batches

Discussion in 'cPanel Developers' started by beewee, May 23, 2018.

  1. beewee

    beewee Registered

    Sep 30, 2017
    Likes Received:
    Trophy Points:
    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.
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Apr 11, 2011
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    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.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice