10. Nov. 2008

As for todays hosting is mainly done on UNIX systems transfering websites can be done quick and reliable using UNIX commands. And therefore a changing your Hosting Provider can become fairly easy.

Instead of downloading all content from Server A to your local system using a however clever FTP Client and later uploading it again to Server B, this whole file transfer can be done within one step using a server to server copying command.

As a basic requirement to use this feature, you have to have secure shell access onto both servers. Being logged in to one server (it doesn’t matter which one) you can use SCP command to transfer all your files. The syntax of the command is fairly easy and it is part of the command to specify source and target system and therefore is doesn’t matter if you are pulling or pushing the files.

Easy command line examples for an SCP command would be:

Copying file to host:

scp SourceFile user@host:directory/TargetFile

Copying file from host:

scp user@host:directory/SourceFile TargetFile

Using the -R option as well will allow you to transfer whole directory trees within one single copy command.

While transfering all files and perhaps several domain can take up several days depending on the size and complexity of your hosting, it can occur that parts of the original files are already changed again until the final go life.

To prevent differences in between source and new target system a final update of both system shortly before switching over does make sense. Here now the command RSYNC will help us.

With RSYNC you can syncronize files and folders between systems.

Again an easy command line example would be:

rsync -r user@host:directory/SourceFolder TargetFolder

Also here source and target system needs to be specified and therefore both sending and receiving are possible.

9. Nov. 2008

Sometimes we need to duplicate a directory with subfolders into a new location on the same server and we have to make sure that these directories are exactly the same.

Normally – but not best – we use the cp -pr command.
The result is that our softlinks aren’t links anymore and the timestamps of some directorys are not the same as they are in the source directory. To partially solve this, you can use tar to create an archive and untar it in the destination – the better way is a combination of find and cpio. You will be save to get all files and directories with links, timestamps and rights in destination like they are in the source location.

example:

change to the directory you want to copy from and invoke the following command
find . -depth -print | cpio -pdmv /destination/

9. Nov. 2008

Sometimes a situation can occur in which we need to do a bulk rename of files. Thinking about a situation in which we want to rename all .html files to make them inaccessible for a while or we want to rename all downloaded photos from your camera perhaps?

Being on Unix this can be done easily by using a simple 4 line shell script like the one below:

for a in *.html; do
  t=`echo $a | sed ‘s/.html$/.html.en/’`
  mv $a $t
done

In this example we will rename all .html file to .html.en e.q. index.html.en which comes handy in case you want to add another set of webpages to your server containing and supporting a 2nd languge.

Guess it is not really necessary to tell you that you should make a copy of your files first??

« previousnext »