For many webmasters, backing up their web sites is a task that is often neglected. If the server your site is hosted on crashes or you accidentally delete files, do you have a current backup to get your site restored quickly when the server is back online or if you need to switch hosts?
Downloading site backups is the safety net your business depends on when the unexpected occurs.
Having up to date backups is critical in minimizing downtime and lost revenue. Automated backup solutions exist, but if you are looking for a quick and simple way to download a backup with one click, the following script is all you need.
Two versions of the script exist, one for Windows platform and another for Linux running the bash shell. For Windows, you can use Internet Explorer or Firefox. The Linux script was written for Firefox, but can be changed to use other browsers.
These scripts can be easily modified by adding other commands and automated using a scheduler, but the intention was to provide a simple one click process to download backups without the need to connect to CPanel and navigate to the backup section.
The only interaction required is logging on to the host when prompted and selecting a folder to download.
Windows Instructions
- Create a file on your desktop and give it a name with .bat extension - yourdomain.bat and copy the script into it.
- Modify yourdomainname at set hostname=yourdomain.com to your site domain name.
- Modify 1234 at set port=1234 to the port number you use to connect to your site CPanel
- If you use Firefox, add REM in front of "C:\Program Files\Internet Explorer\iexplore.exe" and remove REM in front of "C:\Program Files\Mozilla firefox\firefox.exe"
- If you have a MYSQL database, modify dbname at set mysql=dbname to the name of the database and remove REM at the last two lines in the script.
REM #################################################################
REM Web Host Admin Tip from http://www.watchingthenet.com
REM #################################################################
@echo off
set HOSTNAME=yourdomainame
set PORT=1234
set MYSQL=database
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set MDATE=%%c%%a%%b
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set MM=%%a
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set DD=%%b
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set YY=%%c
IF %MM:~0,1%==0 SET MM=%MM:~1%
IF %DD:~0,1%==0 SET DD=%DD:~1%
set CDATE=%MM%-%DD%-%YY%
"C:\Program Files\Internet Explorer\iexplore.exe" https://%HOSTNAME%:%PORT%/getbackup/backup-%HOSTNAME%-%cdate%.tar.gz
REM "C:\Program Files\Mozilla firefox\firefox.exe" https://%hostname%:%port%/getbackup/backup-%HOSTNAME%-%cdate%.tar.gz
REM @ping -n 11 127.0.0.1>nul
REM "C:\Program Files\Internet Explorer\iexplore.exe" https://%HOSTNAME%:%PORT%/getsqlbackup/%MYSQL%.gz
REM "C:\Program Files\Mozilla firefox\firefox.exe" https://%HOSTNAME%:%PORT%/getsqlbackup/%MYSQL%.gz
exit
Linux Instructions
Modify the variables hostname and port to your domain name and port used to access CPanel
If you have a MYSQL database, un-comment # at the line for the MYSQL Firefox command. Modify the mysql variable to the name of the database.
#!/bin/sh
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Web Host Admin Tip from http://www.watchingthenet.com
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HOSTNAME=yourdomain.com
PORT=1234
MYSQL=dbname
mdate=`date +%Y%m%d`
MM=`date -u '+%m'`
DD=`date -u '+%d'`
cdate=`date +%Y-${MM#0}-${DD#0}`
echo ${cdate}
/Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager https://%hostname%:%port%/getbackup/backup-%hostname%-%cdate%.tar.gz
# /Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager https://%hostname%:%port%/getsqlbackup/%mysql%.gz
exit 0
Comments on Backup Your Web Site Home Directory Without Connecting To CPanel
steve @ 3:15 pm
I hope this doesn't work. It looks like people can get my stuff without and passwords. It appears from this all they need is a port number and a database name.
steve @ 3:47 pm
oh I see it will prompt your for a password. Anyway to add the username and password to the script?
@steve
Yes, but then it really would not be secure…as you hoped it would be safe and secure in your first comment….wish granted (to keep it secure) ;-).
steve @ 9:29 pm
No my first comment was with assumption that anyone from anywhere could get my stuff. I'm not (so) concerned about security of my password in my script since its going out on https. I did, after the fact, find the form of username:[email protected]:port What I'm really looking for now is a way to, from my host, take this zip file and send it my amazon S3 account. I've got the amazon part figured out (I think) but haven't figured out how to access the cpanel backup files (primarily dbase). My host doesn't allow the mysqldump command.