Showing posts with label how-to. Show all posts
Showing posts with label how-to. Show all posts

Monday, March 18, 2013

Practical UNIX style backups using an ArchLinux PogoPlug

If there was ever a reason to get a $15 pogoplug hacked to run Arch Linux, this article may sway you.




I'm going to show you how I turn an ordinary $15 linux gadget into a useful "rsync" backup client.

The tasks which I will share with my readers is the typical things I would do administering *NIX based servers. We set up redundancy and failover using some simple and tried and true methods. There really is no rocket science involved. After doing it a few times, it becomes second nature. And because of the simplicity, it becomes apparent why I love small gadgets running Linux.

The articles and methods are pretty much simplified but they illustrate the simple and powerful nature of the powerful command line.

Today, I decided to turn one of my Pogos into a remote robo-copying slave. Its only job is to do remote backups of my GIT server. Then I realize, it should be running independently as a working droid (thinking Star Wars) to find,scan my network and backup any *NIX computers running in my household. I have a few spare older 250-320GB drives that needed to put to good use, so I pared them to a Pogo.

Normally, you would initiate the copy and backup from your desktop/laptop to the PogoPlug running some form of Linux/NAS. Here, I do the reverse. I have my pogoplug go out and do all the work.

So if I turn on my NetBSD G4 mac from 5 years ago, or come home with my Thinkpad, or turn on my iMac, it would automatically back them up without my intervention. I wouldn't have to think about it. If I was working on some code on my Thinkpad. I could go out to the back-yard to my patio and from my Macbook, I can pull source code that was already synced 5 minutes earlier off the Thinkpad.

Think of it as a reverse time machine. The concept is not new. We have dedicated backup servers that do nothing else but do remote backups off-site. Here, I am using a low powered PogoPlug running ArchLinux.

In fact, it took me 30 minutes to implement it. This is the power of *NIX. So I will share it with my readers today. Everything is meant to be done on the Pogo itself.

First, I logged into my Pogo and copy my SSH keys from my Pogo to all my target computers. So if I change my passwords, it would still authenticate against it. As I write this, I am thinking R2-D2 talking to the main-frame of the Death Star. If you don't know what SSH keys are, take a detour and google it before proceeding further. In short, keys allow machines to talk to one another without using passwords.

In arch, it is pretty easy.

ssh-copy-id username@remote_server

It will simply copy your keys over to the remote machine.




Next, I wrote a small bash script that pings the remote machine. If the machine pings, it means it is online and it will then attempt to rsync with it. Rsync is the tried and true industry standard for remote file synchronization/file copies.

Feel free to use this bash script. Simply, change the variable of the "remote_machine" to the IP or hostname of the computer you want it to ping and rsync. Since my network employs Avahi/Bonjour, it pretty much works by hostname. EG. My Thinkpad is accessible via ThinkpadT420.local
In this example, my remoteserver.local is my intended target.

I do a simple IF THEN conditional check in my bash script. If the machine doesn't ping, alert us with a message. Otherwise, proceed to rsync.


 #!/bin/bash  
 remote_machine="remoteserver.local"  
 PINGCOUNT=2  
 PING=$(ping -c $PINGCOUNT $remote_machine | grep received | cut -d ',' -f2 | cut -d ' ' -f2)  
 if [ $PING -eq 0 ]; then  
           echo "Something wrong! server: $remote_machine down"  
 else  
           echo "All good: $remote_machine"  
           echo "We will rsync now"  
           rsync -au --progress --stats root@remoteserver.local:/var/www/ /media/passport/rsync/vps/www/  
 fi  


My rsync command is pretty straightforward here. Archive and update. I added progress and stats for my own reference.


rsync -au --progress --stats root@remoteserver.local:/var/www/ /media/passport/rsync/vps/www/ 


Basically, my rsync logs into the remote server, copying the /var/ww/ into my destination of my 1TB Western Digital USB drive labelled, passport. The copies go into a folder, /media/passport/rsync/vps/www


After writing it, I tested it. I named my script vps_backup.sh

I then change the permissions to executable and did a dry run.



As you can see, the files and folders populate from my remote machine. The below screenshot shows two web directories. One from my iMac and another from a remote VPS.





Lastly, I would use a cron job to run every few minutes. You can even do cron job schedules in Webmin. I would recommend installing webmin so you can have a web based administratie interface of your Pogo. It simplify things quite a bit.

When you log into webmin, head over to System . Scheduled Cron Jobs.


Cron Jobs under webmin is pretty much a point and click.

I specified the user running as "root" to have full system rights and pointed to the script I wrote earlier in /root/vps_backup.sh. For this example, I specified a daily midnight schedule but I could change to hourly or every 5-10 minutes.




And there you have it. A simple (well, at least for me) way to do interval backups from a Pogo.



Wednesday, February 27, 2013

Mute/Disable Notifications in Mountain Lion OSX


One of the most annoying thing is in OSX is when you are watching a full screen movie and an email notification slides in.

Notifications, in general are great, but sometimes, you want to temporary disable them.

Easy. Click on the option key while you mouse click the right pane notification bar.




 When notifications are off, you will see a grey graph bar outline.


When notifications are on, the icon will be back to black. You can easily toggle them on-and off.




It took me a while to actually look this up. I've been dealing with notifications interrupting my VLC video watching far too long.

Saturday, December 1, 2012

OSX: Automatically Unmount Volumes on Startup Login.

Don't you hate it when you start your mac and you have a bunch of unwanted attached drives mounted on your desktop?

Specifically if you have Windows (via Bootcamp) or rarely used drives you dont want shown or accessible. It gets annoying to see those volumes mounted. For example, I don't want my wife to accidentally delete files off my Windows partition. I also have a clone drive of my system and whenever I double click on an image, Photoshop may launch from the clone drive instead of the one on  my SSD system drive. I rarely use the clone drive except to mirror my working system drive once a week.

I prefer to manually mount those drives when I need them.


Here are the 3 drives I dont like littering my desktop: System Reserved, Windows, and my clone drive. System Reserve is the small boot partition that contains files to boot Windows. Delete any of those files and Windows wont boot.

 Here is my solution I found somewhere off the net (I can't find the original link).  You can write an Applescript  to do this. Create the Applescript to unmount and load at login via the "Login Items" under "User & Groups" in the System Preference.

Here is the applescript. Modify with the volume name and save as an application.

 set volname to "System Reserved" -- # name of target volume  
 set p to (POSIX path of (volname & ":" as alias))'s text 1 thru -2  
 set sh to "diskutil umount " & quoted form of p & " &> /dev/null &"  
 do shell script sh  



Next, with the compiled Applescript(s) applications, go to User & Groups and go under Login Items and add your applescript(s).  Also, I check off "Hide" so I don't see the script executes. It will re-run if you log off into another user and re-login back into your user account. Hiding it will run it in the background so if it errors,you won't see it.

Voila. Next time you boot, those drives wont show up.






You can easily remount the drives at any given time via the Disk Utility so this isn't a permanent thing.

Now, the only thing I can think of next is to stop OSX from prompting you to initialize a disk when it can't recognize the filesystem (e.g. Linux EXT4 or Vmware VMFS).


Thursday, November 15, 2012

SSHFS on OSX. Mount SSH/SFTP shares on the Mac.

For over 10 years, I wish Apple implemented something like this:



Command-K. Connect to Sever.

Oh, I wish for the ability to natively mount SFTP/SSH shares as volumes in the operating system. You can already do it with AFP, NFS, CIF,WebDAV, and even FTP. You can do this in many Linux distributions and I actually use it quite a bit in Ubuntu. If Only OSX did this natively!

Sure, there applications like Fetch, Cyberduck, Fillezilla and YummyFTP but it is not the same as a native mounted volume.

With native mounted volumes, you can treat them in any applications including the console and you are not restricted by the limitations of a FTP client. You can open files directly without having to upload/download as you do with as standalone FTP app.

For several years, the MacFuse/MacFusion project has been on-n-off with virtually no support for Lion on.

Fuse OSX (OSXFuse) and SSHFS projects have taken up the slack. They are the successor to the abandoned MacFuse project. Link: http://osxfuse.github.com/
It may not be easy as a point-n-click nature but you can mount SSH/SFTP shares in Mountain Lion via the console. (Note: MacFusion GUI works but only with SSH keys).

1) First, install the OSXFuse/SSHFS library/app.
2) Reboot.
3) Make a mount point directory by making an empty directory. Either in the /tmp/ or /Volumes/

mkdir /path/[local_dir]/

4) Then run sshfs
sshfs user@host:/[remote_dir] /path/[local_dir] -ocache=no -onolocalcaches -ovolname=[local_dir]

You will then be prompted to enter your SSH password. You can skip passwords if you have your SSH keys set-up.

Here is an example where I make a mount a volume and call it ssh. I make the mount point in my /tmp
 mkdir /tmp/ssh  
 sshfs root@172.16.1.57:/ /tmp/ssh -ocache=no -onolocalcaches -ovolname=ssh  

Voila. The mount point is now a visibile volume I can access. It should show up on the Desktop as a network share. Here, I have full access to one of my PogoPlugs running ArchLinux


When finish, you can then umount and remove the mount point.

 umount -f /tmp/ssh
 rmdir /tmp/ssh


Now,  you don't necessarily have to make a mkdir mount point if it already exists. For example, if you make a mount point in /tmp/ like I shown above. With an existing empty mount dir, you can skip step 3 and just go straight to the sshfs command.

Your volume can be named whatever you want and you can mount it in any directory path you choose.
Call your mount point, "MyMountPoint" for all I care.

I prefer to make mounts in the /tmp or /Volumes/ paths for consistency.


There you have it. Quite simple and now you can access SSH/SFTP shares like other file sharing protocols.

Now if the new VP of OSX engineering, Craig Federighi, ever reads this blog, please implement SFTP into the command-K Finder.

Link: http://osxfuse.github.com/

Tuesday, May 29, 2012

Clonezilla


So I am getting a new computer this week. As usual, I follow a strict methodology of preparation for new equipment.

Today's post will be about CloneZilla (http://clonezilla.org/).
In short, CloneZilla is a free Linux based disaster recovery imaging system like Norton Ghost.



Whenever I get a new computer running Windows or Linux, I run clonezilla. Before even booting it, I always clone the drive into a disk image. The drive may be 750GB but the OS install and apps may only take up 20GB. Using clonezilla, I save a factory fresh, ready-to-restore image to a portable drive or to a NAS server (via SFTP). In the event I want to sell an older computer, I can restore the drive to its factory original state.

After I install my applications and set up my system, I do another clone image in case of disaster, viruses, or anything unexpected.

Clonezilla can be installed on to a bootable USB stick or CD.

Usage is very straightforward. You pick a drive or partition you want to clone. You can clone to another drive or as image files. The image files can be an external drive or to a remote server volume. The image files are chunked into small pieces so they can fit on file-systems like FAT32.

Restoring is the opposite process. It interface is old school command-line menu. There is nothing to click and it isn't pretty but it works.

Instead of a barebone Clonezilla install, I suggest PartedMagic. PartedMagic is a complete bootable Linux distro with a bunch of tools which include Clonezilla, Gparted (for redoing partitions), Trucerypt, TestDisk (for recovering files off a crashed hard drive), and a bunch of other recovery applications.

In addition to physical machines, I routinely use CloneZilla along with Gpart to upsize or enlarge Virtual Machine images. For example, if I have a 8GB VM that I want to grow to 20GB, I use Clonezilla to clone and gpart to increase the partition size. Hence, I suggest using a distro like PartedMagic.

More info on PartedMagic can be found here: http://partedmagic.com/doku.php

On the mac, there is always Carbon Cloner. Macs have the beauty using of Target Disk Mode which is where a mac can be booted into a disk drive mode that another mac can mount and use. Hence, I never had to use anything like Clonezilla for imaging on a macintosh.