<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jansipke.nl &#187; Storage</title>
	<atom:link href="http://www.jansipke.nl/category/storage/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jansipke.nl</link>
	<description>Technology Blog</description>
	<lastBuildDate>Tue, 10 Jan 2012 09:20:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Versioning of tables in MySQL</title>
		<link>http://www.jansipke.nl/versioning-of-tables-in-mysql</link>
		<comments>http://www.jansipke.nl/versioning-of-tables-in-mysql#comments</comments>
		<pubDate>Mon, 22 Nov 2010 19:36:33 +0000</pubDate>
		<dc:creator>jansipke</dc:creator>
				<category><![CDATA[Storage]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.jansipke.nl/?p=1141</guid>
		<description><![CDATA[In this article we will see how we can create tables in MySQL in such a way that several versions of the same table are stored in the database and we can choose which one we want to currently use. This may be useful in situations where we have inserted data into a table and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jansipke.nl/wp-content/uploads/mysql.png"><img class="alignnone size-full wp-image-1147" title="mysql" src="http://www.jansipke.nl/wp-content/uploads/mysql.png" alt="" width="110" height="57" /></a><br />
In this article we will see how we can create tables in MySQL in such a way that several versions of the same table are stored in the database and we can choose which one we want to currently use. This may be useful in situations where we have inserted data into a table and we want to update the table without the risk of damaging the old table while we we are inserting the new contents. Or we want to be able to easily switch back to an old version without having to re-insert this data.</p>
<p><a href="http://www.jansipke.nl/wp-content/uploads/view-tables.png"><img class="alignnone size-full wp-image-1143" title="view-tables" src="http://www.jansipke.nl/wp-content/uploads/view-tables.png" alt="" width="424" height="232" /></a>The trick we use here is to create a view that points to the current table we want to use. To be able to atomically point the view to another table, we use a stored procedure.</p>
<p>We start with the SQL code to create the stored procedure <em>createMyTable</em>. This stored procedure has one argument: the name of the table to create, e.g. <em>mytable_2010_11_22</em>.</p>
<blockquote>
<pre>DROP PROCEDURE IF EXISTS createMyTable;

DELIMITER //
CREATE PROCEDURE createMyTable(IN table_name text)
BEGIN
   SET @sql = CONCAT("CREATE TABLE ", table_name, "(", "id int,", "name text");");

   PREPARE stmt FROM @sql;
   EXECUTE stmt;

   DEALLOCATE PREPARE stmt;
END //
DELIMITER ;
</pre>
</blockquote>
<p>At this point we can create a new table and fill it:</p>
<blockquote>
<pre>CALL createMyTable("mytable_2010_11_22");
INSERT INTO mytable_2010_11_22 (id, name) VALUES (1, "Alice");
INSERT ...
</pre>
</blockquote>
<p>The second part we need is the stored procedure that changes the view to point to the newly created table. This stored procedure also has one argument: the name of the table to point to, e.g. <em>mytable_2010_11_22</em>.</p>
<blockquote>
<pre>DROP PROCEDURE IF EXISTS createMyView;

DELIMITER //
CREATE PROCEDURE createMyView(IN name text)
BEGIN
    SET @sql = CONCAT("CREATE OR REPLACE VIEW mytable AS SELECT * FROM ", name);

    PREPARE stmt FROM @sql;
    EXECUTE stmt;

    DEALLOCATE PREPARE stmt;
END //
DELIMITER ;
</pre>
</blockquote>
<p>Call this stored procedure to point to our newly created table:</p>
<blockquote><pre>
CALL createMyView("mytable_2010_11_22");
</pre>
</blockquote>
<p>Now, if we want to list the content of the table that the view currently points to, we can use something like this:</p>
<blockquote>
<pre>SELECT * FROM mytable;
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.jansipke.nl/versioning-of-tables-in-mysql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Increasing the size of an LVM volume</title>
		<link>http://www.jansipke.nl/increasing-the-size-of-an-lvm-volume</link>
		<comments>http://www.jansipke.nl/increasing-the-size-of-an-lvm-volume#comments</comments>
		<pubDate>Thu, 03 Jun 2010 14:58:27 +0000</pubDate>
		<dc:creator>jansipke</dc:creator>
				<category><![CDATA[Storage]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[LVM]]></category>
		<category><![CDATA[XenServer]]></category>

		<guid isPermaLink="false">http://www.jansipke.nl/?p=1049</guid>
		<description><![CDATA[In a previous article we looked at LVM. This short article describes how to grow an existing volume by adding an extra disk to the system. Specifically, we use a XenServer guest VM with CentOS installed. The first disk of a XenServer guest VM is called xvda, the second disk (the one we added) is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jansipke.nl/wp-content/uploads/harddisk.jpg"><img class="alignnone size-full wp-image-604" title="harddisk" src="http://www.jansipke.nl/wp-content/uploads/harddisk.jpg" alt="" width="61" height="60" /></a></p>
<p>In a <a href="/an-introduction-to-logical-volume-management-lvm">previous article</a> we looked at LVM. This short article describes how to grow an existing volume by adding an extra disk to the system. Specifically, we use a XenServer guest VM with CentOS installed.</p>
<p>The first disk of a XenServer guest VM is called <em>xvda</em>, the second disk (the one we added) is called <em>xvdb</em>. We start with the creation of a Physical Volume (PV) on the extra disk.</p>
<blockquote>
<pre>pvcreate /dev/xvdb
</pre>
</blockquote>
<p>Then we extend the existing Volume Group (VG) called VolGroup00.</p>
<blockquote>
<pre>vgextend VolGroup00 /dev/xvdb
</pre>
</blockquote>
<p>Then we extend the Logical Volume (LV) by the size of the extra disk, in this case 8GB.</p>
<blockquote>
<pre>lvextend -L8G /dev/VolGroup00/LogVol00
</pre>
</blockquote>
<p>Finally we resize the filesystem that uses this LV.</p>
<blockquote>
<pre>resize2fs /dev/VolGroup00/LogVol00
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.jansipke.nl/increasing-the-size-of-an-lvm-volume/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An introduction to Logical Volume Management (LVM)</title>
		<link>http://www.jansipke.nl/an-introduction-to-logical-volume-management-lvm</link>
		<comments>http://www.jansipke.nl/an-introduction-to-logical-volume-management-lvm#comments</comments>
		<pubDate>Fri, 26 Jun 2009 15:42:55 +0000</pubDate>
		<dc:creator>jansipke</dc:creator>
				<category><![CDATA[Storage]]></category>
		<category><![CDATA[LVM]]></category>

		<guid isPermaLink="false">http://www.jansipke.nl/?p=568</guid>
		<description><![CDATA[Logical Volume Management (LVM) is a method of allocating space on mass storage devices that is more flexible than conventional partitioning schemes. To understand how LVM works we will first take a look at some terminology: PV: Physical Volume. This can be an entire harddisk, a partition on a harddisk, a RAID device (software or [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-604" title="harddisk" src="http://www.jansipke.nl/wp-content/uploads/harddisk.jpg" alt="harddisk" width="61" height="60" /></p>
<p>Logical Volume Management (LVM) is a method of allocating space on mass storage devices that is more flexible than conventional partitioning schemes. To understand how LVM works we will first take a look at some terminology:</p>
<ul>
<li>PV: Physical Volume. This can be an entire harddisk, a partition on a harddisk, a RAID device (software or hardware), a LUN, etc.</li>
<li>VG: Volume Group. This is an aggregation of one or more PVs, summing small storage spaces into a bigger consolidated one.</li>
<li>LV: Logical Volume. This is a part of a VG that can be used to put a filesystem on.</li>
</ul>
<p>As an example of how these terms work together, have a look at the following picture:</p>
<p><img class="alignnone size-full wp-image-721" title="lvm" src="http://www.jansipke.nl/wp-content/uploads/lvm.gif" alt="lvm" width="435" height="180" /></p>
<p>Breaking things up into these parts means that we can do fun stuff with LVM. First of all, we can have a filesystem that is bigger than the biggest harddisk we have in the system. We can also grow and shrink the space that is given to a filesystem and even do this while the filesystem is being used. Finally, we can create snapshots, read-only ones for backup purposes and read-write ones that allow us to have multiple versions of a filesystem.</p>
<p><strong>Creating</strong></p>
<p>We start by creating the physical volumes (PVs). If you are using a full harddisk as a physical volume it is best to create 1 partition on it that fills the whole disk. The type of the partition can best be set to &#8220;8E&#8221;, which is the type for &#8220;Linux LVM&#8221;. You can do this by running fdisk (&#8220;n&#8221; for new partition, &#8220;t&#8221; to change the type and &#8220;w&#8221; to write changes). Afterwards run partprobe to detect the new partitions:</p>
<blockquote>
<pre>fdisk /dev/sdb
partprobe</pre>
</blockquote>
<p>Create the physical volume on the partitions. Let&#8217;s assume we have three volumes: /dev/sdb1, /dev/sdb2 and /dev/sdb3:</p>
<blockquote>
<pre>pvcreate /dev/sdb{1,2,3}
pvdisplay /dev/sdb{1,2,3}</pre>
</blockquote>
<p>Create the volume group &#8220;vg0&#8243; that will group these physical volumes together:</p>
<blockquote>
<pre>vgcreate /dev/vg0 /dev/sdb{1,2,3}
vgdisplay /dev/vg0</pre>
</blockquote>
<p>Create a logical volume named &#8220;lv0&#8243; from the volume group &#8220;vg0&#8243; with a size of 100MiB:</p>
<blockquote>
<pre>lvcreate -L 100M -n lv0 /dev/vg0
lvdisplay /dev/vg0/lv0</pre>
</blockquote>
<p>Create a filesystem on top of the logical volume &#8220;lv0&#8243; and mount it:</p>
<blockquote>
<pre>mke2fs -j /dev/vg0/lv0
mount /dev/vg0/lv0 /mnt</pre>
</blockquote>
<p><strong>Growing</strong></p>
<p>We will now grow the filesystem. This can be done when the filesystem is offline, but ext3 also supports online growing. We start by growing the space that is available to the filesystem in the logical volume &#8220;lv0&#8243;:</p>
<blockquote>
<pre>lvextend -L 120M /dev/vg0/lv0</pre>
</blockquote>
<p>Now we can ask the filesystem to occupy the extra space it has been given:</p>
<blockquote>
<pre>resize2fs /dev/vg0/lv0</pre>
</blockquote>
<p><strong>Shrinking</strong></p>
<p>Shrinking a filesystem is a bit more difficult. First we need to unmount the filesystem:</p>
<blockquote>
<pre>umount /mnt</pre>
</blockquote>
<p>Run a filesystem check and resize it:</p>
<blockquote>
<pre>e2fsck -f /dev/vg0/lv0
resize2fs /dev/vg0/lv0 80M</pre>
</blockquote>
<p>Mount the filesystem again:</p>
<blockquote>
<pre>mount /dev/vg0/lv0 /mnt</pre>
</blockquote>
<p>At this time, the filesystem is smaller than its logical volume, so we can shrink it:</p>
<blockquote>
<pre>lvreduce -L 80M /dev/vg0/lv0</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.jansipke.nl/an-introduction-to-logical-volume-management-lvm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Linux NAS setup with software RAID and incremental backup</title>
		<link>http://www.jansipke.nl/a-linux-nas-setup-with-software-raid-and-incremental-backup</link>
		<comments>http://www.jansipke.nl/a-linux-nas-setup-with-software-raid-and-incremental-backup#comments</comments>
		<pubDate>Sun, 15 Feb 2009 10:05:57 +0000</pubDate>
		<dc:creator>jansipke</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Storage]]></category>
		<category><![CDATA[NAS]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.jansipke.nl/?p=341</guid>
		<description><![CDATA[Characteristics I wanted to make my own Network Attached Storage (NAS) device with the following characteristics: It should have lots of disk space and new disk space should be easy to add. The primary storage should be redundant: if one disk fails, the data should still be there. Important data on the primary storage should [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-604" title="harddisk" src="http://www.jansipke.nl/wp-content/uploads/harddisk.jpg" alt="harddisk" width="61" height="60" /></p>
<p><strong>Characteristics</strong></p>
<p>I wanted to make my own Network Attached Storage (NAS) device with the following characteristics:</p>
<ol>
<li>It should have lots of disk space and new disk space should be easy to add.</li>
<li>The primary storage should be redundant: if one disk fails, the data should still be there.</li>
<li>Important data on the primary storage should be backed up automatically and incrementally to secondary storage.</li>
<li>It should be able to run VMware.</li>
</ol>
<p><strong>Hardware</strong></p>
<p>The following hardware was used to construct the NAS:</p>
<ul>
<li>Antec NSK4480 mini tower with 380W power supply</li>
<li>Asus M3N78-CM GeForce 8200 SATA2 mainboard</li>
<li>AMD Athlon X2 5050e 2.6GHz 1MB 45W AM2 processor</li>
<li>Scythe <span class="il">Ninja</span> Mini processor cooler</li>
<li>Kingston 2x2GB DDR2 SDRAM PC6400 memory</li>
<li>One Samsung HD501LJ 500GB disk</li>
<li>Three Western Digital <span class="menusubblck">WD10EACS 1TB disks<br />
</span></li>
<li>Samsung SH-S223F DVD player</li>
</ul>
<p><img class="alignnone size-full wp-image-714" title="nas-antec-nsk4480" src="http://www.jansipke.nl/wp-content/uploads/nas-antec-nsk4480.jpg" alt="nas-antec-nsk4480" width="80" height="80" /><img class="alignnone size-full wp-image-715" title="nas-asus-m3n78-cm" src="http://www.jansipke.nl/wp-content/uploads/nas-asus-m3n78-cm.jpg" alt="nas-asus-m3n78-cm" width="80" height="80" /><img class="alignnone size-full wp-image-716" title="nas-amd-athlon-x2-5050e" src="http://www.jansipke.nl/wp-content/uploads/nas-amd-athlon-x2-5050e.jpg" alt="nas-amd-athlon-x2-5050e" width="87" height="80" /><img class="alignnone size-full wp-image-717" title="nas-scythe-ninja-mini" src="http://www.jansipke.nl/wp-content/uploads/nas-scythe-ninja-mini.jpg" alt="nas-scythe-ninja-mini" width="80" height="80" /><img class="alignnone size-full wp-image-718" title="nas-westerndigital-wd10eacs" src="http://www.jansipke.nl/wp-content/uploads/nas-westerndigital-wd10eacs.jpg" alt="nas-westerndigital-wd10eacs" width="86" height="80" /><img class="alignnone size-full wp-image-719" title="nas-samsung-sh-s223f" src="http://www.jansipke.nl/wp-content/uploads/nas-samsung-sh-s223f.jpg" alt="nas-samsung-sh-s223f" width="116" height="80" /></p>
<p>The 500GB disk will be used to hold the operating system, Ubuntu 8.10 desktop, and the backup of the most important files. The three 1TB disks will be bundled together into a software RAID5 set, as shown in the following diagram:</p>
<p><img class="alignnone size-full wp-image-623" title="nas-disks" src="http://www.jansipke.nl/wp-content/uploads/nas-disks.gif" alt="nas-disks" width="330" height="128" /></p>
<p><strong>Software RAID</strong></p>
<p>We start by installing the operating system, Ubuntu 8.10 desktop for i386 systems. I choose the desktop version because I wanted to be able to access the VMware GUI on the NAS itself. I started with the 64 bit version of Ubuntu 8.10, but it was harder to install and it seemed slower than the i386 version. It does mean that we loose some of the 4GB RAM, but that is not a big concern for me.</p>
<p>After installing the OS, we move on to the partitioning of the three disks that will form the RAID5 set. We do this by installing the program gparted which is ideal for partitioning disks from a GUI:</p>
<blockquote>
<pre>sudo su -
apt-get install gparted
gparted</pre>
</blockquote>
<p>In gparted, create a single partition on the three RAID5 disks.<br />
Next, create the RAID5 set:</p>
<blockquote>
<pre>apt-get install mdadm
mdadm --create /dev/md0 --level=5 --chunk=128 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1</pre>
</blockquote>
<p>Create a filesystem on the RAID5 set we just created:</p>
<blockquote>
<pre>mkfs.ext3 -b 4096 -R stride=32 /dev/md0</pre>
</blockquote>
<p>Create a mountpoint for the RAID5 set:</p>
<blockquote>
<pre>mkdir /data</pre>
</blockquote>
<p>Add an fstab entry by editing /etc/fstab:</p>
<blockquote>
<pre>/dev/md0   /data   /ext3   defaults   0   0</pre>
</blockquote>
<p>Finally, mount the RAID5 set:</p>
<blockquote>
<pre>mount /data</pre>
</blockquote>
<p><strong>Incremental backup</strong></p>
<p>The most important files on the NAS need to be backed up to the disk that also holds the operating system. The program rshapsnot is ideal for this task. It will do fast incremental backups that are browsable on the filesystem. So there&#8217;s no need to use a special program to restore the backup. Just copy the files and you&#8217;re done.</p>
<p>Install rsnapshot:</p>
<blockquote>
<pre>apt-get install rsnapshot</pre>
</blockquote>
<p>Edit the rsnapshot configuration file /etc/rsnapshot.conf:</p>
<blockquote>
<pre>snapshot_root /backup/
cmd_cp /bin/cp
cmd_ssh /usr/bin/ssh
cmd_du /usr/bin/du
cmd_rsnapshot_diff /usr/bin/rsnapshot-diff
interval hourly 6
interval daily 7
interval weekly 4
interval monthly 12
backup /data/important_files/ localhost/</pre>
</blockquote>
<p>This configuration file tells rsnapshot some basic things like the whereabouts of some needed programs and which directories it should backup. In our case, the directory /data/important_files is backed up to the directory /backup. It also tells that there should be 6 &#8220;hourly backups&#8221;, 7 &#8220;daily backups&#8221;, 4 &#8220;weekly backups&#8221; and 12 &#8220;monthly backups&#8221;. The reason I use quotation marks here, is that you yourself have to setup the cron jobs to actually run rsnapshot at the time you want. Run the following command:</p>
<blockquote>
<pre>crontab -e</pre>
</blockquote>
<p>and add the following lines:</p>
<blockquote>
<pre># m h  dom mon dow   command
0 */4 * * * /usr/bin/rsnapshot hourly
45 23 * * * /usr/bin/rsnapshot daily
30 23 * * 0 /usr/bin/rsnapshot weekly
15 23 1 * * /usr/bin/rsnapshot monthly</pre>
</blockquote>
<p>This crontab will run the different backups in the following way:</p>
<ul>
<li> The &#8220;hourly backup&#8221; is run every four hours (denoted by the hour value of */4) on the hour (denoted by the minute value of 0).</li>
<li>Every day at 23:45, the &#8220;daily backup&#8221; is run.</li>
<li>Every sunday (denoted by the day-of-the-week value of 0) at 23:30 the &#8220;weekly backup&#8221; is run.</li>
<li>Every first day of the month (denoted by the day-of-the-month value of 1) at 23:15 the &#8220;monthly backup&#8221; is run.</li>
</ul>
<p>In combination with the &#8220;interval hourly 6&#8243; line in the rsnapshot configuration file, this means that the last 24 hours are covered with 6 backups. In the same way we can see that 7 days are covered in the last week, 4 weeks are covered in the last month and 12 months are covered in the last year.</p>
<p><strong>File sharing</strong></p>
<p>To actually start using the NAS, we will now install the Samba package:</p>
<blockquote>
<pre>apt-get install samba</pre>
</blockquote>
<p>Finally, we edit the configuration file /etc/samba/smb.conf:</p>
<blockquote>
<pre>security = user
[data]
   comment = Data
   browseable = yes
   path = /data
   guest ok = no
   read only = no
[backup]
   comment = Backup
   browseable = yes
   path = /backup
   guest ok = no
   read only = yes</pre>
</blockquote>
<p>This will make the primary storage accessible read-write through \nasdata and the backup accessible read-only through \nasbackup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jansipke.nl/a-linux-nas-setup-with-software-raid-and-incremental-backup/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

