Hi,
We think that there may have been some changes made to the cPanel API that are causing this problem.
Our code's objective is to collect the latest backup of the database, download it, and import it. We are unsure of the changes required in the section of the code that pertains to the cPanel API to accomplish this objective.
Therefore, we kindly request your assistance in identifying the necessary changes to our code to resolve this issue. Any guidance or support you can provide would be much appreciated.
This is the bash code (the token has been edited for security reasons):
And this is the console output:
If we replace this line:
with this other one:
this is the console output:
Any ideas?
Thanks a lot!
We think that there may have been some changes made to the cPanel API that are causing this problem.
Our code's objective is to collect the latest backup of the database, download it, and import it. We are unsure of the changes required in the section of the code that pertains to the cPanel API to accomplish this objective.
Therefore, we kindly request your assistance in identifying the necessary changes to our code to resolve this issue. Any guidance or support you can provide would be much appreciated.
This is the bash code (the token has been edited for security reasons):
Code:
!/bin/bash
## Description: Import a fresh database from cPanel.
## Usage: pulldbdos es|mx|it|br
## Example: "ddev pulldbdos es"
## Go to https://url.es:2083/cpsess1481796690/frontend/paper_lantern/telnet/keys/index.html
## and add you SSH key.
## Go to https://url.es:2083/cpsess1481796690/frontend/paper_lantern/api_tokens/index.html
## and add a new token and copy it to "token_es" variable.
# Configurable variables by country:
token_es="asdfasdfasdfasdfasdfasdf"
# Static variables by country:
path_es=https://url.es:2083/cpsess1481796690
user_es="esamaraepro"
declare -A countries
countries[es]="Spain"
if [[ -v "countries[${1}]" ]]; then
# Build country variables.
path="path_${1}"
username="user_${1}"
apitoken="token_${1}"
# test connection and authorization
response=$(curl -o /dev/null -w "%{http_code}" -H "Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/listBackups?type=4&only_snapshots=1")
if [ $response -eq 200 ]; then
echo "Connection and authorization successful"
else
echo "Connection or authorization failed"
fi
# Get latest backup ID.
current_id=$(curl -H"Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/listBackups?type=4&only_snapshots=1" | jq -r ".data.backups[0]._id")
if [ -z "$current_id" ]; then
printf "There is not any available backup for country: '${1}'!\n"
exit 1
fi
printf "Getting download path for backup ID: #${current_id}...\n"
# Check if the download is ready or queue new one.
download_path=$(curl -H"Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/listDownloads" | jq -r '.data.downloads[] | select(.item_id=="'"${current_id}"'") | .path')
if [ -z "$download_path" ]; then
status=$(curl -H"Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/addQueueDownload?_id=${current_id}" | jq -r '.data.added')
if [ "$status" != "1" ]; then
printf "Unable to queue download backup (${current_id}) for country: '${1}'!\n"
exit 1
fi
printf "Queued download path for backup ID: #${current_id}...\n"
fi
# Wait for download path.
while [ -z "$download_path" ]
do
download_path=$(curl -H"Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/listDownloads" | jq -r '.data.downloads[] | select(.item_id=="'"${current_id}"'") | .path')
printf "Waiting for download path for backup ID: #${current_id}...\n"
sleep 15
done
printf "\n\n\033[0;31mIf you are prompted for the user password, interrupt the process and make sure to run 'ddev auth ssh'.\033[0m\n\n"
echo 'LANG="es_ES.utf8"' >> ~/.profile && source ~/.profile
rm -rf /var/www/html/.ddev/import-db/${1}.tar.gz
mkdir -p /var/www/html/.ddev/import-db
printf "Downloading backup: ${download_path}...\n"
scp ${!username}@url.${1}:${download_path} /var/www/html/.ddev/import-db/${1}.tar.gz
printf "Importing backup: /var/www/html/.ddev/import-db/${1}.tar.gz...\n"
mysql -uroot -proot -hdb -e "DROP DATABASE IF EXISTS db_${1};"
mysql -uroot -proot -hdb -e "CREATE DATABASE IF NOT EXISTS db_${1};"
mysql -uroot -proot -hdb -e "GRANT ALL ON db_${1}.* to 'db'@'%' IDENTIFIED BY 'db';"
pv /var/www/html/.ddev/import-db/${1}.tar.gz | tar -zxO | mysql -uroot -proot db_${1}
drush @${1} cr
drush @${1} updb -y
drush @${1} uli
else
printf "Unknown country: '${1}'!\n"
fi
Code:
ddev pulldbdos es
Connection and authorization successful
Getting download path for backup ID: #null...
jq: error (at <stdin>:1): Cannot iterate over null (null)
Unable to queue download backup (null) for country: 'es'!
Failed to run pulldbdos es: exit status 1
Code:
current_id=$(curl -H"Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/listBackups?type=4&only_snapshots=1" | jq -r ".data.backups[0]._id")
Code:
current_id=$(curl -H"Authorization: cpanel ${!username}:${!apitoken}" -s "${!path}/execute/JetBackup/listBackups?type=4&only_snapshots=1" | jq -C)
Code:
ddev pulldbdos es
Connection and authorization successful
Getting download path for backup ID: #{
"warnings": null,
"data": null,
"errors": [
"Failed to load module “JetBackup”: El sistema no pudo cargar el módulo “Cpanel::API::JetBackup” debido a un error: Can't locate Cpanel/API/JetBackup.pm in @INC (you may need to install the Cpanel::API::JetBackup module) (@INC contains: /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/536/cpanel-lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/cpanel-lib /usr/local/cpanel/3rdparty/perl/536/lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/lib /opt/cpanel/perl5/536/site_lib/x86_64-linux /opt/cpanel/perl5/536/site_lib) at (eval 4) line 1.
BEGIN failed--compilation aborted at (eval 4) line 1.
The system failed to load the module “Cpanel::API::JetBackup” because of an error: Can't locate Cpanel/API/JetBackup.pm in @INC (you may need to install the Cpanel::API::JetBackup module) (@INC contains: /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/536/cpanel-lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/cpanel-lib /usr/local/cpanel/3rdparty/perl/536/lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/lib /opt/cpanel/perl5/536/site_lib/x86_64-linux /opt/cpanel/perl5/536/site_lib) at (eval 4) line 1.
BEGIN failed--compilation aborted at (eval 4) line 1.
"
],
"metadata": {},
"status": 0,
"messages": null
}...
jq: error: syntax error, unexpected IDENT, expecting ';' or ')' (Unix shell quoting issues?) at <top-level>, line 2:
"warnings": null,
jq: 1 compile error
(23) Failed writing body
Unable to queue download backup ({
"warnings": null,
"data": null,
"errors": [
"Failed to load module “JetBackup”: El sistema no pudo cargar el módulo “Cpanel::API::JetBackup” debido a un error: Can't locate Cpanel/API/JetBackup.pm in @INC (you may need to install the Cpanel::API::JetBackup module) (@INC contains: /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/536/cpanel-lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/cpanel-lib /usr/local/cpanel/3rdparty/perl/536/lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/lib /opt/cpanel/perl5/536/site_lib/x86_64-linux /opt/cpanel/perl5/536/site_lib) at (eval 4) line 1.
BEGIN failed--compilation aborted at (eval 4) line 1.
The system failed to load the module “Cpanel::API::JetBackup” because of an error: Can't locate Cpanel/API/JetBackup.pm in @INC (you may need to install the Cpanel::API::JetBackup module) (@INC contains: /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/536/cpanel-lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/cpanel-lib /usr/local/cpanel/3rdparty/perl/536/lib/x86_64-linux /usr/local/cpanel/3rdparty/perl/536/lib /opt/cpanel/perl5/536/site_lib/x86_64-linux /opt/cpanel/perl5/536/site_lib) at (eval 4) line 1.
BEGIN failed--compilation aborted at (eval 4) line 1.
"
],
"metadata": {},
"status": 0,
"messages": null
}) for country: 'es'!
Failed to run pulldbdos es: exit status 1
Thanks a lot!
Last edited by a moderator: