7. Nov. 2008

Some of the low cost Hosting Providers do not even offer an interface to backup your webspace.

Personally I do think about it as annoying to download all the previous uploaded files again and again through a slow and less reliable FTP Client interface when an easy script executed on the server can do so much quicker for you instead.

To give you an idea what about I’m talking, I’ve written together an easy example you may feel free about to use it in your own environment in future.

It is able to do both, creating a local backup in a separate folder on your server, as also to transfer this backup to your local machine or even to another FTP Server on the net:

#!/bin/bash
# FTP Backup by Michael Lohmar
# Script: ftpbackup.sh
# Author: Michael Lohmar
# Contact? info@mikelo.com

if [ $# != 3 ];then
echo ""
echo "Shell script for backing up one given domain."
echo "Usage: $(basename $0) domain_to_backup [FTP/NOFTP] [DEL/NODEL]"
echo ""
exit
fi

version=1.0

##### INSTALL INSTRUCTIONS: STEP 1 #####
##### START ENTER YOUR INFO HERE #####

serverip=yourserver.com
# Your remote servers IP address
# EG: serverip=192.168.1.1

serveruser=youruser
# The FTP login for the remote server
# EG: serveruser=bob

serverpass=yourpassword
# The FTP password for the remote server
# EG: serverpass=mypassword

localdir=/home/your/local/folder
# WHERE LOCAL FILES ARE TO BACKUP
# NO TRAILING SLASH
# EG: localdir=/backup/folder/daily

sourcedir=/home/your/source/folder
# WHERE LOCAL FILES ARE TO BACKUP
# NO TRAILING SLASH
# EG: localdir=/domain/source/folder

remotedir=your/remote/folder
# FTP directory where you want to save files to
# This directory must exist on the FTP server!
# NO TRAILING SLASH
# EG: remotedir=/serverdirectory

##### END YOUR INFO HERE #####

##### INSTALL INSTRUCTIONS: STEP 2 #####
# CHMOD the script to 755: # chmod 755 ftpbackup.sh

# Add the script to a scheduled cron job to run as often as you like (if wished!)

# In SSH do crontab -e, then paste in the following
# 0 6 * * 0,1,3,5 /home/admin/ftpbackup.sh
# This does a FTP backup every second day of the week, lookup cronjobs for more info on setting dates and times.
# Don’t forget to substitue the path info to the script with your details
##### INSTALL COMPLETE #####
# DO NOT MODIFY ANYTHING BELOW #

host=`hostname`
cd $sourcedir

echo "Starting FTP Backup on " $host

# Creating a local tar.gz Archive
tar cfvz $localdir/$1_`date +%y_%m_%d`.tar.gz $1

# Transfer the tar.gz Archive to remote server
if [ $2 == FTP ];then
cd $localdir
echo "user $serveruser $serverpass
cd $remotedir
bin
verbose
put $1_`date +%y_%m_%d`.tar.gz
" | ftp -i -n $serverip
fi

# Delete local tar.gz Archive again
if [ $3 == DEL ];then
rm $localdir/$1_`date +%y_%m_%d`.tar.gz
fi

echo "Ftp backup complete on " $host
exit 0

7. Nov. 2008

Working with LAMP (Linux, Apache, MySQL and PHP) Applications we sooner or later do run into the need to change our actual runtime environment for it. Mostly based on specific PHP settings an application does need to be able to run first, we have to specify, change or increase PHP default settings, but do feel somewhat handicapped within a shared hosting environment. Usually Admins there do not allow everybody allow to modify or hack their central configuration files on the server.

But also for this situation clever developers have thought about a trick to help their community to overcome such hassle.

As a matter of fact it is possible to change PHP configuration settings within .htaccess very easily for everyone.

For example it is possible to

Prevent Global Variable Injection Attacks with:

    • php_flag register_globals off

    Prevent Cross Site Scripting (XSS) Attacks with:

      • php_flag allow_url_fopen off

      Prevent Code Injection Attacks with:

        • php_flag magic_quotes_gpc on

        To do so

        1. Open the .htaccess file located in your site’s home directory, or if you don’t have one, create a blank one now.

        2. Add any of the following code samples to your .htaccess file, each on it’s own line.

        5. Nov. 2008

        With  AllowOverride set to ALL, Web Administrators and Hosting Provider do gives their customers a powerfull to customize Apache fitting to all their personal needs.

        Running with this setting, Apache is looking for individual settings specified within a file .htaccess on a per directory basis. This means every folder below our webroot can have individual and different settings for sure.

        Mostly this feature is used to enable and enforce access restrictions, but also can be used to build up static multilingual websites as well. Doing so we have to enable need to enable MultiViews within .htaccess file.

        A basic example of such a .htaccess file would be:

        Options +MultiViews
        AddLanguage de de
        AddLanguage en en
        LanguagePriority de en

        Having MultiViews enabled we can add special language extensions to the filename (e.q. index.html.en), helping Apache to identified the correct file containing content in the language requested by the client. So a webbrowser requesting pages in German language and asking an Apache (runing on English language) for a page index.html would automatically get served with a page index.html.de while index.html.en or index.html would be the automatic fallback in case this German page would not be present.

        So the basic idea is just to double your webpages having one specific page in every needed language defined by it’s language specific filename extention.

        « previous