Today most of the web servers are running Linux. LAMP servers (Linux, Apache, MySQL, PHP) are the most frequent configuration used for web servers. Details can be different from server to server, but in general the backup described here, cen be configured on all the systems.

As backup is repeating activity, we will use cron service to trigger backup on selected time.
But lets go to the script first.

As most of the pages use database, we need to create a backup of the mysql web site database.

We can do that with the following comand:

mysqldump -uusername -p --default_character_set=utf8 database > database.sql

This will create a file database.sql with complete backup of the database, which we can later use to restore the database.

The next step is to zip the content of the web site.You can do that easiliy with:

7za a webpage.7z /var/www/html/websitedir/

This will create a backup file of the webpage named webpage.7z in your current directory.

Of course you can again 7z both file into a single archive. It also helps if we create a filename with date information.

To sum everything into a script:

tdy=`date +%Y%m%d`

echo "Creating backup."
mkdir $temp_dir
mysqldump -uusername -ppassword --default-character-set=utf8 database1 > $temp_dir/database1.sql
7za a $temp_dir/website1.7z $www_dir/website1/
7za a $backup_dir/website1-$tdy.7z $temp_dir/website1.sql $temp_dir/website1.7z
rm -Rf $temp_dir

mkdir $temp_dir
mysqldump -uusername -ppassword --default-character-set=utf8 database2 > $temp_dir/database2.sql
7za a $temp_dir/website2.7z $www_dir/website2/
7za a $backup_dir/website2-$tdy.7z $temp_dir/website2.sql $temp_dir/website2.7z
rm -Rf $temp_dir

echo 'Deleting old backups'
find $backup_dir* -mtime +100 -exec rm {} \;

echo 'Done.'

Of course we also added that backups older than 100 days are automatically deleted.

If we execute the script from console, it will make a backup of website1 and website2 into a /backup/websites directory. You of course can configure that the same directory is also a Dropbox folder, so all the files will be directly synchronized with your company computers. In the final step, we just have to put the script execution into a crontab. Open up an /etc/crontab file and enter:

0  0  *  *  * root sh /backup/ > /dev/null

That's it. You have a full working backup.