Posts tagged 'Backup'

27

February 2012

Enabling Cron on a Western Digital My Book World Edition

Earlier today, a tweet from a colleague got me wondering whether I could set up cron on my NAS drive to give me the ability to run scheduled tasks. I don't leave any machines on at home, but my NAS drive is on 24/7, so it could be useful - especially as a backup system if Google open an API to Takeout!

I managed to get it working with some help from this post, so I thought I blog the details here (it turned out to be simpler than that post suggested) should it be useful to you (or to me, should I ever need to do this again).

There was no requirement to do anything crazy to make this work. I didn't install anything on the NAS, everything was there - even the SSH access is enabled via the web app!

  1. Log in to the My Book admin web app.
  2. Go to the Advanced section.
  3. Tick to enable SSH access at the top of the page (note: you may need to update your firmware to get this option).
  4. SSH into to the IP address of your mybook, using the username "root" and the password displayed on the page where you enabled SSH access.
  5. Create a folder to store our crontabs. Since /var/spool is mapped to /tmp it'll be wiped at rebooted, so we need to keep our own.
    mkdir /etc/crontabs
  6. Create a job that touches /tmp/crontab.test every minute (for testing).
    echo "* * * * * touch /tmp/crontab.test" > /etc/crontabs/root
  7. Create an entry in init.d to start crond using our /etc/crontabs folder.
    echo "/usr/sbin/crond -c /etc/crontabs" > /etc/init.d/S99crond
  8. Set permissions for execution.
    chmod 755 /etc/init.d/S99crond

That was all there was to it. I ran "reboot" and let the NAS reboot, then confirmed that /tmp/crontab.test was being touched every minute (with "ls /tmp/crontab.test -l").

Note: You should disable SSH access when you're done, or change the password. Otherwise, anybody on your network may be able to gain root access to your NAS!

If you make changes, you'll need to restart crond. You can do this with:

  1. killall crond
  2. /usr/sbin/crond -c /etc/crontabs

Next up, I'd like to find a way to edit the cron scripts from my Chromebook via something like Cloud9IDE rather than SSH/Vi ;(

05

February 2011

Compressing Folders into Individual Encrypted 7-Zip Files from the Command Line for Backing Up to Dropbox

As previously mentioned, I've started backing my important files up to Dropbox to make sure I have a copy of the things I can't replace, should the worst happen. To easily encrypt the file contents, I decided to put things into password-protected 7-Zip files before copying into my Dropbox folder.

The problem with putting everything into the same zip file, is that any change to a single file would cause Dropbox to upload the entire archive again. This would be quite a waste of bandwidth!

So, I came up with the following solution. If I create an encrypted 7-Zip file for each sub-directory within a given directory (eg. for each photo album within my photos directory), then only folders that contain changes will be uploaded/overwritten. Since I rarely make changes to photo albums, but frequently create new ones, this will ensure my new files are backed up without constant uploading of the old ones, while still sending any changes I do make to the existing albums. To script this, I'm using the command-line version of 7-Zip.

The following command will loop through each sub-directory in the provided directory, and call 7-Zip, telling it to compress the contents into a 7-Zip file (using the original directory name as the zip filename). Note: This is written for use in a .bat file. You may need to tweak it to use it directly on the command-line.

for /D %%d in ("D:\Pictures\*.*") do "J:\Downloads\Utilities\7-Zip\7za" a -mx0 -t7z -pSuperStrongPasswordHere12345 "J:\TempBackup\Photos\%%~nd.7z" "%%d\*"

You'll want to replace the bold parts with the directory you want to back up, the location of the command-line version of 7-Zip, the password you want to encrypt with and finally, the location to store the files in. I put them into a temp folder first, then copy them over into the Dropbox folder once completed.

It's worth noting that because the script loops through the sub-directories, it will not include any files in the root directory you specified. If you want to include them too, you'll need to add another command, eg:

"J:\Downloads\Utilities\7-Zip\7za" a -mx0 -t7z -pSuperStrongPasswordHere12345 "J:\TempBackup\Photos\_Files.7z" "D:\Pictures\*"

If you don't mind the script taking a little longer, you can change the "mx" argument to compress the files ("mx0" = "zero compression") and it'll take up less space on your Dropbox account. If you're going to encrypt things, make sure you store the encryption password somewhere offsite - so that if the need comes to rebuild a PC, you still have a copy of it!

02

February 2011

Using Dropbox as an Off-site Backup

After a number of incidents with lost (or almost lost) data, I decided it's about time I started backing my important data up properly. Most of the important things on my PC are on RAID-1 mirrored disks, but since they're only 75GB each (giving a total of only 75GB when mirrored!) some things (like music) have been relegated to a single 1TB drive.

I originally planned on picking up a Western Digital My Book World Edition II because it has two disks and supports RAID 1. Only a few weeks ago I spent many hours recovering data from a half-broken NAS with an Ubuntu Live CD, so it seemed to be a good idea.

However, after some discussion with colleagues and a little sleep, I decided that it would really make more sense to back up To The Cloud! (sorry!) than just having a backup 2ft from my PC, should something more catastrophic than a disk failure occur. Some things I can get away with just having locally (eg., music, since I still have the CDs), but other things (like wedding and holiday photos), I wouldn't be able to replace if lost.

I originally planned on using Amazon S3 (or Google Storage, if it had been cheaper), but since I couldn't find any decent software for backing up, I settled on Dropbox. You get 2GB for free, and the Windows client seems pretty lean. You pick a folder to Sync and it sits quietly in your systray uploading files as you create/modify them. Even better, you get an extra 250MB for every person you refer (and they get an extra 250MB for being referred too!), up to 10GB (2GB free + 8GB bonus).

So, this post has two purposes. One, is to get you thinking about backing your shit up. Disks fail. Often. Stop putting it off, it'll only bite you in the ass. Backing up to a NAS does not help if your house burns down or some idiots demolish your house in error. The second purpose, is because if I can get a few more referrals, then I can store all of my family wedding and holiday photos online at Dropbox without having to upgrade just yet. Whoop!

To get an extra 250MB on top of the 2GB free, click here to sign up to Dropbox.