{"id":62,"date":"2013-10-15T14:48:00","date_gmt":"2013-10-15T14:48:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2013\/10\/15\/automatically-backup-godaddy-files-and-databases\/"},"modified":"2021-02-22T01:34:04","modified_gmt":"2021-02-22T01:34:04","slug":"backup-godaddy-files-and-databases","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2013\/10\/backup-godaddy-files-and-databases.html","title":{"rendered":"Automatically Backup GoDaddy Files and Databases"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><img decoding=\"async\" title=\"Go Daddy\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/godaddy.jpg\" alt=\"Go Daddy\" border=\"0\" \/><\/div>\n<h2 style=\"text-align: left;\">What is GoDaddy?<\/h2>\n<div style=\"text-align: justify;\">Go Daddy is an internet domain registrar and a web hosting company. The web hosting varies between shared hosting, Virtual Private Server (VPS) and dedicated servers.<\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Introduction<\/h2>\n<div style=\"text-align: justify;\">In a shared hosting environment, Go Daddy offers a one week backup for all the files, and allows a customer to rollback and restore any of those backups.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">However, Go Daddy does not backup the databases, which contains most of the website&#8217;s crucial information, such as customers database, dynamic pages, transactions and so on.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">The below script was built to backup Go Daddy websites and their databases on a shared host. Also, with a slight modification, the script should also work for any other host.<\/div>\n<p>&nbsp;<\/p>\n<h2>How to Backup Files and Databases?<\/h2>\n<div style=\"text-align: justify;\">In order to successfully back the websites&#8217; files and databases, few information are needed, which can be found in the &#8220;Databases&#8221; section of your host panel:<\/div>\n<ul style=\"text-align: left;\">\n<li>Database(s) host<\/li>\n<li>Database(s) name<\/li>\n<li>Database(s) user<\/li>\n<li>Database(s) password<\/li>\n<\/ul>\n<div style=\"text-align: justify;\">Those information should be written in the script, under the <span style=\"color: blue;\"><b>##### Database Configuration #####<\/b><\/span> section. Assuming we have two databases, each with a different host, name, user and password. Then we write them as follows:<\/div>\n<blockquote>\n<div style=\"text-align: left;\">\n<p><span style=\"font-family: 'Courier New',Courier,monospace;\">dbHost[0]=&#8217;localhost&#8217;<br \/>\ndbName[0]=&#8217;database1&#8242;<br \/>\ndbUser[0]=&#8217;user&#8217;<br \/>\ndbPass[0]=&#8217;myhardtoguesspassword&#8217;<\/span><\/p>\n<p>dbHost[1]=&#8217;db.domain.com&#8217;<br \/>\ndbName[1]=&#8217;database1&#8242;<br \/>\ndbUser[1]=&#8217;myusername&#8217;<br \/>\ndbPass[1]=&#8217;password&#8217;<\/p>\n<\/div>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">It doesn&#8217;t how many databases there are, every database information should be written in its own section.<\/div>\n<div style=\"text-align: justify;\">For example, first database would be written in:<\/div>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">dbHost[0]=&#8217; &#8216;<br \/>\ndbName[0]=&#8217; &#8216;<br \/>\ndbUser[0]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbPass[0]=&#8217; &#8216;<\/span><\/p><\/blockquote>\n<p>Second database in:<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">dbHost[1]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbName[1]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbUser[1]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbPass[1]=&#8217; &#8216;<\/span><\/p><\/blockquote>\n<p>Third database in:<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">dbHost[2]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbName[2]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbUser[2]=&#8217; &#8216;<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\">dbPass[2]=&#8217; &#8216;<\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">The Entire Script<\/h2>\n<p>Simply fill the <span style=\"color: blue;\"><b>################ Configuration ###############<\/b><\/span> section in the script and upload it to your server using ftp.<\/p>\n<p>The entire script can be found below, or on <a href=\"https:\/\/github.com\/etiennerached\/godaddy-backup-script\" target=\"_blank\" rel=\"noopener\">my github<\/a>:<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">#!\/bin\/bash<br \/>\n###################### Configuration ######################<\/span><\/p>\n<p>#Store the backups in the following directory<br \/>\n#Note: Always backup your data outside of your public_html or html directory. This will ensure your backup files won&#8217;t be accessed publicly from a browser.<br \/>\n#Example:<br \/>\n#backupDirectory=&#8221;backup\/mybackupfiles&#8221;<br \/>\nbackupDirectory=&#8221;backup&#8221;<\/p>\n<p>##### Database Configuration #####<br \/>\n#Databases Information<br \/>\n#You can add as much databases information as you wish<br \/>\n#The database information should be incremental and follow the below format:<br \/>\n#############<br \/>\n#dbHost[0]=&#8221;<br \/>\n#dbName[0]=&#8221;<br \/>\n#dbUser[0]=&#8221;<br \/>\n#dbPass[0]=&#8221;<br \/>\n#<br \/>\n#dbHost[1]=&#8221;<br \/>\n#dbName[1]=&#8221;<br \/>\n#dbUser[1]=&#8221;<br \/>\n#dbPass[1]=&#8221;<br \/>\n#<br \/>\n#dbHost[2]=&#8221;<br \/>\n#dbName[2]=&#8221;<br \/>\n#dbUser[2]=&#8221;<br \/>\n#dbPass[2]=&#8221;<br \/>\n#############<br \/>\n#<br \/>\n#<br \/>\n#Example:<br \/>\n##################################<br \/>\n#dbHost[0]=&#8217;localhost&#8217;<br \/>\n#dbName[0]=&#8217;database1&#8242;<br \/>\n#dbUser[0]=&#8217;user&#8217;<br \/>\n#dbPass[0]=&#8217;myhardtoguesspassword&#8217;<br \/>\n#<br \/>\n#dbHost[1]=&#8217;db.domain.com&#8217;<br \/>\n#dbName[1]=&#8217;database1&#8242;<br \/>\n#dbUser[1]=&#8217;myusername&#8217;<br \/>\n#dbPass[1]=&#8217;ghjkkjh2678(27&#8242;<br \/>\n##################################<\/p>\n<p>dbHost[0]=&#8221;<br \/>\ndbName[0]=&#8221;<br \/>\ndbUser[0]=&#8221;<br \/>\ndbPass[0]=&#8221;<\/p>\n<p>dbHost[1]=&#8221;<br \/>\ndbName[1]=&#8221;<br \/>\ndbUser[1]=&#8221;<br \/>\ndbPass[1]=&#8221;<\/p>\n<p>dbHost[2]=&#8221;<br \/>\ndbName[2]=&#8221;<br \/>\ndbUser[2]=&#8221;<br \/>\ndbPass[2]=&#8221;<\/p>\n<p>#Compress Databases (On=1 \/ Off=0)<br \/>\ncompressDatabases=1<\/p>\n<p>##### Files Configuration #####<br \/>\n#Directory (and subdirectories) to backup. By Default, the godaddy public directory is called &#8220;html&#8221;<br \/>\nfilesPath=&#8217;html&#8217;<\/p>\n<p>#Archive files as Zip(0) or Tar(1)<br \/>\nZipOrTar=1<\/p>\n<p>#Compress Files in Archive? (On=1, Off=0)<br \/>\n#Note: Godaddy scripts are usually interrupted after a specific time. Compressing\/deflating the files will take more time to complete. Use zero if you have a huge website and the script is always interrupted.<br \/>\ncompressFiles=0<\/p>\n<p>##### FTP Configuration #####<br \/>\n#Note: Using FTP is not secure, use it at your own risk. Your password will be stored in this file in plain text, and can be read by a simple ps command upon execution by others.<br \/>\n#Godaddy blocks most of the outbound ports, including port 21. If you have a FTP with an unblocked port, you can use this option, otherwise keep it disabled.<br \/>\n#Enable FTP Transfer (Yes=1 \/ No=0)<br \/>\nenableFtpTransfer=0<\/p>\n<p>#FTP Host<br \/>\nFtpHost=&#8221;<\/p>\n<p>#FTP Port<br \/>\nFtpPort=&#8221;<\/p>\n<p>#FTP User<br \/>\nFtpUser=&#8221;<\/p>\n<p>#FTP Password<br \/>\nFtpPass=&#8221;<\/p>\n<p>#FTP Path<br \/>\nFtpPath=&#8221;<\/p>\n<p>################# End Of Configuration ###################<\/p>\n<p>################# Script Execution ###################<\/p>\n<p>### Edit at your own risk ###<\/p>\n<p>#Store Current Date<br \/>\nDate=`date &#8216;+%m-%d-%Y_%H-%M&#8217;`<\/p>\n<p>#Create Final Backup Directory<br \/>\nbackupDirectory=&#8221;$backupDirectory\/$Date&#8221;<\/p>\n<p>#Check if backup directory exist, otherwise create it<br \/>\nif [ ! -d &#8220;$HOME\/$backupDirectory&#8221; ]<br \/>\nthen<br \/>\nmkdir -p $HOME\/$backupDirectory\/<br \/>\necho &#8220;Directory Created&#8221;<br \/>\nfi<\/p>\n<p>#Backup Databases<br \/>\nfor i in ${!dbHost[@]}<br \/>\ndo<br \/>\nif [ $compressDatabases -eq 1 ]<br \/>\nthen<br \/>\nfilename[i]=&#8221;$HOME\/$backupDirectory\/${dbName[$i]}_$Date.sql.gz&#8221;<br \/>\nmysqldump -h ${dbHost[$i]} -u ${dbUser[$i]} -p${dbPass[$i]} ${dbName[$i]} | gzip &gt; ${filename[i]}<br \/>\nelse<br \/>\nfilename[i]=&#8221;$HOME\/$backupDirectory\/${dbName[$i]}_$Date.sql&#8221;<br \/>\nmysqldump -h ${dbHost[$i]} -u ${dbUser[$i]} -p${dbPass[$i]} ${dbName[$i]} &gt; ${filename[i]}<br \/>\nfi<br \/>\ndone<\/p>\n<p>#Backup Files<br \/>\ncd $HOME\/$filesPath<\/p>\n<p>#Zip<br \/>\nif [ $ZipOrTar -eq 0 ]<br \/>\nthen<br \/>\nif [ $compressFiles -eq 0 ]<br \/>\nthen<br \/>\nfilesname=&#8221;$HOME\/$backupDirectory\/files_$Date.zip&#8221;<br \/>\nzip -r -0 $filesname * .[^.]*<br \/>\nelse<br \/>\nfilesname=&#8221;$HOME\/$backupDirectory\/files_$Date.zip&#8221;<br \/>\nzip -r -9 $filesname * .[^.]*<br \/>\nfi<br \/>\nfi<\/p>\n<p>#Tar<br \/>\nif [ $ZipOrTar -eq 1 ]<br \/>\nthen<br \/>\nif [ $compressFiles -eq 0 ]<br \/>\nthen<br \/>\nfilesname=&#8221;$HOME\/$backupDirectory\/files_$Date.tar&#8221;<br \/>\ntar -cvf $filesname .<br \/>\nelse<br \/>\nfilesname=&#8221;$HOME\/$backupDirectory\/files_$Date.tar.gz&#8221;<br \/>\ntar -zcvf $filesname .<br \/>\nfi<br \/>\nfi<\/p>\n<p>#FTP Transfer<br \/>\nif [ $enableFtpTransfer -eq 1 ]<br \/>\nthen<br \/>\nif [ &#8220;$FtpPath&#8221; == &#8220;&#8221; ]<br \/>\nthen<br \/>\nFtpPath=&#8221;$Date&#8221;<br \/>\nelse<br \/>\nFtpPath=&#8221;$FtpPath\/$Date&#8221;<br \/>\nfi<br \/>\n#Upload Database(s)<br \/>\nftp -nv $FtpHost $FtpPort\u00a0 &lt;&lt; END<br \/>\nuser $FtpUser $FtpPass<br \/>\nmkdir $FtpPath<br \/>\ncd $FtpPath<br \/>\nlcd $HOME\/$backupDirectory<br \/>\nmput *<br \/>\nbye<br \/>\nEND<br \/>\nfi<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">If you are a windows user, your script might not run correctly on GoDaddy servers, since GoDaddy servers use linux operating system.<\/div>\n<div style=\"text-align: justify;\">There are many tools and ways to convert DOS files to Unix files. The one I use is by logging in using SSH, browsing to the location of the script file and editing it:<\/div>\n<blockquote><p>vim filename<\/p><\/blockquote>\n<p>Once the text editor opens, type:<\/p>\n<blockquote><p>:set ff=unix<br \/>\n:w<br \/>\n:q<\/p><\/blockquote>\n<div style=\"text-align: justify;\">First line will convert from DOS to Unix, second line will save the file and third will quit the editor.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">The bash script file should also be executable, make sure it has a 744 permissions or above.<\/div>\n<h2 style=\"text-align: left;\">Automatic Backup and Cron Job<\/h2>\n<div style=\"text-align: justify;\">In order to run the script automatically, a cron job needs be setup. To setup a Cron job, go to your Web Hosting Panel, and search for <b>&#8220;Cron Job Manager&#8221;<\/b><\/div>\n<p><b>\u00a0<\/b><\/p>\n<div style=\"clear: both; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" title=\"Godaddy Cron Job Manager\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/cronjobmanager.jpg\" alt=\"Godaddy Cron Job Manager\" width=\"400\" height=\"283\" border=\"0\" \/><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">Create a new cron job, and choose how often do you want the backup to occur, in my case, I chose weekly at 12pm.<\/div>\n<div style=\"text-align: justify;\"><b>$HOME<\/b> means your hosting home directory, and <b>backup.sh<\/b> is the name of the script file. In my case, the script is outside the &#8220;<b>html<\/b>&#8221; directory.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/godaddycronjob.jpg\" width=\"400\" height=\"170\" border=\"0\" \/><\/div>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p><b>Questions or Comments? I will gladly answer!<\/b><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; What is GoDaddy? Go Daddy is an internet domain registrar and a web hosting company. The web hosting varies between shared hosting, Virtual Private Server (VPS) and dedicated servers. &nbsp; Introduction In a shared hosting environment, Go Daddy offers a one week backup for all the files, and allows a customer to rollback and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43,75,65,45,22,74,10],"tags":[],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-bash","category-cpanel","category-godaddy","category-mysql","category-php","category-script","category-zip"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":4,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}