In this article, we are discussing a bash script to upload CyberPanel backups to Google Drive. CyberPanel is one of the best opensource control panel and support openlitespeed web server out of the box. It’s enterprise editions supports LiteSpeed Enterprise editions. More details can be found in their website here.

script to upload cyberpanel backups to google drive
How to take CyberPanel backups to google drive

CyberPanel backups

We can schedule the backups from the CyberPanel Main » Backup » Create Backup with destination as “Home” directory. It will take backups at specified time to each user’s home directory. 

Script to upload CyberPanel backups to Google Drive

Our script here, will generate a fresh backup, move all of them to a single temporary directory for easy uploading, upload it to Google Drive using a script developed by prasmussen, gdrive. Once uploaded, the backups and the temporary directory are deleted. 


# This script takes CyberPanel backups and upload to the Google Drive
# gdrive script is adopted from
# Author : Arun D
# Rev : 1.0

# Checking whether the gdrive is already installed
if [ ! -e /usr/local/bin/gdrive ]
echo "gdrive not found. Installing it"
wget -O gdrive ""
sudo install gdrive /usr/local/bin/gdrive

echo "gdrive installed and linked to your account"

# G_ID is the Google Drive Directory ID. To get it, go to the directory created or add a new one. The GID is the random string found at the end of the URL.

# Variables :-

DATE="$(date +%Y-%m-%d)"

echo " Continuing with the backup generation"
echo "------------------------------------------"

echo $DATE
# Deleteing old backups and Journal Files and create fresh temporary backup directory
rm -rf /home/*/backup/* /var/log/journal/*/*.journal $BACKUP_DIR && mkdir -p "$BACKUP_DIR/$DATE"

# Executing a new CyberPanel's Local Backup Script instance

echo "Calling CybperPanel Backup Script to execute"
python /usr/local/CyberCP/plogical/

# Copying tar.gz backup files from the default backup location to the script's backup location
echo "Copying tar.gz files to Backup Directory"
mv /home/*/backup/*.tar.gz "$BACKUP_DIR/$DATE"

echo $(cd $BACKUP_DIR/$DATE && ls -A | wc -l) files in the backup directory

# Upload backup files to Directory with ID provided

echo "Uploading Backup tar files to Google Drive"
/usr/local/bin/gdrive upload --recursive --parent $G_ID $BACKUP_DIR/$DATE

# Remove backup directory to avoid confusions

echo "Removing temporary backup directory created"
rm -rf $BACKUP_DIR

echo " Backups are uploaded to your GDRIVE!!!"
sleep 5

This script works out of box. Just need to edit the variable G_ID with directory ID created in your Google Drive. You can run this manually or as a cron job. 

Try this and let me know how it goes. 

1 thought on “Script to upload CyberPanel backups to Google Drive

Leave a Reply

Your email address will not be published. Required fields are marked *