Where is Backup Users List Located?

Khalid Nihaya

Member
Jun 22, 2018
5
0
1
Pakistan
cPanel Access Level
Root Administrator
Hi CP Community,

I'm trying to locate the file that contains list of users that are eligible for scheduled backup, when an Admin enables backups & select a number of users for the backups from WHM.
Can someone tell me the path of that file?
Actually I want to create a script that would insert into that file, the users that fulfill my criteria of backup, & then the backup would run for those specific users.

In short, please help me locate the file that contains the list of users that backup command uses for backup.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello @Khalid Nihaya,

The backup selection value is stored in the individual cPanel user files in the /var/cpanel/users/ directory. Here's an example of a command you can use to see the status for all accounts:

Code:
grep BACKUP= /var/cpanel/users/*
The modifyacct WHM API 1 function is available if you'd like to enable or disable backups for a specific user:

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

For example, to disable backups for a user, you'd use a command like this:

Code:
whmapi1 modifyacct user=myuser BACKUP=0
Thank you.
 

Khalid Nihaya

Member
Jun 22, 2018
5
0
1
Pakistan
cPanel Access Level
Root Administrator
Ok I'm trying to use your suggested commands in a script. The logic goes like this,

1. Fetch All Accounts From /home
2. Fetch the accounts whose home dirs are less than 1 GB
3. Disable BackUP For "All Users" for start.
4. Enable BackUp For "Account with home data < 1GB... excluding suspended Accounts"
5. Generate BackUP


BUT I'm stuck at step 3 & 4. The reason is when I use following command twice, it either enables backup for all, or disable for all

whmapi1 modifyacct user=$i BACKUP=[0/1]
whereas
[0/1] symbolizes enabling or disabling.

Can you guys let me know what could be the reason?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
BUT I'm stuck at step 3 & 4. The reason is when I use following command twice, it either enables backup for all, or disable for all

whmapi1 modifyacct user=$i BACKUP=[0/1]
whereas
[0/1] symbolizes enabling or disabling.

Can you guys let me know what could be the reason?
Hello @Khalid Nihaya,

Can you provide a full example of the code you are using in your custom script so we can attempt to reproduce the same behavior?

Thank you.
 

Khalid Nihaya

Member
Jun 22, 2018
5
0
1
Pakistan
cPanel Access Level
Root Administrator
yes here's all the code, and description of what code should accomplish.


### BASH SCRIPT ###

#!/bin/bash



## Arrays ##

-- I defined these arrays to sort all hosting accounts into two arrayed lists.


-- Arrayed List 1: All accounts whose data has exceeded 1 GB data mark. Belows is command that does the trick

L=($( comm -23 <(du -h --max-depth=1 /home 2>/dev/null | grep G | awk -F"/" '{print $NF}' | sort | egrep -vw '(home|virtfs)') <(ls -al /var/cpanel/suspended/ | grep -v 'lock' | sort) ))



-- Arrayed List 2: All account whose data is less than 1 GB. Below command does the trick

S=($(comm -23 <(du -h --max-depth=1 /home 2>/dev/null | egrep -v '(!G|.cp|cP|clamav)' | awk -F"/" '{print $NF}' | sort | egrep -vw '(home|virtfs)') <(ls -al /var/cpanel/suspended/ | grep -v 'lock' | sort) ))


-- Now next step is to disable backup for all accounts to achieve zero state, so that I can set which accounts to backup next.

-- Disable > 1GB Accounts && Disable Accounts < 1GB

whmapi1 modifyacct user=${L[@]} BACKUP=0 && whmapi1 modifyacct user=${S[@]} BACKUP=0


-- Enable Backup For Small Accounts.


whmapi1 modifyacct user=${S[@]} BACKUP=1



-- Run Backup Command.

## /usr/local/cpanel/bin/backup --force ##





### Problem In Script ###

But when following command runs, it doesn't disable backup for all accounts. I don't know why.

whmapi1 modifyacct user=${L[@]} BACKUP=0 && whmapi1 modifyacct user=${S[@]} BACKUP=0

even if it may, when next command runs & enables backup, it doesn't anable backup for desired accounts.


You can check & troubleshoot according to my logic..
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello @Khalid Nihaya,

It looks like it's more of an issue with your specific coding, as it works successfully when manually entering the values in the WHM API 1 command. You may want to seek out feedback on a website related to programming (e.g. StackOverflow) or consult with a qualified system administrator for help with the programming itself:

System Administration Services | cPanel Forums

Thank you.
 

Khalid Nihaya

Member
Jun 22, 2018
5
0
1
Pakistan
cPanel Access Level
Root Administrator
Ok here's revised code for backup, goal is to backup small accounts (Less than 1G) first, then when it's all don, backup large accounts (bigger than 1G)


#!/bin/bash



## Variables & Arrays Defined ##

du_buff=$(du -h --max-depth=1 /home 2>/dev/null)
lock_buff=$(ls -al /var/cpanel/suspended/ | grep -v 'lock' | sort)
L=($(comm -23 <(echo "$du_buff" | grep G | awk -F"/" '{print $NF}' | sort | egrep -vw '(home|virtfs)') <(echo "$lock_buff") ))
S=($(comm -23 <(echo "$du_buff" | egrep -v '(G|.cp|cP|clamav)' | awk -F"/" '{print $NF}' | sort | egrep -vw '(home|virtfs)') <(echo "$lock_buff") ))


## Enable/Disable Backup Loops ##


# for every user in L and S
for user in "${L[@]}" "${S[@]}"; do
whmapi1 modifyacct user=$user BACKUP=0
done

# for every user in S
for user in "${S[@]}"; do
whmapi1 modifyacct user=$user BACKUP=1
done

/usr/local/cpanel/bin/backup --force ---->BACKUP1



# for every user in L and S
for user in "${L[@]}" "${S[@]}"; do
whmapi1 modifyacct user=$user BACKUP=0
done

# for every user in S
for user in "${L[@]}"; do
whmapi1 modifyacct user=$user BACKUP=1
done

/usr/local/cpanel/bin/backup --force ---->BACKUP2

--------------


SO BACKUP1 must finish before the 2 loops & BACKUP2 command. BUT it seems that it executes BACKUP1 in background and next instant the following loop starts running, which is not what is intended.
BACKUP1 is supposed to complete fully. I guess your backup commands are not sychronus for bash scripts. Please give me help of how it should be done..
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
Hello,

You may want to add a check for the second part of the script so that it does not start if the /usr/local/cpanel/bin/backup process is still running.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
by adding check you mean conditional if statement?
Hello,

Yes, and you could also set it up so that if the process is still running, it waits for a set amount of time and then tries again. Note that StackOverflow is generally a better website for the discussion of programming or code itself.

Thank you.