Backing up cPanel 11 hosted account with wget and dav/rsync
Posted by Admin • Thursday, August 21. 2014 • Category: Linux
I want to back up my hosting account regularly by retrieving everything onto my box somewhere else (my home server). By regularly, I mean every day. I want this to happen automatically. cPanel makes that hard to do, but there is always a way to script things.
First, let's break down what we want to back up:
Other fun options: Adding -nd -P cpanel will cause wget to ignore all local directories when saving files and instead pile everything it downloads to one directory called cpanel.
First, let's break down what we want to back up:
- Files
- Databases and email forwarders
- FTP account using recursive wget (create an FTP account with required access and teach an ftp client of your choice to recursively transfer everything. Hopefully this client skips unchanged files)
- WebDAV using rsync (this is what I'm using). Just mount, back up, unmount
- Submit your login to the log-in page and save cookies
- Parse the resulting file, find the backup link which includes your session name in the URL and hit that
- Only accept .gz files (DB backups and email stuff), but avoid hitting /logout, and don't start spidering the entire website
We save the front page first, because we can't do everything in one request. Once we have the backup page URL, we spider avoiding /logout in various forms (-X/logout) and anything that's more than one hop away from this page (-l1).
USER="your_username"
PASS="your_password"
DOMAIN="your_domain"
URL="https://$DOMAIN:2083/login/"
# Step 1: login to cpanel
wget -k --no-check-certificate --keep-session-cookies --save-cookies /tmp/my.backup.cookies.txt --post-data="user=$USER&pass=$PASS" $URL -O index.html
# Step 2: determine backup page URL
BACKUP_URL=$(grep 'backup/index.html' index.html | grep href | sed 's/^.*href="\([^"]*\)".*$/\1/' | tail -n 1)
echo "Backup URL is $BACKUP_URL"
# Step 3: get everything on that page except the file backup
wget -e robots=off --load-cookies /tmp/my.backup.cookies.txt --no-check-certificate -r -X/logout -l1 -A.gz -R/ -Rlogout -Rindex.html -Rrobots.txt -R"backup-$DOMAIN*" $BACKUP_URL
Other fun options: Adding -nd -P cpanel will cause wget to ignore all local directories when saving files and instead pile everything it downloads to one directory called cpanel.
0 Comments
Add Comment