Archive-Backup Your Website

This is the #2 article in the backup topics, check out the first one : MySQL Archived Backup

Nowadays, nearly everyone / every company have a website of sorts. What most of us forgot is to back them up, in case of problems.
And as Murphy’s Law stated :

If it can go wrong, it will go wrong – in the worst possible time

Backup of your data can save you from such occasion.

An archived-backup can help you further – should you need to retrieve certain version of your data, then you can. Because it saves multiple copies of your data, each from certain point of time.

A way to do this is by using tools like the excellent rdiff-backup. In short – it’s like Apple’s Time Machine, but can be easily scripted & automated.

For other cases, you may need to create your own script for it.

Below is a script we use to backup our customer’s website.
It will backup both their MySQL database and the actual website itself.

Note that the backup script will archive for 2 weeks.
If you need diffent archive period, please feel free to modify the script, following the example in this article.

Here’s the script : backup-website.sh



#!/bin/bash

### Please change the variables below to suit you
sourcedir="/home/myuser/web"
targetdir="/home/myuser/mybackup"
targetfile="myname"
datestr="`date +%A`"
# 2 months archive
#datestr="`date +%d`"

tempdir="/tmp/$targetfile-$datestr"

dbuser="root"
dbpass="mypass"
database="mydb"

#################################
bmkdir="/bin/mkdir"
btar="/bin/tar"
bbzip2="/bin/bzip2"
bcp="/bin/cp"
bmysqldump="/usr/bin/mysqldump"

################################## start backup now

### create temporary space
$bmkdir $tempdir

### backup database
$bmysqldump -u $dbuser --password=$dbpass $database > $tempdir/$targetfile-$datestr.mysql
$bbzip2 $tempdir/$targetfile-$datestr.mysql

### backup website
$btar cvzf $tempdir/$targetfile-web-$datestr.tar.gz $sourcedir

### 2 weeks archive
$bcp $targetdir/$targetfile-$datestr.tar $targetdir/$targetfile-last-$datestr.tar

### backup website + mysql database
$btar cvf $targetdir/$targetfile-$datestr.tar $tempdir/*


Enjoy 🙂

94 thoughts on “Archive-Backup Your Website

  1. wah,detail banget nih. semoga bermanfaat untuk yg baca, seperti saya.

    Salam Kenal. di tunggu kunjungannya ya.

    ada kontak ga yg bisa di hubungi??

  2. kayanya berguna bagi yang punya website mandiri yah kang bro …. soal bekap membekap web …

  3. halo mas,
    saya berminat tukeran link..
    boleh?
    tolong kasih tau anchor apa yang harus saya pasang di web saya ya.. kalau saya sih tolong dipasang yg sama seperti di comment ini aja
    trims banyak n ditunggu respon nya 🙂

  4. Saya telah melacak situs Anda untuk waktu yang lama saya membaca artikel ini, ini adalah bacaan yang menarik saya akan terus memperhatikan lebih
    Artikel Anda adalah salah satu gaya yang paling klasik, ketika saya membaca sekali, saya telah sangat cinta dengan mereka, Anda berharap untuk bekerja lebih sempurna..

  5. nice atrikel gan.. banyak masukan utk kita”… sukses selalu gan .. mampir” ke link ini ya agan”http://www.spesialiskitchenset.com/ berisi tentang kitchenset..

  6. It is uncommon to obtain the knowledgeable individual inside to whom you have a number of initiative. On the globe right now, no one unquestionably cares about you regarding featuring other folks the way in which in such a subject material. Precisely how endowed I’m to get at this point determined such a fantastic web page since that. Its persons just like an individual exactly who come up with a genuine variation on earth from the techniques that they select.

  7. There’s nothing worse than losing your content. Backing up your files is definately a good idea.

  8. ini sangat bagus…. dan ane rasa hanya orang2 yang ahli html yang bisa membuat dan membacanya…sayangnya ane awam bgt…

  9. I’m a beginner, and still don’t understand what to do with this tutorial. Would you like to explain more about this? I need to backup my site. 😀

  10. nah dapat ilmu baru, kemarin database saya kehapus, dan blm tau cara ngebackupnya,, mantap mas

  11. ane sangat suka posting ini Hal ini berbeda dari posting Anda yang lain dan itu sangat relevan Terima kasih gan infonya

  12. Siapa yang tidak kenal dengan Clixsense?
    Sebuah PTC No Scam yang sangat direkomndasikan.
    Saya yakin Anda semua sudah mengetahuinya..
    Tapi bagi Anda yang ingin mengetahui lebih jelas apa itu Clixsense?
    Atau bagi Anda yang ingin mengetahui lebih dalam mengenai Clixsense..
    Silahkan ke http://www.panduanclixsense.blogspot.com/
    Sebuah blog sederhana yang semoga bermanfaat

Leave a Reply

Your email address will not be published. Required fields are marked *