Skip to content

Automatic cPanel Backup via Curl & Cron

This setup creates a full backup of your cPanel account each month, maintaining one backup for each previous year, and monthly backups for the current year. 

You need two files:

  • crontab.txt (for setting up the cron job, that is, the automation)
  • (the actual backup commands)


5 4 28 * * /home/yourdomain/
5 4 31 12 * /home/yourdomain/ --year

You'll have to set your crontab with a command like:

crontab crontab.txt

You can see what's in your crontab with the following command:

crontab -l

# cPanel Backup via Cron v1.2

#  Instructions
# Make sure CP_SCP_BACKUP_ROOT directory exists. It is "web_backup" by default.
# Within this directory you'll need a directory for each cPanel account you're
# backing up.
# I.e. if you're backing up "" and "" and you want them
# to be backed up in the default location of "web_backup", you'll need to
# execute the following commands at the recieving end:
# mkdir ~/web_backup
# mkdir ~/web_backup/
# mkdir ~/web_backup/

#cPanel info -- host that is being backed up
CP_SKIN=x3 # plain "x" is probably the most common one

#SCP/FTP info -- host to receive the backup file

# see cPanel backup page for alternatives of transfer mode

# target directory on remote host; do not include domain names in this one
CP_SCP_BACKUP_ROOT=web_backup%2F  # url encoded, e.g. "/" equals "%2F"

# creates the target path (directory and filename)
# if you make changes, remember to url encode slashes, i.e. "/" equals "%2F"
# if --year option is used, script creates a yearly filename, otherwise a monthly one
if [ "$1" = '--year' ]; then

# email address for sending notification after backup is completed
# initiate backup (the following command should be on one line)
curl --silent --insecure --user $CP_USERNAME:$CP_PASSWORD -d "dest=$CP_SCP_MODE&email=$CP_EMAIL&server=$CP_SCP_HOST&user=$CP_SCP_USER&pass=$CP_SCP_PASS&port=$CP_SCP_PORT&rdir=$CP_SCP_RDIR" https://$CP_DOMAIN:2083/frontend/$CP_SKIN/backup/dofullbackup.html > /dev/null

# gets curl return code

# curl encountered an error
if [ $CURL_EXIT -gt 0 ]; then
	echo curl returned exit status $CURL_EXIT - see curl manual pages for more details
	exit 69

# everything ok
exit 0

Put the file, say, in your account root and make the file executable (e.g. with command "chmod 700").

Let me know in the comments how it works for you. Thanks!

Monthly Archives: October 2007

Idle SSH Connection Drops? Fix with Keep-alive


One possible solution for dropping ssh connection is to create (or modify) a file name config in your .ssh directory (~/.ssh/config) on your local machine, adding a line ServerAliveInterval 60 This and plenty of other useful ssh keep-alive tips can be found on The Mad Philosopher's ssh keep-alive post. For some reason my ssh connections […]

OS X Mail: Always Bcc Specific Address


In Terminal, write defaults write UserHeaders '{"Bcc" = ""; }' You can write other headers as well: defaults write UserHeaders '{"Reply-To" = ""; "Bcc" = ""; }' To get defaults back: defaults delete UserHeaders This, as many other useful hints, came from macosxhints.

How To Speak HTTP To .htaccess Login


The raw HTTP to access a directory that is protected with .htaccess: Authorization: BASIC <base64encoded_user_pass> Where base64encoded_user_pass is a base64 encoded string from a string "username:password". With imaginative username my_username and password my_password, i.e. "my_username:my_password", the result is Authorization: BASIC bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ= (You may want to use some online tools, like opinionatedgeek's Base 64 Encoder.) And, […]