Using rdiff-backup/rsync with your LinkStation Pro Duo

I wanted to use rdiff-backup with my LinkStation Pro Duo as it makes incremental backups and the retrieving of backups just dead easy. Unfortunately, its a pain in the *** to install rdiff-backup on the LinkStation Pro Duo. So I wrote a work-around.

Note: This only works if you are using a public/private key for authentication via SSH and on a user by user basis. To do this read my post titled, LinkStation Pro Duo, enabling SSH.

To get this to work from a Client machine that runs Linux, you need to install “sshfs”. In short, this allows you to mount a drive/share on your LinkStation Pro Duo onto your client machine. This in turn gives you the opportunity to run rdiff-backup locally which DOES NOT require rdiff-backup –server to be installed on the LinkStation.

Once you have sshfs installed, you will need to create a startup script for your username. Now this will vary depending on the distribution you use, but if you use Ubuntu or one of its derivatives, you can do the following:

  1. Setup Directory for Mount Detection
    We need a directory setup on the NAS so that we can tell if the share has already been mounted. This is needed because every time you login via SSH, it will try to mount this drive, and if you are like me and you run your PC 24/7, this could be a problem.

    1. Remote into your NAS via SSH, using ssh <username>@<nas_ip_address>
    2. Create a directory on your NAS that you will put in as the CHECK_FOLDER value in the below script by running
      mkdir <path_to_your_new_folder>
  2. Create a .bash_login script

    1. Open your favorite editor (gui, graphical user interface or cli, command line is fine), name it “.bash_login”
    2. Copy the following into the file:
      #!/bin/bash

      CHECK_FOLDER=/mnt/nas-backup/
      REMOTE_FOLDER=<username>@<nas_ip_address>:/mnt/array1/Backup
      LOCAL_FOLDER=/mnt/nas-backup

      # Check if the NAS Backup Share has been Mounted, if it hasn't mount it
      if [ ! -d $CHECK_FOLDER ]; then
      sshfs $REMOTE_FOLDER $LOCAL_FOLDER
      fi

    3. Replace the values of CHECK_FOLDER, REMOTE_FOLDER, and LOCAL_FOLDER so it suites your setup.
    4. Save the file
  3. Logout and log back in
    Your NAS share should be mounted automatically so long as you have a public/private key authentication setup.
  4. Setting up your rdiff-backup
    For rdiff-backup, I simply run
    rdiff-backup --exclude-special-files <path_to_directory_to_backup> <mount_location_of_nas_share>

    To automate it, I put it as a cronjob that runs every night.

Note on 12/08/2008: I have now started to use rsync as it does not require me to mount the NAS Shares onto my personal computer. It also supports public/private keys allowing me to run it via cronjob daily.

That’s it!

LinkStation Pro Duo, enabling SSH

What I did to enable SSH on my LinkStation Pro Duo:

IMPORTANT NOTE: I made a few corrections to the below by adding item 3.6, and updating items 4.4, 5.11, and 5.12. Please read those items over again. If you needed to perform items 5.11 and 5.12 for two PCs, it is important that you use the updated commands.

  1. Enable Telnet (temporarily)

    1. Download the acp-commander
    2. Run the .jar file by running
      java -jar acp_commander.jar -t <IP ADDRESS> -o
    3. Login to your LinkStation Pro Duo using (username and password are found on the above link)
      telnet <IP ADDRESS>
  2. Enable SSH at Startup

    1. Create an SSH Startup script by typing vi /etc/init.d/sshd.sh
    2. Type ‘i’ to enter Interactive Mode (this enables you to type), then proceed to type the following code:
      #!/bin/sh
      test -f /usr/local/sbin/sshd || exit 0

      ACTIVE_FILE=/var/run/active_sshd

      case "$1" in
      start) echo -n "Start services: sshd"
      /usr/local/sbin/sshd -f /etc/sshd_config 2>/dev/null &
      touch $ACTIVE_FILE
      ;;
      stop) echo -n "Stop services: sshd"
      killall sshd
      rm -f $ACTIVE_FILE
      ;;
      restart) $0 stop
      $0 start
      ;;
      *) echo "Usage: $0 start | stop | restart"
      exit 1
      ;;
      esac
      exit 0

    3. Press the ESC key and type “:wq” to Save and Exit
    4. Make the file executable by running
      chmod +x /etc/init.d/sshd.sh
    5. Backup the original script startup file by running
      cp /etc/init.d/rcS /etc/init.d/rcS.bak
    6. Modify the rcS file to contain the SSH startup script by typing the following:
      vi /etc/init.d/rcS
    7. Press “i” to enter Interactive Mode
    8. Page Down till you see
      echo "** step3 **"
    9. At the end of the next line, add
      sshd.sh
    10. Your change should now look similar to the following:
      for cmd in diskmon.sh drivecheck.sh ftpd.sh atalk.sh httpd.sh smb.sh clientUtil_servd.sh bonjour.sh lsprcvd.sh daemonwatch.sh logrotate_init.sh cron.sh checkconfig.sh ups.sh pwrmgr.sh sshd.sh
    11. Save your changes and exit by pressing the ESC key and typing :wq
    12. Add your SSH script to the Daemon Watch, so if it crashes/closes, it will be started again automatically. Run the following code to edit the list
      vi /etc/daemonwatch.list
    13. Type “i” to enter Interactive Mode
    14. Add the following line to the file
      /var/run/sshd.pid /var/run/active_sshd /etc/init.d/sshd.sh restart
    15. Save your changes and exit bt pressing the ESC key and typing :wq
  3. Configure SSH

    1. Backup your original sshd_config file by typing
      cp /etc/sshd_config /etc/sshd_config.bak
    2. Modify the sshd_config file by typing
      vi /etc/sshd_config
    3. Press “i” to enter Interactive Mode
    4. Remove the # in front of the following lines (you need to use the backspace key to do this; you may also need to change some of the ‘no’ values to ‘yes’)
      Port 22
      Protocol 2,1

      HostKey /etc/ssh_host_key
      HostKey /etc/ssh_host_rsa_key
      HostKey /etc/ssh_host_dsa_key

      PermitRootLogin yes
      StrictModes yes

      RSAAuthentication yes
      PubkeyAuthentication yes

    5. Save the file by pressing the ESC key then typing :wq
    6. Start the SSH Server by running /etc/init.d/sshd.sh start
  4. Create new Home folders for each user
    You will need to do the following for every user you have created!

    1. Create the users via the Web Interface first, once the users are created, start Step 2 for each user
    2. Create a directory for the user by typing (replace <username> with the actual username)
      mkdir /home/<username>
    3. Give the user permission to that folder by typing
      chown <username>.<group> /home/<username>
      Now this is a bit tricky, depending how you setup the groups. You want to give the permission to a valid user and a group the user is part of. For example, if you have a user named “matt” and a group named “contributor”, then your command would be
      chown matt.contributor /home/matt
    4. Finally, make sure the directory has the correct permissions by running the following command
      chmod 0755 /home/<username>
    5. Set the user’s home directory by running
      usermod -d /home/<username> <username>
  5. Create public/private key pairs for each user
    You will need to do the following for every user you have created!
    I am only going to go over the commands you would use in Linux as I haven’t tried this with PuTTY yet. You will need to do these steps as “each user”. In other words, you will have to logout on your PC, login as the next user and repeat the commands (advanced users can use su <username> to login as an additional user without logging out as their own).

    1. Run the following command in Terminal or Konsole on YOUR PC
      ssh-keygen
    2. Leave the file name as “id_rsa”
    3. If you want a passphrase enter it here, otherwise, leave it blank (I left mine blank)
    4. Next run the following command to generate a SSH 2 key
      ssh-keygen -t dsa
    5. Leave the file name as “id_dsa”
    6. If you want a passphrase enter it here, otherwise, leave it blank (I left mine blank)
    7. Next copy the files to your LinkStation by running
      scp .ssh/*.pub <username>@<IP ADDRESS>:/home/<username>
    8. Next login to the LinkStation via SSH using
      ssh <username>@<IP ADDRESS>
    9. Once login run the following command to create your SSH key directory
      mkdir .ssh
    10. Make sure the permissions are set properly by running
      chmod 0700 .ssh
    11. Load the public key for SSH 1 by running
      cat id_rsa.pub >> .ssh/authorized_keys
    12. Load the public key for SSH 2 by running
      cat id_dsa.pub >> .ssh/authorized_keys2
    13. Make sure the public key entries for SSH have the correct permissions by running
      chmod 0600 .ssh/authorized_keys*
    14. Exit out of the LinkStation by typing “exit”
    15. Try step 8 again and make sure it did not ask for your password this time (if you entered a passphrase, you will be prompted for your passphrase)

Download the sshd_config.zip

Flex and Flex Builder 3

I just have to tell everyone how cool Flex really is! When I did flash work several years ago it was a real pain developing an entire site in Flash especially if you wanted to incorporate any backend to it. This is definitely not the case with Flex and I have to give Adobe its’ props on this.

However, let me state, that I do want to see Flex Builder 3 ported to Linux. I could then ditch my Windows Virtual Machine and run things natively, but that is my only complaint at this moment.

So why do I love Flex?
Flex is just easy to use, the components built it are amazing and you have the ability to build components on your own too! Much like Server Controls in .NET, .NET gives you a TON to begin with and you can create your own as well. However, this is for Flash! That is extremely important to acknowledge, as I do not have to have Macromedia Flash MX or whatever the latest version is on my PC to build a Flash application now.

Not only do I love being able to build a Flash application without Macromedia Flash, but I also love how it can work with an infinite number of backends without a lot of effort. Got a web service you want to plugin to? No problem, how about an RSS feed? Again, No problem. Well how about just a plain HTTP stream with a custom format? No Problem! I mean literally, you can plugin to any service that can send back a response. If it is a custom type of response, then you can write a routine to read your custom format. However, if you are using a Web Service, be in written in .NET and it returns an XML stream, then you literally have to do nothing! It will read it without any custom code from you, the developer. And that my friends is the “cream of the crop”.

So where do we go from here?
I am going to be doing a lot of things with Flex fromt his point on. I was just totally amazed by the simplicity and yet the complexity you can have within it. I still have a lot to test. Updating the grid’s data when it has changed, and similar events. But time will tell and so far Adobe has bought me back with this wonderful technology. Just bring it to Linux and I will move right next to your head-quarters Adobe!