Backup Directories and Subdirectories Preserving File Structure

I needed a quick way to backup my small music collection on my laptop and preserve the complete file structure and permissions.  There are a few ways to do this of course…for example, you can just copy the files using whatever file manager you happen to be using in your Linux distribution.  In some cases though, you might want your backup to take up less space than the full monty.  Especially true if you are backing up to thumb drives!

You can use the tar command to make this a snap.

Tar combines multiple files into an archive and you can use it to preserve permissions and file structure and then you can compress the archive to save space.

tar -c --recursion -p --file=backup.tar directory

The -c flag creates an archive for us.  –recursion goes through all subdirectories.  The -p flag preserves permissions on all the files.  This is handy if you have certain folders or files that you need to sticky with individual users or groups.  The –file flag is the option for outputting to a file name.  You can also add multiple directories that you’re zipping up like the following:

tar -c --recursion -p --file=backup.tar directory1 directory2 directory3

After you have the file output as backup.tar it’s time to compress it.  The most standard way to do this is to use the gzip command:

gzip backup.tar

This command will output backup.tar.gz to the current directory which will take up less space than that of a standard 1-to-1 copy.  There are many other flags and options that you can use with the tar command.  For an in depth look at those flags and options, check the tar man page by typing ‘man tar’ in a terminal or view it online here.

UPDATE:

Commenter ‘jack’ has offered a few extra flags to combine the archiving and zipping into one command:

tar -c -z --recursion -p --file=backup.tar directory1 directory2 directory3

The -z flag will gzip the archive after you’ve used tar to create it.  Substituting -j in for -z above will bzip the archive.  Thanks for the tips jack!

Host Your Own Domain, Website and Webserver

This post was originally published on 13 July, 2006.  This version has been updated.

I have a problem with facebook, myspace, and other social networking websites out there.  The problem is when I upload my data to their webservers….I don’t own it anymore.  They do.  And they can do whatever they want with it once it is there.

With this in mind, I’d rather setup my own twitter using Status.net or my own digg using Pligg.  But I’d do it on MY OWN SERVER.  That way, any content I upload is MINE.  It doesn’t reside on some server in California or DC and get recycled to advertisements.

I like to control my own stuff.  I don’t like to be cut out of the loop.  If you’re like me, then you’ll want to host your own domain, website and webserver so that your friends/family/shrink can quickly and easily connect up to see new photos, find out the latest family developments, and understand why you wear tinfoil hats every Thursday after 4pm.

Normally, to host your own webpage you would need to spend around 7 bucks to purchase a domain.  Next you would need a hosting plan that usually runs around 3-15 dollars per month to serve up your web pages.

What most don’t realize is that you can skip these steps all together…you don’t need to get dedicated hosting (this blog is hosted on dedicated hosting…but started out in my apartment!) to serve pages up to your friends and family.  You absolutely do not need to get domain name services through a provider.  You can even host your own webserver using a dialup connection (that’s right…I said dialup) although. I don’t recommend it (but I’ve done it using 56.6kbps).

Why would you want to do this?  The answer might be to stay connected to friends and family…perhaps install a gallery so that your grandparents can see pics of your new dog/car/tinfoil hat.  Sure, you could waste my time with MyWaste..er..space and facebook and be barraged daily by advertisers and solicitors and be inundated with the minutiae of what all your friends had to eat for the day …or you could roll your own web host, install a gallery or website, and provide media to your friends and family without costing yourself a dime.  That’s right, NO COST (except time spent getting it running).  Just remember, your website might not survive a digging or slashdotting if you run it yourself.  Keep that in mind 🙂  So without more chatter, let’s get to the meat and potatoes of things:

Meat and Potatoes

If you have Cable or DSL at home (not a business account) you have something called a dynamic connection.  Dynamic connection means that it can change every once in a while.  DSL and cable ISP’s purchase blocks of IP Addresses in the dynamic range so that they can keep consumers separate from businesses.  It’s also easier for them to manage dynamic pools of people than to have to remember static connections that don’t change for everyone.

Because of this problem…an ever changing connection for you at home…web servers and websites do not do very well.  The reason for this is because when you visit a website on a dynamic connection one day, it might be different the next day.  In order for visitors of a website to find you each and every single time, you need a “domain” or web name that points back to the address (IP Address) your internet service provider changes on a whim.  You’ll also need an update service to update your website each time your ISP decides to change things on you.

Believe it or not, there are free services out there to do that for you.  You just have to be willing to do a little extra work in the beginning to set things up.  You can also do this without spending 20-40 bucks a month on DNS service.

I’ll divide this up into 2 sections.  The first will deal with Linux hosting.  The second, Windows hosting.  This is only something that I’ve found easy to do and the price is just right (it’s free).  The only thing that I recommend is a dedicated internet connection (cable, DSL) but even this is not necessary as dialup can be used.  I recommend that you use the Linux way of doing things since it is more secure and doesn’t require a restart every time you patch it.

*note: I’m assuming that you aren’t behind a firewall/proxy of any kind and that your ISP doesn’t block port 80 traffic.  If your ISP blocks port 80, see the appendix at the end of this article.

LINUX

No matter what version of Linux you run, chances are that you’ll be able to install the apache webserver.  This is good news as over half the websites of the world are run by apache. I’m not going to address the specifics of how to set up your apache…only how to get it a fixed address without buying a domain.  So, you have your html or php pages located into your webservers public directory…good…whatever application you have is installed on your server.  Now, how to resolve your IP…lets say it is…25.24.4.166 (for our example) and you want it to have a host.name.com to bind to.  Easy to resolve.  Go to http://www.no-ip.com/index.php and sign up.  You can get a site from noip that is like yourname.theirdomain.com/.net/.info.  They have cool names like sytes.net and servebeer.org…even workisboring.com.  Other services like dyndns.org also exist and provide the free service as well.

You’ll be able to choose your own top level name…for instance, Ithink.dnsiskinky.com could be your new domain name.  Next download a client from the download tab: https://www.no-ip.com/downloads.php

The linux client is a tar.gz source and is simple to install. Follow the instructions when installing.  You may have to install compilation tools (devel packages like GCC) to install the client.  You now are the proud owner of yoursite.theirsite.com and your IP will ALWAYS update (as long as noip.com is up) each time you log on/sign on/beam up or whatever it is you do.

How does this help you?  Well, if you’re like me, you have a dynamic IP address.  If you connect to the internet via cable, dialup, or dsl…you also have a dynamic IP address.  Dynamic means that it will change from time to time without warning.  So by binding yoursite.theirsite.com to your IP address…you don’t ever have to worry about what IP address you have anymore.  Instead, you’ll always be able to connect using yoursite.theirsite.com.  You can host a webserver using Apache and a virtual host in this style as well (look for another how-to on this subject later) so that everyone can visit a shiny website at yoursite.theirsite.com.

Now you can give your friends/family/dog walker/mailman the address to your new webserver…maybe it’s Ithink.dnsiskinky.com like we used in the example above.  Now when they visit that address in their web browser, your application or web page displays for them.  You also get bragging rights at being the most technical friend/relative/dog walker client/household that everyone knows.  Now let’s cover Windows.

WINDOWS

First you need a free and clear webserver since one is not included by default with windows. You can download Apache for this as well OR try the Abyss Webserver.

Interestingly enough, Abyss is also free!  I ran it while my linux machine was being worked on (bad hard disk…it was a Quantum 200MB drive from 1913…had to upgrade) and it worked just great off of Windows XP.  Download that puppy and install it.  Make sure you read all of the documentation and familiarize yourself with how Abyss does business.

The next step…getting a hostname… is even easier than the linux method because you don’t have to manually install the noip client…they have a windows installer.  Go to http://www.no-ip.com/index.php and sign up.  Choose the domain name you would like (see above examples in Linux section).  Next, download the noip client from the download tab: https://www.no-ip.com/downloads.php but this time choose the windows client.  From there, you’ll be able to install this with a simple double click.  Fill in all of your information (pretty self explanatory) and make sure that it will run with each time you sign on.  You’re set! Your IP will now resolve to the yourchoice.theirhostname.com

CONCLUSION

You don’t have to spend a dime to keep a domain bound to your IP.  This is perfect for the home user who just wants a gallery or homepage.  It’s even good for someone who has a weblog or enthusiast site.  It’s good for someone who wants to be able to find their files and music…setup Jinzora and stream all your music library to yourself anywhere you are!  Setup Amahi and have access to all the goodness it brings.

Please remember, this wouldn’t be good for a business to have.  You will probably violate your ISP’s terms and conditions for using their connection if you tried to run a business this way.

It’s always good form to put a link of the stuff you are using on your website to direct traffic back to your software provider.  When I used noip, I included a noip link on my main page and also an abyss webserver icon as well.  It’s just good form and some companies/software providers necessitate the use of their logo or a link on sites that use their software/code.  Just be a nice person and give a link back to them.  Good luck! Have fun!

Also, please note that having hosted my own webserver for quite some time (circa 2001) I’ve found Linux and Apache as a combination to be more secure, faster, and more stable than any webserver I’ve hosted on the Windows Platform. I included information on Windows mainly to introduce you to the concept of free and open source software. If you thought getting a webserver for free was great, think about getting a whole operating system! Give it a try, you don’t even have to install it (use a Live CD).

APPENDIX

If your ISP blocks port 80 traffic, your webserver won’t work.  Before deciding that your ISP is blocking however, make sure your firewall has the appropriate rules to allow incoming traffic.  You can do a quick add to IPTABLES in the following manner:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -j DROP

If you’ve opened up the appropriate ports and things still don’t work, it will be safe to say that you’ve determined the ISP is blocking port 80.  How you can get around this conundrum is to switch the listening port on the webserver to a different one and redirect traffic there.

  1. See how to do this for IIS Webservers
  2. See how to do this for Apache Webservers (normally in /etc/apache2/httpd.conf but your distro may vary.)
  3. See how to do this for Abyss Webservers

If you still have problems, drop me a line in the comments section.  I may not be able to answer all questions but I can most likely get you to a person/place/thing that can.  Have fun and thanks for reading!

Convert PNG to GIF via Command Line

I installed a bare bones Arch Linux system today and took a screenshot.  With no graphics utilities installed, I needed a way to convert a PNG to a GIF for a Simple Machines forum template thumbnail.  I figured I’d use a command line utility to help me and ImageMagick is installed by default on most distributions.  A quick read through the ImageMagick manpage and I found the convert command and thought I’d share it with everyone.  Use convert in the following fashion:  convert [input-options] input-file [output-options] output-file

convert SMFPress.png -channel Alpha -threshold 80% -resize 120x120 thumbnail.gif

This did a quick, same-size conversion with little loss for me to display the thumbnail online.  For more information on the options I used and other options that I didn’t use, take a peek at the ImageMagick Online Help Page for convert.

Adding Color to Bash List Command Part II

I previously blogged about how to add color to the ‘ls’ command utilizing an config file and alias.  I then stumbled across a nugget of wisdom from a Foresight Linux user on the developers mailing list who gave a handy command that remedies some problems with missing color in a terminal.

On some distributions, the system-wide /etc/DIR_COLORS* files are removed or not present.  This results in no colors being given inside of a terminal when looking for color directories and filenames.  If you find yourself in this boat, try the following command to re-populate this setting:

devnet-> cd ~/
devnet-> dircolors -p >.dircolors

This should create a default profile for colors for your session if it hasn’t been done or was accidentally removed.  For more information on the dircolors command try ‘man dircolors’.  Please also note that dircolors command uses the environmental variable LS_COLORS to set your session.

For more information on LS_COLORS and how it pertains to the terminal/shell/cli/prompt, there are a few blog posts that do an excellent job explaining here, here and here.

Adding Color to Bash List Command

One of the things I love is being able to enter into a directory via terminal, list the contents, and quickly see which ones are executable or not and which ones are directories or are not directories IN COLOR (not everyone is perfect right?).  This is specifically handy as I move through working with Slackware based distributions like the one I’m using now, Zenwalk Linux 6 and the /etc/rc.d/ directory.  Most of the Red Hat based distributions out there that I’ve used have this set automatically…so I’m used to it.  When I opened up a terminal in Zenwalk I found no color. A quick investigation of ~/.bashrc showed me that there are aliases set to display color…instead of ls I’d just use the letter L; 2 l’s for another option, 3 for another.  It’s interesting, but not normally how I do business.  See bashrc below:

devnet[~]$ cat ~/.bashrc
alias lll="ls -al --color"
alias ll="ls -l --color"
alias l='ls --color'<br />alias search='find . -name'
alias aterm="aterm -fg white -tr"
alias version='cat /etc/zenwalk-version'
alias dh='df -h'<br />export PS1='\u[\W]\$ '
export PAGER="most"<br />devnet[~]$

I don’t use those aliases much…others of you might do the ‘ll’ or ‘lll’ but it’s just not part of my routine.  So, I added in just after line 4 in the code above:

alias ls='ls --color'

You can do this a few different ways…with any command line editor like emacs, vi, or nano/pico. It’s really up to you. The easiest way for new users is to use a text editor:

devnet[~]$ mousepad ~/.bashrc

This will launch the mousepad text editor in XFCE. If you’re in Gnome, try gedit. If KDE, give kwrite a try. You should see something like the following window pop up for editing:

bashrcYou should see in the picture above, I’ve added in the alias needed to make me comfortable.  After that, File >> Save.  You’re set!  Except, you may notice that when you type the command ‘ls’ there are no colors.  So what gives?  Well, we haven’t loaded our ./bashrc since we changed it.  You don’t have to logout and back in to get things to work though…you can do this right from the terminal:

devnet[~]$ exec bash

Now try giving the ‘ls’ command a try again and you should see that it is in color.  I know a lot of the more advanced Linux guys out there are probably saying, “why’d he waste a post on this!  It’s easy” and you’d be right for a majority of users out there…I hope that this post finds some new user out there that may be stuck for an answer on how to do this.  One final note on this as well: You will have to do this as the root user and change /root/.bashrc in order for your root user to also have color.  Thanks for reading!

Laptop Multimedia Keys and PCLinuxOS 2009

I installed PCLinuxOS 2009 recently on a Dell D630 Latitude and was disappointed to see that I couldn’t get the hardware volume (up/down/mute) buttons didn’t work out of the box.  I thought a bit about kmilo, a program that was previously used for laptop buttons (thinkpad buttons though) and I searched around a bit inside the KDE Control Center for keyboard shortcuts to see if I could assign the keys manually.  However, I couldn’t find any volume setting inside this menu.

Then, it hit me, I had remembered seeing volume settings before…inside kmix; there is an area for assigning global shortcuts for volume and mute!  This should work for anyone running KDE 3.5.8 and above (I think).  Left click on Kmix in your tray and choose the mixer button.  From there, choose Settings >> Configure Global Shortcuts.  Now assign the volume up, down, and mute keys manually by clicking in the blank and pressing the hardware button.  This should work for a majority of people out there.  For me though, this didn’t work.  When pressing the keys, nothing happened.  I thought I was doomed.

I researched a bit more and found that installing a program called keytouch would allow me to, at the very least, program my keyboard in any way I wanted to program it.  I opened Synaptic and installed keytouch and keytouch-editor.  After install, I went to Kmenu >> System >> Configuration >> Hardware >> Keytouch.  It prompted me to choose my keyboard.  Since it didn’t have the Dell D630, I chose the closest thing which was the Dell D800.  I closed the application and now the volume buttons and mute button works!  Keytouch also has the ability to manually edit and also to import keytouch ‘schemas’ to give maximum flexibility.  Hopefully, this helps some of you out there that cannot get your multimedia keys working in PCLinuxOS and KDE to work!

Creative Commons License
Except where otherwise noted, the content on this site is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.