Apr 26

Hello guys and ladies,
Long time no see :) . Today I’m going to show you how to make a php script to perform full website backup the script can be executed via http request or via ssh shell or like a cron job .
We all know about the most standard way to add backup for your website maintenance for example using the Cron Jobs in the CPanel. If you already don’t know this – if your hosting provider does support CPanel you should be able to access it via this URL: www.yourwebsite.com/cpanel
Cron Job CPanel

After you login into you CPanel and choose ‘Cron jobs’ you can enter there manually script to fully backup your database or file system. For example a script for full file system backup should look like this:
tar -cvpzf my_backup_file.tar /home/your_user/public_html
we could make the script more interesting when instead of ‘my_backup_file’ we include the date and time in the filename:
tar -cvpzf `date +%y-%m-%d_%H-%M`.tar /home/ your_user/public_html
of course you should change `/home/your_user/public_html` to whatever your home directory is. You can find out what your home directory is by executing ‘pwd’ (print working directory) in the ssh shell or creating the file `exec.php` with the code:
<?php echo exec(‘pwd’); ?>

and after that executing the code by opening http://www.yoursite.com/exec.php in your browser.
So we can add this line directly into the Curl command field:
Cron Job CPanel Command field
But now I am going to tell you better way to do it, because very often the commands directly typed at the cron’s `Command:` field are ignored because of some stupid quote convention etc.
Full website filesystem backup using php file and cron job:
1. First we are going to create the file backup_filesystem.php and put this code into it :
<?php echo exec(‘cd /home/your_user/backup/files;tar -cvpzf `date +%y-%m-%d_%H-%M`.tar /home/ your_user /public_html’); ?>

2. After that we’ll access the website via the FTP and put the backup_filesystem.php file into the /home/your _user/backup/. Make sure that you create “backup” and “backup/files” directories if they are not already created. Better don’t put backup_filesystem.php file into the /public_html/ folder because we don’t want the users to have direct access to the file.

3. Now we are going back to the CPanel -> Cron Jobs. On the common settings we enter Once a day (so the Command will be executed once a day) and on the Command field we enter:
php ‘the path to backup_filesystem.php’
Cron Job CPanel enter Command
After that click on the ‘Add new cron job’ button and Voila !! – the Cron Job for backup of your database is ready.
The archive is created using low tar compression, so if needed you can archive your site using stronger bzip2 compression by replacing: “tar –cvpzf filename.tar” with “tar –cjf tarname.bz2”.
Cron Job CPanel enter Command
The full backup of your website is created in the /backup/files directory and can be downloaded via FTP if necessarily – as you see the filename include the date and time of the moment it has been created, so it won’t be hard for you to guess which is the latest version of the backup if needed.
Thank you for your time, next time I’m going to show you how to perform similar backup, but this time full database backup instead of filesystem backup.
Cheers :)

22 Responses to “Website file system backup using php and cron job”

  1. Anderson Smulik Says:

    Very straightforward and useful. Thanks.

  2. Canada goose outlet Says:

    I surely will bookmark your site.Best Regards!caiyifang/comment201112

  3. Peuterey outlet Says:

    Wow, Great post,Nice work, I would like to read your blog every day Thanks.caiyifang/comment201112

  4. cheap uggs Says:

    This article gives the light in which we can observe the reality This is a really good read for me. its really very good post. Thanks for posting this informative article.caiyifang/comment201112

  5. beats by dre Says:

    Wow, Great post,Nice work, I would like to read your blog every day Thanks.

  6. dr dre Cuffie Says:

    Nice post.Thank you for taking the time to publish this information very useful!I’m still waiting for some interesting thoughts from your side in your next post thanks.

  7. beats by dre uk Says:

    Thank you for taking the time to publish this information very useful!I’m still waiting for some interesting thoughts from your side in your next post thanks.

  8. oakley glasses Says:

    Good, I agree with your point of view, thanks for your sharing!I think i am very close to your imagination. caiyifang/comment201112

  9. oakley sunglasses Says:

    thank you for posting . please do more good article.i like it so much .I will always follow it..caiyifang/comment201112

  10. ugg boots outlet Says:

    Great post. Thanks for sharing..caiyifang/comment201112

  11. Winter Jacket Sale Says:

    http://www.snow-coats.com/ Let us seem at the other outside brand name-Monlcer. It also has its personal thermal

    technique. The brilliant hues and abnormal down are used for the duration of the course of

    naking to make confident warmth efficiency and comfort.The lousy impression on the

    preceding down jackets can be attributed to the incorrect methods to collocate it. If you

  12. UGGS Sale Says:

    Mostly all the Websites are for the information purpose and you have also created such a great website here.Such a great ideas you have Provided here.Thank you for sharing

  13. Christian Louboutin Says:

    Beige with red highlights, these are for men. There is a woman’s variation Christian Louboutin Volpi 150mm Alba and this is called the Stynger Gtx and it is blue and looks like the slightly christian louboutin sale daintier version of the blue Fugitive. Here are some of the features

  14. Tiffany and Co Outlet Says:

    I love this blog. In fact I challenged myself trying to commence one like this too, but not savvy enough on how to do it. How exactly is this so-called thing? Is it hard? Is it necessary to be smart in computers to create a blog?

  15. cheap louboutin shoes Says:

    We are all budding psychologists whether we know it or not and we pick higher a lot from what we suppose others wearing.

  16. Christian Louboutin Outlet Says:

    Good job. I was taught to do things in different blogs more every day. It will all the time to read the content material incentive to other writers and practice some things from their store. I prefer to use some of the content on my blog.

  17. moncler pas cher Says:

    moncler pas cher, manteaux moncler
    , doudoune moncler

  18. supra shoes Says:

    Justin Bieber Shoes, Supra TK Society, Supra Vaider

  19. moncler down jackets Says:

    今日、MONCLER MAYA Ivoryは、ほとんどの公式の仕入業者、特にMONCLER VBOROSIRI Blueになることを小売業者キューイングによるファッションレーベル引っ張りだこの一つであると主張することができます。そしてこの品物に対しては、提供する様々ながあることがモンクレールを購入することができます。

  20. Customized NFL Jerseys Says:

    At current you can get a few official Aaron Rodgers Women jersey and even while the gamers use the ordinary uniform in most from the video games, we can see one other two variations at least after or twice a year. In custom nfl Clay Matthews jersey background, it re-wrote the unofficial rule in accordance to which a staff should certainly have on the colored jersey when playing at place.

  21. christian louboutin outlet Says:

    The feature red-sole that makes Christian louboutin outlet shoes stand out at first is the glossy nail-varnish red sole that has become his trademark. Everyone says there is a demand and a desire for society, then the society can progress. And because the christian louboutin platforms in various designs, colors, shapes and styles of construction that have won more than the recovery of millions of women worldwide, it is catch up the demands of times.

  22. myyaxian Says:

    The main quarterback – Roth Reese Berg because of an ankle injury did not play the game, 37-year-old Charlie – budge first.

Leave a Reply

*

Spam Protection by WP-SpamFree