The Journal

Backing up your whole website through cpanel

Don’t wait until you have a disaster regularly backup your site in cpanel using a scheduled tasks

This is a great thing but relies on you remembering to do it!, a better way would be to set up a script that runs every right and backs up your website to a specified directory which you can download at anytime, this method backups your home folder contents only so a mysql database back up will also be required separately if required.

Basically we need to set up a script and run that in “Scheduled Tasks (Cron job)” which is a linux tool that allows commands/scripts to be run at set intervals.

  1. First create a directory in your root level / (in a Linux environment with cPanel this will be one level higher than public_html) and name it /backups (this is where the backups will go) and create a directory /backupscripts at the same level. This means you have two new directories called backups and backupscripts.

    The script files will go in the backupscripts folder - structure will look like this - (in a Linux environment with cPanel this will be one level higher than public_html)

    • backupscripts/daily/backupdaily.sh
    • backupscripts/weekly/backupweekly.sh
    • backupscripts/monthly/backupmonthly.sh

    Then create directory structure : this is where your backups will live - to keep a daily, a weekly and a monthly back up on hand; so you need to create three directories first at your root level such as at /public_html/:

    • /backups/daily/
    • /backups/weekly/
    • /backups/monthly/

     

     

  2. Create three scripts and place each script in the corresponding folder in backupscripts/daily etc etc . Ensure the file permissions are 711 and double check if you ftp them into the folders on the server that they still have the correct file permissions.  Use a simple text editor like NotePad/TexEdit or TextWrangler or via Vi or Pico in the command line and paste the following:


  3. backupdaily.sh:

    #!/bin/bash
    rm -rf ~/backups/daily/*
    tar czf ~/backups/daily/backup_`date +%Y_%m_%d`.tgz ~/public_html


    backupweekly.sh:

    #!/bin/bash
    rm -rf ~/backups/weekly/*
    tar czf ~/backups/weekly/backup_`date +%Y_%m_%d`.tgz ~/public_html




    backupmonthly.sh:

    #!/bin/bash
    rm -rf ~/backups/monthly/*
    tar czf ~/backups/monthly/backup_`date +%Y_%m_%d`.tgz ~/public_html


    2. Create a file called backup.sh in /backups,

    #!/bin/bash
    tar czf ~/backups/backup_`date +%Y_%m_%d`.tgz ~/public_html

    Then create directory structure : to keep a daily, a weekly and a monthly back up on hand; so you would create three directories first at your root level such as at /public_html/:

    • /backups/daily/
    • /backups/weekly/
    • /backups/monthly/

    This tells Linux that is a command and will save a compressed zipped file and file it in your /backups folder, name it backup_Year/Month/Day and it is backing up the entire contents of the /public_html folder.

     

  4. Change the file permissions of backup.sh to 711 so just the owner has read/write/execute permissions and read permissions for user. Do this through either file manager in cPanel or FTP
  5.  

  6. The final thing to do is to set this script/command to run automatically in your cPanel. Log into your cPanel with Ecoweb hosting (and many other cpanel hosters) and use the scheduled tasks button to set a daily weekly and monthly backup.
  7.  

  8. Keep an eye on the number of backups and I recommend doing a test restore at a convenient time to check your backup plan is providing real good solid working backups
Posted by admin on 01/26 at 04:07 PM in News • (0) Comments

Comments

Name:

Email:

URL:

Comments:

Remember my personal information

Notify me of follow-up comments?

Enter this word:


Here:

Categories

Monthly Archives

Get our RSS feed

Casey's Hot Topics

seomozad