Tuesday, July 10, 2012

Tag: ubuntu


Tag: ubuntu

About

Ubuntu (IPA pronunciation /ùbúntú/) is a predominantly desktop-oriented Linux distribution, based on Debian GNU/Linux but with a stronger focus on usability, regular releases, and ease of installation. Ubuntu is sponsored by Canonical Ltd, owned by South African Mark Shuttleworth; the name of the distribution comes from the African concept of ubuntu which may be rendered roughly as "humanity toward others", though other meanings have been suggested.

The most recent version, Ubuntu 7.04 (Feisty Fawn), was released on April 19, 2007. Version 7.10 (Gutsy Gibbon) is scheduled for release on October 18, 2007. Ubuntu aims to use only free software to provide an up-to-date yet stable operating system for the average user.

Kubuntu and Xubuntu are official subprojects of the Ubuntu project, aiming to bring the KDE and Xfce desktop environments to the Ubuntu core, respectively. Edubuntu is an official subproject "designed for school environments, and should be equally suitable for kids to use at home."


Tag: linux


Tag: linux

About

Linux (IPA pronunciation: /ˈlɪnʊks/) is a Unix-like computer operating system. Linux is one of the most prominent examples of free software and open source development; its underlying source code can be freely modified, used, and redistributed by anyone.

The Linux kernel was first released to the public on 17 September 1991, for the Intel x86 PC architecture. The kernel was augmented with system utilities and libraries from the GNU project to create a usable operating system, which later led to the alternate term GNU/Linux. Linux is now packaged for different uses in Linux distributions, which contain the sometimes modified kernel along with a variety of other software packages tailored to different requirements.

Predominantly known for its use in servers, Linux has gained the support of corporations such as IBM, Sun Microsystems, Dell, Hewlett-Packard, and Novell, and is used as an operating system for a wide variety of computer hardware, including desktop computers, supercomputers, and embedded devices such as mobile phones and routers.

Tag: rsync


Tag: rsync

About

In computing, rsync is a computer program for Unix systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction. rsync can copy or display directory contents and copy files, optionally using compression and recursion.

rsyncd, the rsync protocol daemon, uses the default TCP port of 873. rsync can also be used to synchronize local directories, or via a remote shell such as RSH or SSH. In the latter case, the rsync client executable must be installed on both the local and the remote host.

Released under the GNU General Public License, rsync is free software.

Synchronizing files from one server to another is quite awesome. You can use it for backups, for keeping web servers in sync, and much more. It's fast and it doesn't take up as much bandwidth as normal copying would. And the best thing is, it can be done with only 1 command. Welcome to the wonderful world of rsync.

Tag: backup


Tag: backup

About

In information technology, backup refers to making copies of data so that these additional copies may be used to restore the original after a data loss event. These additional copies are typically called "backups." Backups are useful primarily for two purposes: 1) to restore a computer to an operational state following a disaster (called disaster recovery) and 2) to restore small numbers of files after they have been accidentally deleted or corrupted.

Due to a considerable overlap in technology, backups and backup systems are frequently confused with archives and fault-tolerant systems. Backups differ from archives in the sense that archives are the primary copy of data and backups are a secondary copy of data. Backup systems differ from fault-tolerant systems in the sense that backup systems assume that a fault will cause a data loss event and fault-tolerant systems assume a fault will not. Backups are typically that last line of defense against data loss, and consequently the least granular and the least convenient to use.

Since a backup system contains at least one copy of all data worth saving, the data storage requirements are considerable. Organizing this storage space and managing the backup process is a complicated undertaking.

Tag:synchronization


Tag:synchronization

About

In computer science, synchronization refers to one of two distinct, but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, so as to reach an agreement or commit to a certain sequence of action. Data synchronization refers to the idea of keeping multiple copies of a dataset in coherence with one another, or to maintain data integrity. Process synchronization primitives are commonly used to implement data synchronization.
Synchronizing files from one server to another is quite awesome. You can use it for backups, for keeping web servers in sync, and much more. It's fast and it doesn't take up as much bandwidth as normal copying would. And the best thing is, it can be done with only 1 command. Welcome to the wonderful world of rsync.

Synchronize files with rsync


Synchronize files with rsync

Synchronizing files from one server to another is quite awesome. You can use it for backups, for keeping web servers in sync, and much more. It's fast and it doesn't take up as much bandwidth as normal copying would. And the best thing is, it can be done with only 1 command. Welcome to the wonderful world of rsync.

Installing rsync

On most modern Linux distributions you will find rsync comes preinstalled. If that's not the case, just install it with your package manager. On Ubuntu this would look like:
aptitude -y install rsync
done!
Simple - one command
Let's copy our local /home/kevin/source to /home/kevin/destination which resides on the server:server.example.com:
rsync -az --progress --size-only /home/kevin/source/* server.example.com:/home/kevin/destination/
explained:
  • -r
    recursive
  • a
    archive, preserves all attributes like ownership, timestamps, etc
  • z
    compress, saves bandwidth but is harder on your CPU so use it for slow/expensive connections only
  • --progress
    shows you the progress of all the files that are being synced
  • --size-only
    compare files based on their size instead of hashes (less CPU, so faster)

Well, that's it! But read on if you want to learn how to automate this!

Advanced - automatic syncing with SSH keys

Alright so syncing files on Linux is pretty easy. But what if we want to automate this? How can we avoid that rsync asks for a password every time?
There are different ways to go about this, but the one I mostly use is installing SSH keys. By installing your SSH key on the destination server, it will recognize you in the future and permit instant access. So this way we can automate the synchronization with rsync.

Easy script

I've written another article explaining on setting up SSH keys. It also includes a script that can do all the work for you.

Did it work?

Open a terminal and type:
ssh server.example.com
It should not ask you for any password. Great! this means we can also run rsync directly without logging in! If you need more in depth information on this, I wrote an article on logging in automatically with SSH keys.

Let's create a sync script

So now just create a script /root/bin/syncdata.bash
nano /root/bin/syncdata.bash
that contains your rsync command:
#!/bin/bash
rsync -az --delete /home/kevin/source/* server.example.com:/home/kevin/destination/
Save the file (CTRL+O) and exit (CTRL+X) and make it executable like this:
chmod a+x /root/bin/syncdata.bash

Schedule it to run every hour

And to have your data synchronized every hour, open up your crontab editor:
crontab -e
And type
0 * * * * /root/bin/syncdata.bash
(if you need more in depth information on crontab I've written another article on scheduling tasks on linux using crontab)
That's it! New files are automatically updated @ server.example.com:/home/kevin/destination/ every hour. Files that are deleted from /home/kevin/source/ are also deleted at the destination, thanks to the --deleteparameter. 

Some extra rsync command line options

Some extra arguments that might come in handy customizing your synchronization job:
  • --delete delete files remotely that no longer exist locally
  • --dry-runshow what would have been transferred, but do not transfer anything
  • --max-delete=10don't delete more than 10 files in one run, safety precaution
  • --delay-updates put all updated files into place at transfer's end, very useful for live systems
  • --compress-level=9 explicitly set compression level 9. 0 disabled compression
  • --exclude-from=/root/sync_exclude specifies a /root/sync_exclude that contains exclude patterns (one per line). filenames matching these patterns will not be tranfered
  • --bwlimit=1024This option specifies a maximum transfer rate of 1024 kilobytes per second.

Pitfalls

  • Of course you should really be carefull where and when to install ssh keys, because if one machine is comprimised, it's very easy for a cracker to hop to the next system without logging in. So choose wisely when to use this technology.
  • Keys are user user specific. So if you're going to run programs as root that need to automatically login to systems, you must also install the key as root.

Tuesday, June 12, 2012

How to get readonly textbox value in codebehind or CS file

As we know that when we declare a textbox as readonly then we didnot get value from that readonly textbox from code file. Because asp.net rejects any changes in readonly textbox after postback. Here in this article i will describe ASP.NET Read Only TextBox lose client side changes, values across post back? Why Readonly Text box values are empty in code behind ? Issue in Retrieving textbox value when readonly = true in codebehind.? The real thing is when you declare a textbox as readonly in design mode and assign a value using a javascript function then from code file you did not get the value in server side. Its a bug.Its a problem for developers. There is a workaround on this issue which i will share with you. The solution is simple.

Solution:
1. Dont assign readonly property=true in design mode.
2. Bind the readonly property from serverside page load event like:


1if (!IsPostBack)
2            txt_ReadOnly.Attributes.Add("readonly", "readonly");
Hope now your problem has been resolved.


Ok now i am going to create an example. In this example first take a textbox in your page with readonly=true. like:
1<asp:TextBox runat="server" ID="txt_ReadOnly" ReadOnly="true"></asp:TextBox>
Then add two button. One is to set some value into the readonly textbox using javascript. And another button will try to read the readonly textbox value that i have set before. Look at this moment you would not get the value & the readonly textbox will loose the value after second button postback. Now remove the readonly property from design page. So now your complete HTML markup will look like:


01<%@ Page Language="C#" AutoEventWireup="true" CodeFile="readonly_textbox.aspx.cs" Inherits="readonly_textbox" %>
02
03<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04
05<html xmlns="http://www.w3.org/1999/xhtml" >
06<head runat="server">
07    <title>Read readonly textbox value in code file</title>
08    <script type="text/javascript">
09    function setValue()
10    {
11        document.getElementById('<%= txt_ReadOnly.ClientID %>').value="Hello World!";
12        return false;
13    }
14    </script>
15</head>
16<body>
17    <form id="form1" runat="server">
18    <div>
19    <asp:TextBox runat="server" ID="txt_ReadOnly" ReadOnly="true"></asp:TextBox>
20     
21
22     
23
24    <asp:Button runat="server" ID="cmdSet" Text="Set value in readonly textbox"OnClientClick="return setValue();" />
25    <asp:Button runat="server" ID="cmdGetValue" Text="Get value from readonly textbox"OnClick="cmdGetValue_Click" />
26    </div>
27    </form>
28</body>
29</html>
Here you found that under first button i have assigned a javascript function to write something in the readonly textbox. Now under second button just write the readonly textbox value into the form. Also do not forget add the readonly attribute under page_load event like below. So your server side code will look like:
01using System;
02using System.Data;
03using System.Configuration;
04using System.Collections;
05using System.Web;
06using System.Web.Security;
07using System.Web.UI;
08using System.Web.UI.WebControls;
09using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class readonly_textbox : System.Web.UI.Page
13{
14    protected void Page_Load(object sender, EventArgs e)
15    {
16        if (!IsPostBack)
17            txt_ReadOnly.Attributes.Add("readonly", "readonly");
18    }
19    protected void cmdGetValue_Click(object sender, EventArgs e)
20    {
21        Response.Write(txt_ReadOnly.Text);
22    }
23}
The output will look like:
Readonly textbox problem
So now hope you understand what is the problem & how we can resolve it.