25 Nov 2008 @ 8:38 PM 

I am writing this in response to a question it seems I receive daily:
“What do you use to download movies and apps?”

So you are looking to download music, movies, or applications but those old P2P network such as Gnutella, Edonkey, and Freenet(think KaZaa, BearShare, Shareaza) just arent cutting it anymore.
Not only are these networks insecure and the clients used to connect to them full of spyware, but they are also outdated as Bittorent has become the standard for file sharing on the internet.

Here I will give a detailed(as much as I can) explanation of what BitTorrent is and how it compares to other methods of sharing files. I will post a detailed account of actually using a bittorrent client to download (and of course upload) files.

So…

What is BitTorrent?

BitTorrent is a protocol designed for transferring files. It is peer-to-peer in nature, as users connect to each other directly to send and receive portions of the file. However, there is a central server (called a tracker) which coordinates the action of all such peers. The tracker only manages connections, it does not have any knowledge of the contents of the files being distributed, and therefore a large number of users can be supported with relatively limited tracker bandwidth. The key philosophy of BitTorrent is that users should upload (transmit outbound) at the same time they are downloading (receiving inbound.) In this manner, network bandwidth is utilized as efficiently as possible. BitTorrent is designed to work better as the number of people interested in a certain file increases, in contrast to other file transfer protocols.

One analogy to describe this process might be to visualize a group of people sitting at a table. Each person at the table can both talk and listen to any other person at the table. These people are each trying to get a complete copy of a book. Person A announces that he has pages 1-10, 23, 42-50, and 75. Persons C, D, and E are each missing some of those pages that A has, and so they coordinate such that A gives them each copies of the pages he has that they are missing. Person B then announces that she has pages 11-22, 31-37, and 63-70. Persons A, D, and E tell B they would like some of her pages, so she gives them copies of the pages that she has. The process continues around the table until everyone has announced what they have (and hence what they are missing.) The people at the table coordinate to swap parts of this book until everyone has everything. There is also another person at the table, who we’ll call ‘S’. This person has a complete copy of the book, and so doesn’t need anything sent to him. He responds with pages that no one else in the group has. At first, when everyone has just arrived, they all must talk to him to get their first set of pages. However, the people are smart enough to not all get the same pages from him. After a short while they all have most of the book amongst themselves, even if no one person has the whole thing. In this manner, this one person can share a book that he has with many other people, without having to give a full copy to everyone that’s interested. He can instead give out different parts to different people, and they will be able to share it amongst themselves. This person who we’ve referred to as ‘S’ is called a seed in the terminology of BitTorrent. There’s more about the various terms in a later section.

How does BitTorrent compare to other forms of file transfer?

The most common method by which files are transferred on the Internet is the client-server model. A central server sends the entire file to each client that requests it — this is how both http and ftp work. The clients only speak to the server, and never to each other. The main advantages of this method are that it’s simple to set up, and the files are usually always available since the servers tend to be dedicated to the task of serving, and are always on and connected to the Internet. However, this model has a significant problem with files that are large or very popular, or both. Namely, it takes a great deal of bandwidth and server resources to distribute such a file, since the server must transmit the entire file to each client. Perhaps you may have tried to download a demo of a new game just released, or CD images of a new Linux distribution, and found that all the servers report “too many users,” or there is a long queue that you have to wait through. The concept of mirrors partially addresses this shortcoming by distributing the load across multiple servers. But it requires a lot of coordination and effort to set up an efficient network of mirrors, and it’s usually only feasible for the busiest of sites.

Another method of transferring files has become popular recently: the peer-to-peer network, systems such as Kazaa, eDonkey, Gnutella, Direct Connect, etc. In most of these networks, ordinary Internet users trade files by directly connecting one-to-one. The advantage here is that files can be shared without having access to a proper server, and because of this there is little accountability for the contents of the files. Hence, these networks tend to be very popular for illicit(and I say that loosely) files such as music, movies, pirated software, etc. Typically, a downloader receives a file from a single source, however the newest version of some clients allow downloading a single file from multiple sources for higher speeds. The problem discussed above of popular downloads is somewhat mitigated, because there’s a greater chance that a popular file will be offered by a number of peers. The breadth of files available tends to be fairly good, though download speeds for obscure files tend to be low. Another common problem sometimes associated with these systems is the significant protocol overhead for passing search queries amongst the peers, and the number of peers that one can reach is often limited as a result. Partially downloaded files are usually not available to other peers, although some newer clients may offer this functionality. Availability is generally dependent on the goodwill of the users, to the extent that some of these networks have tried to enforce rules or restrictions regarding send/receive ratios.

Use of the Usenet binary newsgroups is yet another method of file distribution, one that is substantially different from the other methods. Files transferred over Usenet are often subject to miniscule windows of opportunity. Typical retention time of binary news servers are often as low as 24 hours, and having a posted file available for a week is considered a long time. However, the Usenet model is relatively efficient, in that the messages are passed around a large web of peers from one news server to another, and finally fanned out to the end user from there. Often the end user connects to a server provided by his or her ISP, resulting in further bandwidth savings. Usenet is also one of the more anonymous forms of file sharing, and it too is often used for illicit files of almost any nature. Due to the nature of NNTP, a file’s popularity has little to do with its availability and hence downloads from Usenet tend to be quite fast regardless of content. The downsides of this method include a baroque set of rules and procedures, and requires a certain amount of effort and understanding from the user. Patience is often required to get a complete file due to the nature of splitting big files into a huge number of smaller posts. Finally, access to Usenet often must be purchased due to the extremely high volume of messages in the binary groups.

BitTorrent is closest to Usenet, in my opinion. It is best suited to newer files, of which a number of people have interest in. Obscure or older files tend to not be available. Perhaps as the software matures a more suitable means of keeping torrents seeded will emerge, but currently the client is quite resource-intensive, making it cumbersome to share a number of files. BitTorrent also deals well with files that are in high demand, especially compared to the other methods.

Where can I download the BitTorrent program?

There are several choices here, because unlike some peer to peer applications (such as Kazaa), the BitTorrent implementation is open source. This means that programmers are free to take the source code to the program and modify it, if they feel there is something they’d like to change. Here are the various clients of which I am aware. As a note I use Azureus(Vuze) exclusivley on Linux and Windows. It has a great set of features and is easy to configure and learn. It is somewhat CPU and Memory intensive so a  strong CPU(3Ghz+) and 1GB+ of memory is highly recomended for optimal performance. It will certainly work fine with a less powerful machine but dont expect to get much other work done.

  • Azureus - Recommended! A very nice Java client that incorporates a full-featured GUI with extensive visualizations/statistics about the transfer. You will need the Java Runtime Environment which you most likely have.
  • The Shad0w’s experimental client - Recommended! This client incorporates the codebase of the official version as well as all the improvements of the experimental version, below. Additionally, there are some misc. bug fixes, improvements from the latest development CVS sources, a user preferences feature that remembers its settings, and more. I highly recommend this version! (alternate) (alternate 2)
  • burst! - Recommended! This client features a smaller memory footprint compared to the others, due to replacing the wxPython GUI with one written in Delphi. The GUI lets you control multiple transfers from a single window, in addition to many other handy features such as a built-in TorrentSpy-like capability. It uses the same Python back-end as The Shad0w’s client so you also get all of the recent developments included therein.
  • burst plus! - A client which is based on the burst base and includes Spanish language support, as well as some other additions.
  • SimpleBT - Another fork of the burst code base that features Chinese language support.
  • ABC (”Another BitTorrent Client”) - This is a relatively new client that includes many of the most recent changes in the experimental versions, as well as other added features such as controling multiple downloads from a single window, queueing, automatic seeding, etc. See also: Sourceforge page.
  • Official client - This is the “official” client in that it is the latest supported version from Bram Cohen, architect of BitTorrent. It has the fewest features of all the clients, and releases are much more conservative than the experimental versions. Use this if you want stability but don’t need any of the common features of the other clients, such as upload rate limiting. See also: (CVS view), Sourceforge page.
  • Eike Frost’s Experimental client - This is based on the official version, with patches to allow upload rate control and show statistics about the number of peers and seeds, among other things. New in the “-2″ revision is support for displaying additional details about the peers that are connected, as well as some annoyance and bug fixes.
  • Personal Torrent Collector (PTC) - This is an alternative GUI interface to the Python BitTorrent client. It has support for a number of interesting features, such as the ability to control the total bandwidth usage of a group of BitTorrent transfers, and RSS syndication for organizing torrent files. See also: SourceForge page.
  • Shareaza - Newer public beta versions of this program now include BitTorrent support, in addition to the eDonkey2k and Gnutella protocols. However, the BitTorrent support may still have bugs, and some things (such as seeding a file) may not be as straightforward as with dedicated BitTorrent clients.
  • NovaTorrent - I welcome reviews of this client. :-) I have not personally evaluated it yet.
  • BitTorrent++ - This is an alternative to the official client. It supports extra functionality such as multiple downloads from a single GUI. Some people (myself included) have experienced major bugs with this program, so consider it unstable and use a different client unless you want to experiment. It appears to be abandoned and has not had any bug fixes in a long time. Therefore, since these bugs have the ability to adversely affect the performance of the BitTorrent swarm, so pleae do not use this client.

Linux/Unix

Most of the clients that are pure Python/wxPython (e.g. the official BitTorrent client, Eike Frost’s experimental, Shad0w’s experimental) will run under *BSD/Linux without problems. The source code tarballs for all of these clients are available at the home pages; see the links above. Clients written in other cross-platform languages such as Java (e.g. Azureus) should also work.

The biggest challenge to running a BT client under *BSD/Linux is getting the required libraries installed. At a minimum you will need Python 2.2 or greater. If you want to use the ‘-gui’ versions of the clients you will also need wxWindows, which has Python bindings called wxPython. These should all be available as packages for your system. Your first step should be to consult your distribution’s package system and get these prerequisites installed.

For Debian systems there is a package called bittorrent, which requires the python 2.2 package. You should also install the packages libwxgtk2.4-python and mime-support, if you plan to use the GUI version of the client.

If you are using Mandrake with Cooker, you might want to try the RPMs listed here.

Below are some general instructions for installing on a Unix/Linux system.

Install Python, preferably version 2.2. You can run “python -V” to see what version you currently have installed, if any. Also, you may have multiple versions of Python installed, so you might check /usr/bin for commands like python2.2 if plain python says it’s version 1.x. If your distribution uses packages, use the search tool to find prepackaged versions before trying to manually install. Try here and here for Python RPMs.

Install wxPython if you want to use the GUI version. Note that this will require the GLib and GTK+ libraries, which are probably already on your system if you have GNOME installed. (Start here or search your distribution’s package manager if you need GTK+.) You’ll want to find the wxPython package corresponding to the version of Python which you have installed. For RPM systems such as RedHat and Mandrake, you might try the following wxPython RPMs corresponding to version 2.1, version 2.2, and version 2.3 of Python. More RPMs are available at the Sourceforge site, and you can also consult the wxPython download page. Please be aware that the RPMs linked above assume that Python is installed under /usr and that the Python libs are in /usr/lib/python2.x/. If this is not the case, you will probably need to tell the installer this information.

Finally, install the source tarball for the BT client to a directory of your choice. To integrate the client with your web browser, it will be necessary to associate files of type “application/x-bittorrent” with the BitTorrent client. You will need to add a line such as the following to your /etc/mailcap file:

application/x-bittorrent; /usr/local/bin/btdownloadgui.py –responsefile %s; test=test -n “$DISPLAY”

Note that you should substitute the correct path for the location in which you installed the source tarball. If don’t have wxPython or would prefer to use one of the text-mode clients you can replace btdownloadgui.py with btdownloadcurses.py or btdownloadheadless.py. Also note there’s an error in the INSTALL.unix.txt file, which is missing the –responsefile argument.

Other web browsers may have a different way of associating a command with a MIME-Type, so you may want to try looking at the preferences or init file for details.

Java Clients (platform independent)

  • Azureus - A full-featured Java BitTorrent client with many enhancements and features.
  • snark 0.4 - Snark is an implementation of BitTorrent protocol that uses gcj, the GNU Compiler for Java. In addition to acting as a regular client, Snark also includes an integrated .torrent file creator, micro-HTTPd server, and tracker. With Snark the user can share files with a single command, without the usual hassle of installing a tracker, finding a web server, posting the .torrent file, etc. Compilation requires gcj 3.3 or higher; alternatively you can find a precompiled bytecode version here. See the home page for more information.
  • Effusion 0.3 - Experimental Java client with IRC integration. See home page for details and usage.
  • JTorrent 0.1 - This is a line-by-line port of the 3.0.2 python client/tracker to Java. It currently installs and runs under Windows and Unix, and requires the JRE v1.4 or greater. To install, download the installer and have a look at the README file. See also the project status README. Note that this is alpha-level code, so be prepared for bugs.

What other BitTorrent-related utilities are out there?

  • TorrentSpy - Recommended! An MS Windows tool which allows you to query a tracker about a specific torrent, view metadata info, check a file’s hashes, etc. A new feature is the “create” tab for making torrent files to upload.
  • maketorrent - A utility for creating torrent files, by the author of the burst! client. Version 1.x of MakeTorrent was a modified version of the Python ‘completedir’ program with extra features. Version 2.x is a complete rewrite in Delphi. Highly recommended!
  • completedir 1.0.1 - A utility for creating new .torrent files, part of the official BitTorrent client package. This is packaged as a Windows installer, get the source code for use with other platforms.
  • BNBT - This is a C++ implementation of a BitTorrent tracker. It should compile under most any Unix with GCC available, as well as MS Windows with MSVC (binaries included.) It includes all of the functionality of the reference Python tracker, but it also includes many enhancements: user accounts, improved web interface, statistics, etc. See also the TrackPak for a bundled BNBT and installer that’s easy to use.
  • Java BitTorrent Tools - A metafile viewer/editor, availability checker, and a basic tracker.
  • BTChange 0.94a - For modifying tracker info in an existing .torrent file. Use this if the tracker changes, so that you don’t have to recreate the file. See also: Sourceforge page.
  • PHPBTTracker - a free (GPL) tracker implementation in PHP with a MySQL back-end, includes built-in statistics collection and reporting. See also: sample output.
  • DumpTorrentCGI - Use this handy web page to parse and output the contents of a .torrent file (from either your local system or a link URL.) Use this to quickly determine a torrent’s hash ID or which tracker is hosting it.
  • trackerlyze.pl 1.11 - A free (GPL) Perl script that analyzes the logfile of a tracker and creates graphs and reports of the bandwidth used and number of peers/seeds. See also: Home page.
  • libbt - A library implementation of the BitTorrent protocol in C. This project is still under development, and is not suitable to end-users at this point.

I’ve installed BitTorrent, now what? There’s no program to run!

BitTorrent is not like other peer-to-peer applications (such as Winmx, Kazaa, Gnutella, etc.) in that it does not have its own “universe.” Put another way, BT lives on top of the Web, which means that all of the searching/listing of available files is done on the web. When you find a file you want to download, you click on it and the BitTorrent client program will run and ask you where to put it, and then start downloading.

What do all these words mean? (seeding, uploading, share rating, etc.)

Here is a brief list of words associated with BitTorrent and their meanings.

torrent
Usually this refers to the small metadata file you receive from the web server (the one that ends in .torrent.) Metadata here means that the file contains information about the data you want to download, not the data itself. This is what is sent to your computer when you click on a download link on a website. You can also save the torrent file to your local system, and then click on it to open the BitTorrent download. This is useful if you want to be able to re-open the torrent later on without having to find the link again.
In some uses, it can also refer to everything associated with a certain file available with BitTorrent. For example, someone might say “I downloaded that torrent” or “that server has a lot of good torrents”, meaning there are lots of good files available via BitTorrent on that server.
peer
A peer is another computer on the internet that you connect to and transfer data. Generally a peer does not have the complete file, otherwise it would be called a seed. Some people also refer to peers as leeches, to distinguish them from those generous folks who have completed their download and continue to leave the client running and act as a seed.
seed
A computer that has a complete copy of a certain torrent. Once your client finishes downloading, it will remain open until you click the Finish button (or otherwise close it.) This is known as being a seed or seeding. You can also start a BT client with a complete file, and once BT has checked the file it will connect and seed the file to others. Generally, it’s considered good manners to continue seeding a file after you have finished downloading, to help out others. Also, when a new torrent is posted to a tracker, someone must seed it in order for it to be available to others. Remember, the tracker doesn’t know anything of the actual contents of a file, so it’s important to follow through and seed a file if you upload the torrent to a tracker.
reseed
When there are zero seeds for a given torrent (and not enough peers to have a distributed copy), then eventually all the peers will get stuck with an incomplete file, since no one in the swarm has the missing pieces. When this happens, someone with a complete file (a seed) must connect to the swarm so that those missing pieces can be transferred. This is called reseeding. Usually a request for a reseed comes with an implicit promise that the requester will leave his or her client open for some time period after finishing (to add longevity to the torrent) in return for the kind soul reseeding the file.
swarm
The group of machines that are collectively connected for a particular file. For example, if you start a BitTorrent client and it tells you that you’re connected to 10 peers and 3 seeds, then the swarm consists of you and those 13 other people.
tracker
A server on the Internet that acts to coordinate the action of BitTorrent clients. When you open a torrent, your machine contacts the tracker and asks for a list of peers to contact. Periodically throughout the transfer, your machine will check in with the tracker, telling it how much you’ve downloaded and uploaded, how much you have left before finishing, and the state you’re in (starting, finished download, stopping.) If a tracker is down and you try to open a torrent, you will be unable to connect. If a tracker goes down during a torrent (i.e., you have already connected at some point and are already talking to peers), you will be able to continue transferring with those peers, but no new peers will be able to contact you. Often tracker errors are temporary, so the best thing to do is just wait and leave the client open to continue trying.
downloading
Receiving data FROM another computer.
uploading
Sending data TO another computer.
share rating
If you are using the experimental client with the stats-patch, you will see a share rating displayed on the GUI panel. This is simply the ratio of your amount uploaded divided by your amount downloaded. The amounts used are for the current session only, not over the history of the file. If you achieve a share ratio of 1.0, that would mean you’ve uploaded as much as you’ve downloaded. The higher the number, the more you have contributed. If you see a share ratio of “oo”, this means infinity, which will happen if you open a BT client with a complete file (i.e., you seed the file.) In this case you download nothing since you have the full file, and so anything you send will cause the ratio to reach infinity. Note: The share rating is just a number that is displayed for your convenience. It does not directly affect any aspect of the client at all. In general, out of courtesy to others you should strive to keep this ratio as high as possible, of course.
distributed copies
In some versions of the client, you will see the text “Connected to n seeds; also seeing n.nnn distributed copies.” A seed is a machine with the complete file. However, the swarm can collectively have a complete copy (or copies) of the file, and that is what this is telling you. Referring again to the “people at a table” analogy, consider the case where the book has 10 pages, and person A has pp.1-5 and B has pp.6-10. Collectively, A and B have a complete copy of the book, even though no one person has the whole thing. In other words, even if there are no seeds, as long as there is at least one distributed copy of the file everyone can eventually get a complete file. Meditate on this, the Zen of BitTorrent, grasshopper.
choked
This is a term used in the description of the BitTorrent protocol. It refers to the state of an uploader, i.e. the thread that sends data to another peer. When a connection is choked, it means that the transmitter doesn’t currently want to send anything on that link. A BT client signals that it’s choked to other clients for a number of reasons, but the most common is that by default a client will only maintain –max_uploads active simultaneous uploads, the rest will be marked choked. (The default value is 4 and this is the same setting that experimental client GUI lets you adjust.) A connection can also be choked for other reasons, for example a peer downloading from a seed will mark his connection as choked since the seed is not interested in receiving anything. Note that since each connection is bidirectional and symmetrical, there are two choked flags for each connection, one for each Tx endpoint.
interested
Another term used in the protocol specification. This is the corollary to the choked flag, in that interested refers to the state of a downloader with respect to a connection. A downloader is marked as interested if the other end of the link has any pieces that the client wants, otherwise the connection is marked as not interested.
snubbed
If the client has not received anything after a certain period (default: 60 seconds), it marks a connection as snubbed, in that the peer on the other end has chosen not to send in a while. See the definition of choked for reasons why an uploader might mark a connection as choked. The real function of keeping track of this variable is to improve download speeds. Occasionally the client will find itself in a state where even though it is connected to many peers, it is choked by all of them. The client uses the snubbed flag in an attempt to prevent this situation. It notes that a peer with whom it would like to trade pieces with has not sent anything in a while, and rather than leaving it up to the optimistic choking to eventuall select that peer, it instead reserves one of its upload slots for sending to that peer. (Reference)
optimistic unchoking
Periodically, the client shakes up the list of uploaders and tries sending on different connections that were previously choked, and choking the connections it was just using. You can observe this action every 10 or 20 seconds or so, by watching the “Advanced” panel of one of the experimental clients.
Tags Tags: , , ,
Categories: Teknology
Posted By: DteK
Last Edit: 26 Nov 2008 @ 02 36 AM

E-mailPermalinkComments (0)
 25 Nov 2008 @ 2:37 PM 

mod_rewrite is a module for the Apache webserver that allows apache to dynamically change the url of a site using php (or other scripting languages). It may seem like a difficult/confusing task at first, but it actually only takes a few steps on most linux distro’s .

1. Before you begin this, please make sure you make a backup copy of the original file in case you make a mistake, this way you can always go back to the original configuration - always backup before you begin doing something like this.)
2. Find the httpd.conf file (usually you will find it in a folder called conf.  In Fedora you can find it at /etc/httpd/conf .)
3. Inside the httpd.conf file find and uncomment the line “LoadModule rewrite_module modules/mod_rewrite.so”
4. After you have made the changes and saved them, restart your httpd (apache) server for the changes to take affect. as root : apachectl -k restart

Test It

If apache started without any errors mod_rewrite should be enabled, so now lets verify:

1. Create a php file called “rewrite.php” with your text editor
2. Copy and paste the following code into rewrite.php

<html>
<h2 align=center>
<?
// mod_rewrite Test Page
//  Dtek360 2008 dtek@dtek360.net
if($_GET['link']==1){echo”You are not using mod_rewrite”;}
elseif($_GET['link']==2){echo”Congratulations!! You are using Apache mod_rewrite”;}
else{echo”Linux Apache mod_rewrite Test Tool”;}
?>
</h2>

<hr>

<head>
<title>How To Test mod_rewrite in Apache Linux Server</title>
</head>

<body>
<p align=”center”>by <a href=”http://www.dtek360.net”>dtek360</a></p>
<p><a href=”rewrite.php?link=1″>LINK1</a> = rewrite.php?link=1</p>
<p><a href=”link2.html”>LINK2</a> = link2.html</p>
<p>How this works: both links are for this same page, except they both are different. link one is without the mod_rewrite and link2 is using mod_rewrite. Link1 show the php file, with with mod_rewrite we are mascarading the php file into a html file. you can use whatever type of extension you want, you can change it to .htm or .shtml etc… all you have to do is to make sure you also change it in the .htaccess file</p>
<p>&lt;&lt;
</body>
</html>

3. Save rewrite.php
4. Now create a file called .htaccess with your text editor
5. Populate the following into the .htaccess file:

RewriteEngine On
RewriteBase /t1/
This requires you have the alias setup in httpd.conf “Alias /t1/ “/var/www/html/test”
RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

6. Save  .htaccess
7. Now upload these two file into a new directory in your site. for example: test
8. Open the rewrite.php file with your browser .
9. you should see two links, LINK1 and LINK2 Click on LINK1 and the same page will display.
10. Now click on LINK2 and the same page will display with the a mod_rewrite message. If it doesnt you either did something wrong. Check your steps. If you checked your steps, refresh your browser, and if refreshing doesn’t work, then you don’t have mod_rewrite enabled.

You can also add this code to rewrite.php to see if mod_rewrite was loaded by apache:

if ( in_array(”mod_rewrite”, apache_get_modules()) ) echo “mod rewrite on”;

NOTE

The “AllowOverride All” must be set for .htaccess to override config settings
You will pull your hair out trying to figure out why you thing it is set up properly, but the rewrite is
not working as you get http 404 pages.

You can also enable Rewrite Logging to get some useful debugging info:

in httpd.conf:
RewriteLog “/var/log/httpd/rewrite_log”
RewriteLogLevel 9

Tags Tags: ,
Categories: Apache WebServer
Posted By: DteK
Last Edit: 26 Nov 2008 @ 02 34 AM

E-mailPermalinkComments (0)
 25 Nov 2008 @ 2:23 PM 

So far, we covered backing up files locally and over a network. Now let let see how to backup databases(only mysql supported - yet).

The script uses ‘mysqldump’ command to backup the data. That means that the backups are in the SQL dump format. The dumps of all the databases that are backed up are compressed and stored in the destination folder. They will be named in this format - YYYY-MM-DD.tar.gz.

Configuration File

This script reads a configuration file named ‘dbbackup.config’ and backups all the databases specified in that file to another location in the same system. This configuration file must be in the same folder as the perl script. The configuration file format is given below…

Data
Project_Nexty
App_activecollab
# Unwanted_DB - commented - will not be backedup
binco
binnyva

The Perl Script


#!/usr/bin/perl
# Backups all the databases specified in the dbbackup.config file

$backup_folder = '/var/Backup/Special/Databases'; #EDIT THIS LINE

use File::Basename;
my $config_file = dirname($0) . "/dbbackup.config";
my @databases = removeComments(getFileContents($config_file));

chdir($backup_folder) or die("Cannot go to folder '$backup_folder'");

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++;
#Zero padding
$mday = '0'.$mday if ($mday<10);
$mon = '0'.$mon if ($mon<10);

my $folder = "$year-$mon-$mday";
mkdir($folder) or die("Cannot create a folder called '$folder'");

foreach my $database (@databases) {
	next if ($database eq '');
	chomp($database);

	my $table = '';
	if(index($database,' ')+1) { #Get just 1 table in the database - if there is a ' '(space) in the db name
		my @parts = split(' ',$database);
		$database = $parts[0];
		$table = $parts[1];
	}

	print "Backing up $database ... ";

 	my $file = $database;
 	$file .= '_' . $table if($table ne '');
 	$file .= ".sql";

 	`mysqldump -u root $database $table > $folder/$file`;

	print "Done\n";
}
print "Compressing the folder ... ";
`tar -czf $folder.tar.gz $folder/`;
print "Done\nRemoving Folder ... ";
`rm -rf $folder`;
print "Done\n\n";

sub getFileContents {
	my $file = shift;
	open (FILE,$file) || die("Can't open '$file': $!");
	my @lines=<FILE>;
	close(FILE);

	return @lines;
}

sub removeComments {
	my @lines = @_;

	@cleaned = grep(!/^\s*#/, @lines); #Remove Comments
	@cleaned = grep(!/^\s*$/, @cleaned); #Remove Empty lines

	return @cleaned;
}

If you need, you can set this script as a cron job - this will make sure that you don’t have to worry about the backup.

Tags Tags: , , , ,
Categories: MySQL, linux
Posted By: DteK
Last Edit: 25 Nov 2008 @ 02 23 PM

E-mailPermalinkComments (45)

This script will backup the specified files to another computer on your network. You can also use this to send your files to a remote server. This script compliments the last Rsync Backup script. Its possible to combine both the script together, I prefer to keep them separate.
The Setup

For this to work, you need to have a password-less login system over ssh. You should configure the remote system to accept your credentials by giving your public key to the remote server. If you are not sure how to do that, just leave a comment and I’ll make a post on how to set it up.

The configuration file is the same format as the one used in the last Rsync script. But in this case, the file name will be ‘rsyncnetworkbackup.config‘.
The Code

#!/usr/bin/perl

#The folder on the remote system that must be used to store the data
$backup_folder = ‘/home/neo/Backup’; #Final ‘/’ must NOT be there.
# The user for whom we have set up the key based login
$backup_user = ‘neo’;
# The IP address/domain name of the remote system.
$backup_server = ‘192.168.0.30′;

use File::Basename;
my $config_file = dirname($0) . “/rsyncnetworkbackup.config”;
my @all_locations = removeComments(getFileContents($config_file));

foreach my $folder_locations (@all_locations) {
my($folder,$backup_location) = split(/\s+/,$folder_locations);

print “Backing up $folder to $backup_location … “;
`rsync -avze ssh $folder $backup_user\@$backup_server:\”$backup_folder/$backup_location\”`;
print “Done\n”;
}

sub getFileContents {
my $file = shift;
my @lines;

open (FILE,$file) || die(”Can’t open ‘$file’: $!”);

@lines=;
close(FILE);
return @lines;
}

sub removeComments {
my @lines = @_;

@cleaned = grep(!/^\s*#/, @lines); #Remove Comments
@cleaned = grep(!/^\s*$/, @cleaned); #Remove Empty lines

return @cleaned;
}

del.icio.us | Digg it | Furl | ma.gnolia | reddit | StumbleUpon |
Related Posts
# Shell Script to Backup Files Locally Using Rsync
# Perl Script to Backup MySQL Databases
# Nautilus Scripts - Terminal, File Finder

Tags Tags: , , , , ,
Categories: linux
Posted By: DteK
Last Edit: 25 Nov 2008 @ 02 19 PM

E-mailPermalinkComments (44)
 25 Nov 2008 @ 1:52 PM 

Music

There are no shortage of audio players in Linux. It has everything from command line MP3 players(mpg123) to RAM eating GUI players(like Amarok). With easily available codecs, linux supports almost all available formats.

This is the final post on a series about MP3 Players in linux. This series focuses on dedicated audio players - not video players that can handle audio as well(like mplayer). Without further ado, presenting the top 10 Linux MP3 players…

1. Amarok

Amarok Logo

amaroK is currently the player of my choice - it rocks. Everything I ever wanted in a MP3 Player and more. It is the clear winner in this field. In my opinion, there is nothing that beats amarok even if you look at Windows and Mac MP3 players as well.

Amarok Linux MP3 Player Screenshot

More Information on Amarok MP3 Player

2. XMMS

XMMS Logo

A Winamp clone. Simple and user friendly, it is very popular on linux. It does not have a large feature set - but I am going to give it second place due to its popularity.

XMMS MP3 Audio Player Screenshot

Official Sites for XMMS Player

3. RhythmBox

RhythmBox Gnome Music Player Logo

Rhythmbox Music Player is a music player and library for tagged files, that support various music formats. It was inspired by Apple’s iTunes. Although it is designed to work well under the GNOME Desktop, I had no issues with it in KDE.

RhythmBox - Gnome Music Player

RhythmBox Media Player Screenshot

Official Sites

4. Exaile

Exaile MP3 Player Logo

Exaile is a music player aiming to be similar to KDE’s Amarok, but for GTK+ and written in Python. It incorporates many of the cool things from Amarok (and other media players)

Exaile - Music Player for Gtk+

Exaile Media Player Screenshot

Official Sites

5. Audacious

Audacious Logo

Audacious is not among the ’star media-players’ in Linux - so many people never try it out. But those who have tried it out like it. For the sake of the article, I installed it - and I liked it. I even considered switching from amaroK to Audacious.

Audacious Media Player

Official Sites

6. Banshee

Banshee Music Player Logo

Banshee is an MP3 players for Gnome. You can import, organize, play, and share your music using Banshee’s simple, powerful interface.

Banshee - Music Management and Playback for GNOME

Banshee MP3 Player Screenshot

Banshee Official Sites

7. SongBird

SongBird MP3 Software Logo

SongBird is an MP3 player built on the XUL framework. It’s a desktop media player mashed-up with the Web.

SongBird - The Firefox of MP3 Players

Songbird Screenshot

Official Sites

8. Juk

Juk MultiMedia Player Logo

An audio jukebox that supports collections of MP3, Ogg Vorbis and FLAC files. It is a part of the kdemultimedia package.

Juk

9. mpg123/mpg321

mpg123 is a fast, free, minimalist, console MPEG audio player software program for UNIX and Linux operating systems.

mpg123/mpg321 - The Command Line MP3 Players

Official Sites

10. Other MP3 Players and Media Software…

Instead of putting the last MP3 Player here, I am going to list the MP3 software that did not make it to the list…

So, which is your favorite MP3 Player? Leave a comment…

Tags Tags: ,
Categories: Teknology, linux
Posted By: DteK
Last Edit: 25 Nov 2008 @ 02 05 PM

E-mailPermalinkComments (0)
 25 Nov 2008 @ 1:41 PM 

To me, a shell script is a script that automates repetitive tasks. But that is not the ‘official’ definition. Wikipedia has this definition

A shell script is a script written for the shell, or command line interpreter, of an operating system.

I use a definition that defines the purpose of the script - while the others prefer a definition that defines the technology used. I am not going to claim that my definition is better than the other definition - that’s pointless. Besides, even I think that the ‘other’ definition is the right one. But I will try to show you the advantages of my approach.

The Purpose

I like to automate things(in other words, I’m lazy). So I have a nice little collection of custom shell scripts. But there is a huge barrier to writing shell scripts - the language used. Traditionally shell scripts are written in a language provided by the shell - like bash or tcsh. That is the problem - these languages are Bad - with a capital ‘B’.

The Problem

To people who are accustomed to decent languages, these shell languages will seem clunky - or even evil. But since most shell scripts are small, most people don’t mind the torture.

In bash, the control flow commands seem to be thrown in as a after thought rather than something that’s built into the language. If you don’t believe me, compare the ‘if’ loop of bash and Perl.

Bash

This code checks wether the variable ‘$value’ has the value 0 - if so it prints the message ‘No Value’

if [ $value -eq 0 ] ; then
	echo "No Value"
fi

Perl

The same code in Perl…

if($value == 0) {
	print "No Value";
}

Of course, Perl experts will go for if(!$value) or even unless($value) - but that’s not the point. See how better the code looks in Perl. Yeah, even I am surprised to hear those words - Perl is considered by many to be an ‘ugly’ language. But when compared to shell languages, Perl is a gem(sorry about the pun - couldn’t resist).

The Solution

The solution is simple - don’t use a shell language to write your shell scripts - use a high level scripting language like Perl. Or Python, Ruby, PHP, Tcl or even JavaScript.

I still use bash to write shell scripts - but if the shell script has an if condition(other than a simple argument check), I use a higher language - usually Perl.

Advantages of using a Shell Language

  • Its supported in even the tinest linux distros - even in embedded systems.
  • Its the method preferred by the majority - I hope this will change soon.
  • Command calls look more natural in a shell language.

Advantages of using a High Level Language

  • Better Code
  • Easy to maintain
  • Faster development
  • Libraries provide a lot of functionality
  • Easier to port to different platforms.

So why am I telling you all this? Two reasons…

One, the next time you are going to write a shell script, I want you to choose a high level language rather than using bash.

The second reason is that now that my series on Linux MP3 Players are over, I am going to take a small break from desktop posts and write on more ‘linuxy’ topics. And one of those topic is Shell Scripting. So in the future posts, I am going to share some of my shell scripts with you. So when I publish a Perl script and call it a shell script, I don’t want you to get confused .

Tags Tags: , , , ,
Categories: linux
Posted By: DteK
Last Edit: 25 Nov 2008 @ 01 44 PM

E-mailPermalinkComments (42)
 25 Nov 2008 @ 1:18 PM 

All programmers have their own customized backup solutions. I have six. Yes, six! Five to backup files and one to backup database tables. And I am not counting version control or other backup systems built into the tools I use. Anyway, in the first post of the shell scripts series, let me introduce you to my Rsync based local backup solution.

Configuration File

This script reads a configuration file named ‘rsyncbackup.config’ and backups all the folders specified in that file to another location in the same system. This configuration file must be in the same folder as the perl script. The configuration file format is given below…

#Notes - do NOT include the last '/' at the end of the source folders
~/Scripts
~/Documents

#################### Web files ####################
# My Sites
#Folder to backup		#Folder to which it should be backuped to
/var/www/html/Sites		Htdocs/
/var/www/html/Projects	Htdocs/

If there is just one column in a line, that folder will be backuped to “<backup folder>/<folder name>“. Let say that my backup destination folder is ‘/var/Backup/Rsync‘. So the first line, ‘~/Scripts‘ will copy the contents of ‘~/Scripts‘ to ‘/var/Backup/Rsync/Scripts

If a line in the configuration file has two columns, then an extra folder will be created with the name provided in the second column. For example, the line ‘/var/www/html/Sites     Htdocs/‘ will create a backup of ‘/var/www/html/Sites‘ in ‘/var/Backup/Rsync/Htdocs/Sites

And if you have not guessed it already, all lines that begin in a # are comments and will be ignored.

The Script

There is the perl script that automates the rsync calls…

#!/usr/bin/perl

#EDIT THIS LINE
$backup_folder = '/var/Backup/Rsync'; #Final '/' must NOT be there.

use File::Basename;
my $config_file = dirname($0) . "/rsyncbackup.config";
my @all_locations = removeComments(getFileContents($config_file));

chdir($backup_folder) or die("Cannot go to folder '$backup_folder'");

foreach my $folder_locations (@all_locations) {
	my($folder,$backup_location) = split(/\s+/,$folder_locations);

	print "Backing up $folder to $backup_location ... ";
	`rsync -a $folder $backup_folder/$backup_location`;
	print "Done\n";
}

sub getFileContents {
	my $file = shift;
	my @lines;
	if(!open (FILE,$file)) {
		die("Can't open '$file': $!");
	} else {
		@lines=<FILE>;
		close(FILE);
	}
	return @lines;
}

sub removeComments {
	my @lines = @_;

	@cleaned = grep(!/^\s*#/, @lines); #Remove Comments
	@cleaned = grep(!/^\s*$/, @cleaned); #Remove Empty lines

	return @cleaned;
}

Execute this script using the command ‘perl RsyncBackup.pl’. In my system I have created an alias ‘bk’ for this script. I recommend that you make a similar alias if you take backups regularly(extremely recommended).

Backing up is done using rsync - so its faster than a simple ‘cp’ as only the modified and new files are copied.

Tags Tags: , ,
Categories: linux
Posted By: DteK
Last Edit: 25 Nov 2008 @ 01 48 PM

E-mailPermalinkComments (46)
 25 Nov 2008 @ 11:27 AM 

The kernel summit was two months ago, and at the end of that I got one of the new 80GB solid state disks sent to me from Intel. Since then, I’ve been wanting to talk to people about it because I’m so impressed with it, but at the same time I don’t have anyone locally who is interested enough to blabber to, so since I’m testing this whole blogging thing, I might as well vent about it here.

This drive is the absolute truth.

I’ve been impressed by Intel before (Core 2), but they’ve had their share of total mistakes and idiotic screw-ups too (Itanic), but the things Intel tends to have done well are the things where they do incremental improvements. So it’s a nice thing to be able to say that they can do new things very well too. And while I often tend to get early access to technology, seldom have I looked forward to it so much, and seldom have things lived up to my expectations so well.

In fact, I can’t recall the last time that a new tech toy I got made such a dramatic difference in performance and just plain usability of a machine of mine.

So what’s so special about that Intel SSD, you ask? Sure, it gets up to 250MB/s reads and 70MB/s writes, but fancy disk arrays can certainly do as well or better. Why am I not gushing about some nice NAS box? I didn’t even put the thing into a laptop, after all, it’s actually in a 1U Slackware server, so a RAID NAS box would certainly have been a lot bigger and probably have more features.

But no, forget about the throughput figures. Others can match - or at last come close - to the throughput, but what that Intel SSD does so well is random reads and writes. You can do small random accesses to it and still get great performance, and quite frankly, that’s the whole point of not having some stupid mechanical latencies as far as I’m concerned.

And the sad part is that other SSD’s generally absolutely suck when it comes to especially random write performance. And small random writes is what you get when you update various filesystem meta-data on any normal filesystem, so it really does matter. For example, a vendor who shall remain nameless has an SSD disk out there that they were also hawking at the Kernel Summit, and while they get fine throughput (something like 50+MB/s on big contiguous writes), they benchmark a pitiful 10 (yes, that’s ten, as in “how many fingers do you have) small random writes per second. That is slower than a rotational disk.

In contrast, the Intel SSD does about 8,500 4kB random writes per second. Yeah, that’s over eight thousand IOps on random write accesses with a relevant block size, rather than some silly and unrealistic contiguous write test. That’s what I call solid-state media.

The whole thing just rocks. Everything performs well. You can put that disk in a machine, and suddenly you almost don’t even need to care whether things were in your page cache or not. Firefox starts up pretty much as snappily in the cold-cache case as it does hot-cache. You can do package installation and big untars, and you don’t even notice it, because your desktop doesn’t get laggy or anything.

So here’s the deal: right now, don’t buy any other SSD than the Intel ones, because as far as I can tell, all the other ones are pretty much inferior to the much cheaper traditional disks, unless you never do any writes at all (and turn off ‘atime’, for that matter).

So people - ignore the manufacturer write throughput numbers. They don’t mean squat. The fact that you may be able to push 50MB/s to the SSD is meaningless if that can only happen when you do big, aligned, writes.

If anybody knows of any reasonable SSDs that work as well as Intel’s, let me know.

Tags Tags: , , ,
Categories: Hardware, Teknology
Posted By: DteK
Last Edit: 25 Nov 2008 @ 01 39 PM

E-mailPermalinkComments (44)
 25 Nov 2008 @ 10:31 AM 

You don’t know this, but your life is empty and missing something important. You need a woolly mammoth in the living room, and on a leash to take shopping. There will be a range of sizes to choose from, mammoths to order from miniatures for condos to 17 ft tall behemoths that will live on your ranch.

read more | digg story

Tags Tags: , , ,
Categories: Teknology
Posted By: DteK
Last Edit: 25 Nov 2008 @ 10 35 AM

E-mailPermalinkComments (44)
 05 Nov 2008 @ 11:34 AM 

Tags Tags: , ,
Categories: Off Beat, Politics Smolitics
Posted By: DteK
Last Edit: 05 Nov 2008 @ 11 34 AM

E-mailPermalinkComments (46)
\/ More Options ...
Change Theme...
  • Role »
  • Posts »
  • Comments »
Change Theme...
  • VoidVoid (Default)
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLightweight
  • No Child Pages...